diff options
| author | Michael Howitz <mh@gocept.com> | 2022-12-28 07:26:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-28 07:26:13 +0100 |
| commit | f1a2a39fcc779a6dd10a161a2ced8c3cf488d9f2 (patch) | |
| tree | b02d61b7bae5eb325614b1a0b9ef1160208606af /src/zope/interface/common | |
| parent | f05a16b94f135a6262667aeb7591487e8eefafa7 (diff) | |
| download | zope-interface-f1a2a39fcc779a6dd10a161a2ced8c3cf488d9f2.tar.gz | |
Drop support for Python 2.7, 3.5, 3.6. (#266)
Co-authored-by: Jens Vagelpohl <jens@plyp.com>
Diffstat (limited to 'src/zope/interface/common')
| -rw-r--r-- | src/zope/interface/common/__init__.py | 8 | ||||
| -rw-r--r-- | src/zope/interface/common/builtins.py | 18 | ||||
| -rw-r--r-- | src/zope/interface/common/collections.py | 61 | ||||
| -rw-r--r-- | src/zope/interface/common/interfaces.py | 6 | ||||
| -rw-r--r-- | src/zope/interface/common/io.py | 12 | ||||
| -rw-r--r-- | src/zope/interface/common/mapping.py | 18 | ||||
| -rw-r--r-- | src/zope/interface/common/numbers.py | 19 | ||||
| -rw-r--r-- | src/zope/interface/common/sequence.py | 26 | ||||
| -rw-r--r-- | src/zope/interface/common/tests/__init__.py | 2 | ||||
| -rw-r--r-- | src/zope/interface/common/tests/basemapping.py | 2 | ||||
| -rw-r--r-- | src/zope/interface/common/tests/test_builtins.py | 6 | ||||
| -rw-r--r-- | src/zope/interface/common/tests/test_collections.py | 75 | ||||
| -rw-r--r-- | src/zope/interface/common/tests/test_io.py | 10 |
13 files changed, 50 insertions, 213 deletions
diff --git a/src/zope/interface/common/__init__.py b/src/zope/interface/common/__init__.py index 137e938..56f4566 100644 --- a/src/zope/interface/common/__init__.py +++ b/src/zope/interface/common/__init__.py @@ -28,7 +28,7 @@ __all__ = [ # pylint:disable=no-self-argument,no-method-argument # pylint:disable=unexpected-special-method-signature -class optional(object): +class optional: # Apply this decorator to a method definition to make it # optional (remove it from the list of required names), overriding # the definition inherited from the ABC. @@ -162,7 +162,7 @@ class ABCInterfaceClass(InterfaceClass): return '' docs = "\n\nThe following methods are optional:\n - " + "\n-".join( - "%s\n%s" % (k, v.__doc__) for k, v in optionals.items() + "{}\n{}".format(k, v.__doc__) for k, v in optionals.items() ) return docs @@ -175,7 +175,7 @@ class ABCInterfaceClass(InterfaceClass): return "`%s`" % name if mod == '_io': mod = 'io' - return "`%s.%s`" % (mod, name) + return "`{}.{}`".format(mod, name) implementations_doc = "\n - ".join( ref(c) for c in sorted(self.getRegisteredConformers(), key=ref) @@ -187,7 +187,7 @@ class ABCInterfaceClass(InterfaceClass): based_on_doc = based_on_doc.splitlines() based_on_doc = based_on_doc[0] if based_on_doc else '' - doc = """Interface for the ABC `%s.%s`.\n\n%s%s%s""" % ( + doc = """Interface for the ABC `{}.{}`.\n\n{}{}{}""".format( based_on.__module__, based_on.__name__, attrs.get('__doc__', based_on_doc), self.__optional_methods_to_docs(attrs), diff --git a/src/zope/interface/common/builtins.py b/src/zope/interface/common/builtins.py index a07c0a3..17090e4 100644 --- a/src/zope/interface/common/builtins.py +++ b/src/zope/interface/common/builtins.py @@ -17,7 +17,6 @@ that they implement the appropriate interface. .. versionadded:: 5.0.0 """ -from __future__ import absolute_import from zope.interface import classImplements @@ -60,12 +59,11 @@ class ITuple(collections.ISequence): class ITextString(collections.ISequence): """ - Interface for text (unicode) strings. + Interface for text ("unicode") strings. - On Python 2, this is :class:`unicode`. On Python 3, - this is :class:`str` + This is :class:`str` """ - extra_classes = (type(u'unicode'),) + extra_classes = (str,) class IByteString(collections.IByteString): @@ -81,12 +79,11 @@ class IByteString(collections.IByteString): extra_classes = (bytes,) -class INativeString(IByteString if str is bytes else ITextString): +class INativeString(ITextString): """ Interface for native strings. - On all Python versions, this is :class:`str`. On Python 2, - this extends :class:`IByteString`, while on Python 3 it extends + On all Python versions, this is :class:`str`. Tt extends :class:`ITextString`. """ # We're not extending ABCInterface so extra_classes won't work @@ -119,7 +116,4 @@ class IFile(io.IIOBase): many different classes that implement different interfaces from :mod:`zope.interface.common.io`. """ - try: - extra_classes = (file,) - except NameError: - extra_classes = () + extra_classes = () diff --git a/src/zope/interface/common/collections.py b/src/zope/interface/common/collections.py index 00e2b8c..c549028 100644 --- a/src/zope/interface/common/collections.py +++ b/src/zope/interface/common/collections.py @@ -29,37 +29,16 @@ is, ``verifyObject(ISequence, list()))`` will pass, for example), a few might no .. versionadded:: 5.0.0 """ -from __future__ import absolute_import import sys from abc import ABCMeta -# The collections imports are here, and not in -# zope.interface._compat to avoid importing collections -# unless requested. It's a big import. -try: - from collections import abc -except ImportError: - import collections as abc +from collections import abc from collections import OrderedDict -try: - # On Python 3, all of these extend the appropriate collection ABC, - # but on Python 2, UserDict does not (though it is registered as a - # MutableMapping). (Importantly, UserDict on Python 2 is *not* - # registered, because it's not iterable.) Extending the ABC is not - # taken into account for interface declarations, though, so we - # need to be explicit about it. - from collections import UserList - from collections import UserDict - from collections import UserString -except ImportError: - # Python 2 - from UserList import UserList - from UserDict import IterableUserDict as UserDict - from UserString import UserString - -from zope.interface._compat import PYTHON2 as PY2 -from zope.interface._compat import PYTHON3 as PY3 +from collections import UserList +from collections import UserDict +from collections import UserString + from zope.interface.common import ABCInterface from zope.interface.common import optional @@ -68,8 +47,6 @@ from zope.interface.common import optional # pylint:disable=unexpected-special-method-signature # pylint:disable=no-value-for-parameter -PY35 = sys.version_info[:2] >= (3, 5) -PY36 = sys.version_info[:2] >= (3, 6) def _new_in_ver(name, ver, bases_if_missing=(ABCMeta,), @@ -144,7 +121,7 @@ class IIterator(IIterable): abc = abc.Iterator class IReversible(IIterable): - abc = _new_in_ver('Reversible', PY36, (IIterable.getABC(),)) + abc = _new_in_ver('Reversible', True, (IIterable.getABC(),)) @optional def __reversed__(): @@ -155,8 +132,8 @@ class IReversible(IIterable): """ class IGenerator(IIterator): - # New in 3.5 - abc = _new_in_ver('Generator', PY35, (IIterator.getABC(),)) + # New in Python 3.5 + abc = _new_in_ver('Generator', True, (IIterator.getABC(),)) class ISized(ABCInterface): @@ -168,7 +145,7 @@ class ISized(ABCInterface): class ICollection(ISized, IIterable, IContainer): - abc = _new_in_ver('Collection', PY36, + abc = _new_in_ver('Collection', True, (ISized.getABC(), IIterable.getABC(), IContainer.getABC())) @@ -205,7 +182,7 @@ class IByteString(ISequence): """ This unifies `bytes` and `bytearray`. """ - abc = _new_in_ver('ByteString', PY3, + abc = _new_in_ver('ByteString', True, (ISequence.getABC(),), (bytes, bytearray)) @@ -226,14 +203,6 @@ class IMapping(ICollection): # produces an inconsistent IRO if we also try to register it # here. ignored_classes = (OrderedDict,) - if PY2: - @optional - def __eq__(other): - """ - The interpreter will supply one. - """ - - __ne__ = __eq__ class IMutableMapping(IMapping): @@ -265,20 +234,20 @@ class IValuesView(IMappingView, ICollection): """ class IAwaitable(ABCInterface): - abc = _new_in_ver('Awaitable', PY35) + abc = _new_in_ver('Awaitable', True) class ICoroutine(IAwaitable): - abc = _new_in_ver('Coroutine', PY35) + abc = _new_in_ver('Coroutine', True) class IAsyncIterable(ABCInterface): - abc = _new_in_ver('AsyncIterable', PY35) + abc = _new_in_ver('AsyncIterable', True) class IAsyncIterator(IAsyncIterable): - abc = _new_in_ver('AsyncIterator', PY35) + abc = _new_in_ver('AsyncIterator', True) class IAsyncGenerator(IAsyncIterator): - abc = _new_in_ver('AsyncGenerator', PY36) + abc = _new_in_ver('AsyncGenerator', True) diff --git a/src/zope/interface/common/interfaces.py b/src/zope/interface/common/interfaces.py index 4308e0a..70bd294 100644 --- a/src/zope/interface/common/interfaces.py +++ b/src/zope/interface/common/interfaces.py @@ -22,11 +22,7 @@ classImplements(Exception, IException) class IStandardError(IException): - "Interface for `StandardError` (Python 2 only.)" -try: - classImplements(StandardError, IStandardError) -except NameError: #pragma NO COVER - pass # StandardError does not exist in Python 3 + "Interface for `StandardError` (no longer existing.)" class IWarning(IException): diff --git a/src/zope/interface/common/io.py b/src/zope/interface/common/io.py index 540d53a..0d6f3ba 100644 --- a/src/zope/interface/common/io.py +++ b/src/zope/interface/common/io.py @@ -18,7 +18,6 @@ that they implement the appropriate interface. .. versionadded:: 5.0.0 """ -from __future__ import absolute_import import io as abc @@ -37,16 +36,7 @@ class IRawIOBase(IIOBase): class IBufferedIOBase(IIOBase): abc = abc.BufferedIOBase - try: - import cStringIO - except ImportError: - # Python 3 - extra_classes = () - else: - import StringIO - extra_classes = (StringIO.StringIO, cStringIO.InputType, cStringIO.OutputType) - del cStringIO - del StringIO + extra_classes = () class ITextIOBase(IIOBase): diff --git a/src/zope/interface/common/mapping.py b/src/zope/interface/common/mapping.py index de56cf8..d043333 100644 --- a/src/zope/interface/common/mapping.py +++ b/src/zope/interface/common/mapping.py @@ -29,7 +29,6 @@ implement ``IMutableMapping``, but *do not* implement any of the interfaces in this module. """ from zope.interface import Interface -from zope.interface._compat import PYTHON2 as PY2 from zope.interface.common import collections class IItemMapping(Interface): @@ -103,20 +102,8 @@ class IIterableMapping(IEnumerableMapping): """A mapping that has distinct methods for iterating without copying. - On Python 2, a `dict` has these methods, but on Python 3 - the methods defined in `IEnumerableMapping` already iterate - without copying. """ - if PY2: - def iterkeys(): - "iterate over keys; equivalent to ``__iter__``" - - def itervalues(): - "iterate over values" - - def iteritems(): - "iterate over items" class IClonableMapping(Interface): """Something that can produce a copy of itself. @@ -131,13 +118,10 @@ class IExtendedReadMapping(IIterableMapping): """ Something with a particular method equivalent to ``__contains__``. - On Python 2, `dict` provides this method, but it was removed + On Python 2, `dict` provided the ``has_key`` method, but it was removed in Python 3. """ - if PY2: - def has_key(key): - """Tell if a key exists in the mapping; equivalent to ``__contains__``""" class IExtendedWriteMapping(IWriteMapping): """Additional mutation methods. diff --git a/src/zope/interface/common/numbers.py b/src/zope/interface/common/numbers.py index 3bf9206..6b20e09 100644 --- a/src/zope/interface/common/numbers.py +++ b/src/zope/interface/common/numbers.py @@ -18,14 +18,12 @@ that they implement the appropriate interface. .. versionadded:: 5.0.0 """ -from __future__ import absolute_import import numbers as abc from zope.interface.common import ABCInterface from zope.interface.common import optional -from zope.interface._compat import PYTHON2 as PY2 # pylint:disable=inherit-non-class, # pylint:disable=no-self-argument,no-method-argument @@ -46,14 +44,6 @@ class IComplex(INumber): Rarely implemented, even in builtin types. """ - if PY2: - @optional - def __eq__(other): - """ - The interpreter may supply one through complicated rules. - """ - - __ne__ = __eq__ class IReal(IComplex): abc = abc.Real @@ -66,15 +56,6 @@ class IReal(IComplex): __floor__ = __ceil__ = __complex__ - if PY2: - @optional - def __le__(other): - """ - The interpreter may supply one through complicated rules. - """ - - __lt__ = __le__ - class IRational(IReal): abc = abc.Rational diff --git a/src/zope/interface/common/sequence.py b/src/zope/interface/common/sequence.py index da4bc84..5edc73d 100644 --- a/src/zope/interface/common/sequence.py +++ b/src/zope/interface/common/sequence.py @@ -32,7 +32,6 @@ in this module. __docformat__ = 'restructuredtext' from zope.interface import Interface from zope.interface.common import collections -from zope.interface._compat import PYTHON2 as PY2 class IMinimalSequence(collections.IIterable): """Most basic sequence interface. @@ -107,14 +106,6 @@ class IReadSequence(collections.IContainer, IFiniteSequence): def __rmul__(n): """``x.__rmul__(n) <==> n * x``""" - if PY2: - def __getslice__(i, j): - """``x.__getslice__(i, j) <==> x[i:j]`` - - Use of negative indices is not supported. - - Deprecated since Python 2.0 but still a part of `UserList`. - """ class IExtendedReadSequence(IReadSequence): """Full read interface for lists""" @@ -145,23 +136,6 @@ class IUniqueMemberWriteSequence(Interface): supports slice objects. """ - if PY2: - def __setslice__(i, j, other): - """``x.__setslice__(i, j, other) <==> x[i:j] = other`` - - Use of negative indices is not supported. - - Deprecated since Python 2.0 but still a part of `UserList`. - """ - - def __delslice__(i, j): - """``x.__delslice__(i, j) <==> del x[i:j]`` - - Use of negative indices is not supported. - - Deprecated since Python 2.0 but still a part of `UserList`. - """ - def __iadd__(y): """``x.__iadd__(y) <==> x += y``""" diff --git a/src/zope/interface/common/tests/__init__.py b/src/zope/interface/common/tests/__init__.py index 2023072..0503495 100644 --- a/src/zope/interface/common/tests/__init__.py +++ b/src/zope/interface/common/tests/__init__.py @@ -60,7 +60,7 @@ def add_verify_tests(cls, iface_classes_iter): self.assertTrue(self.verify(iface, stdlib_class)) - suffix = "%s_%s_%s_%s" % ( + suffix = "{}_{}_{}_{}".format( stdlib_class.__module__.replace('.', '_'), stdlib_class.__name__, iface.__module__.replace('.', '_'), diff --git a/src/zope/interface/common/tests/basemapping.py b/src/zope/interface/common/tests/basemapping.py index b756dca..6fe91a1 100644 --- a/src/zope/interface/common/tests/basemapping.py +++ b/src/zope/interface/common/tests/basemapping.py @@ -63,7 +63,7 @@ def testIEnumerableMapping(self, inst, state): test___len__(self, inst, state) -class BaseTestIReadMapping(object): +class BaseTestIReadMapping: def testIReadMapping(self): inst = self._IReadMapping__sample() state = self._IReadMapping__stateDict() diff --git a/src/zope/interface/common/tests/test_builtins.py b/src/zope/interface/common/tests/test_builtins.py index 1f0d338..cf7019b 100644 --- a/src/zope/interface/common/tests/test_builtins.py +++ b/src/zope/interface/common/tests/test_builtins.py @@ -9,11 +9,9 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. ############################################################################## -from __future__ import absolute_import import unittest -from zope.interface._compat import PYTHON2 as PY2 from zope.interface.common import builtins from . import VerifyClassMixin @@ -29,12 +27,12 @@ class TestVerifyClass(VerifyClassMixin, add_verify_tests(TestVerifyClass, ( (builtins.IList, (list,)), (builtins.ITuple, (tuple,)), - (builtins.ITextString, (type(u'abc'),)), + (builtins.ITextString, (str,)), (builtins.IByteString, (bytes,)), (builtins.INativeString, (str,)), (builtins.IBool, (bool,)), (builtins.IDict, (dict,)), - (builtins.IFile, (file,) if PY2 else ()), + (builtins.IFile, ()), )) diff --git a/src/zope/interface/common/tests/test_collections.py b/src/zope/interface/common/tests/test_collections.py index 152626b..2bd6f50 100644 --- a/src/zope/interface/common/tests/test_collections.py +++ b/src/zope/interface/common/tests/test_collections.py @@ -13,18 +13,12 @@ import array import unittest -try: - import collections.abc as abc -except ImportError: - import collections as abc +from collections import abc from collections import deque from collections import OrderedDict -try: - from types import MappingProxyType -except ImportError: - MappingProxyType = object() +from types import MappingProxyType from zope.interface import Invalid @@ -34,7 +28,7 @@ from zope.interface.common import collections from zope.interface._compat import PYPY -from zope.interface._compat import PYTHON2 as PY2 + from . import add_abc_interface_tests from . import VerifyClassMixin @@ -65,16 +59,6 @@ class TestVerifyClass(VerifyClassMixin, unittest.TestCase): self.assertTrue(self.verify(collections.ISequence, collections.UserString)) - def test_non_iterable_UserDict(self): - try: - from UserDict import UserDict as NonIterableUserDict # pylint:disable=import-error - except ImportError: - # Python 3 - self.skipTest("No UserDict.NonIterableUserDict on Python 3") - - with self.assertRaises(Invalid): - self.verify(collections.IMutableMapping, NonIterableUserDict) - # Now we go through the registry, which should have several things, # mostly builtins, but if we've imported other libraries already, # it could contain things from outside of there too. We aren't concerned @@ -110,30 +94,13 @@ class TestVerifyClass(VerifyClassMixin, unittest.TestCase): # Likewise for index range, }) - if PY2: - # pylint:disable=undefined-variable,no-member - # There are a lot more types that are fundamentally unverifiable on Python 2. - UNVERIFIABLE.update({ - # Missing several key methods like __getitem__ - basestring, - # Missing __iter__ and __contains__, hard to construct. - buffer, - # Missing ``__contains__``, ``count`` and ``index``. - xrange, - # These two are missing Set.isdisjoint() - type({}.viewitems()), - type({}.viewkeys()), - }) - NON_STRICT_RO = { - } - else: - UNVERIFIABLE_RO = { - # ``array.array`` fails the ``test_auto_ro_*`` tests with and - # without strict RO but only on Windows (AppVeyor) on Python 3.10.0 - # (in older versions ``array.array`` does not appear as - # ``IMutableSequence``). - array.array, - } + UNVERIFIABLE_RO = { + # ``array.array`` fails the ``test_auto_ro_*`` tests with and + # without strict RO but only on Windows (AppVeyor) on Python 3.10.0 + # (in older versions ``array.array`` does not appear as + # ``IMutableSequence``). + array.array, + } add_abc_interface_tests(TestVerifyClass, collections.ISet.__module__) @@ -154,7 +121,7 @@ class TestVerifyObject(VerifyObjectMixin, type(iter({}.keys())): lambda: iter({}.keys()), type(iter({}.items())): lambda: iter({}.items()), type(iter({}.values())): lambda: iter({}.values()), - type((i for i in range(1))): lambda: (i for i in range(3)), + type(i for i in range(1)): lambda: (i for i in range(3)), type(iter([])): lambda: iter([]), type(reversed([])): lambda: reversed([]), 'longrange_iterator': unittest.SkipTest, @@ -166,16 +133,10 @@ class TestVerifyObject(VerifyObjectMixin, type(iter(tuple())): lambda: iter(tuple()), } - if PY2: - # pylint:disable=undefined-variable,no-member - CONSTRUCTORS.update({ - collections.IValuesView: {}.viewvalues, - }) - else: - UNVERIFIABLE_RO = { - # ``array.array`` fails the ``test_auto_ro_*`` tests with and - # without strict RO but only on Windows (AppVeyor) on Python 3.10.0 - # (in older versions ``array.array`` does not appear as - # ``IMutableSequence``). - array.array, - } + UNVERIFIABLE_RO = { + # ``array.array`` fails the ``test_auto_ro_*`` tests with and + # without strict RO but only on Windows (AppVeyor) on Python 3.10.0 + # (in older versions ``array.array`` does not appear as + # ``IMutableSequence``). + array.array, + } diff --git a/src/zope/interface/common/tests/test_io.py b/src/zope/interface/common/tests/test_io.py index c6ff8bd..0e8e74d 100644 --- a/src/zope/interface/common/tests/test_io.py +++ b/src/zope/interface/common/tests/test_io.py @@ -40,13 +40,3 @@ class TestVerifyObject(VerifyObjectMixin, abc.FileIO: lambda: abc.FileIO(__file__), '_WindowsConsoleIO': unittest.SkipTest, } - - try: - import cStringIO - except ImportError: - pass - else: - CONSTRUCTORS.update({ - cStringIO.InputType: lambda cStringIO=cStringIO: cStringIO.StringIO('abc'), - cStringIO.OutputType: cStringIO.StringIO, - }) |
