Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-typing_extensions for openSUSE:Factory checked in at 2021-11-15 15:26:23 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-typing_extensions (Old) and /work/SRC/openSUSE:Factory/.python-typing_extensions.new.1890 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-typing_extensions" Mon Nov 15 15:26:23 2021 rev:13 rq:931292 version:3.10.0.2 Changes: -------- --- /work/SRC/openSUSE:Factory/python-typing_extensions/python-typing_extensions.changes 2021-07-16 22:13:07.470668098 +0200 +++ /work/SRC/openSUSE:Factory/.python-typing_extensions.new.1890/python-typing_extensions.changes 2021-11-15 15:28:00.925850636 +0100 @@ -1,0 +2,8 @@ +Sat Nov 13 20:42:04 UTC 2021 - Dirk M??ller <dmuel...@suse.com> + +- Update to 3.10.0.2: + * Docs improvements + * Fixes crash and _GenericAlias import + * Support most use cases for PEP 612 with Generic + +------------------------------------------------------------------- Old: ---- typing_extensions-3.10.0.0.tar.gz New: ---- typing_extensions-3.10.0.2.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-typing_extensions.spec ++++++ --- /var/tmp/diff_new_pack.YUPHQy/_old 2021-11-15 15:28:01.421850776 +0100 +++ /var/tmp/diff_new_pack.YUPHQy/_new 2021-11-15 15:28:01.425850777 +0100 @@ -28,7 +28,7 @@ %bcond_with test %endif Name: python-typing_extensions%{psuffix} -Version: 3.10.0.0 +Version: 3.10.0.2 Release: 0 Summary: Backported and Experimental Type Hints for Python 35+ License: Python-2.0 ++++++ typing_extensions-3.10.0.0.tar.gz -> typing_extensions-3.10.0.2.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/PKG-INFO new/typing_extensions-3.10.0.2/PKG-INFO --- old/typing_extensions-3.10.0.0/PKG-INFO 2021-05-01 19:56:08.000000000 +0200 +++ new/typing_extensions-3.10.0.2/PKG-INFO 2021-08-30 20:43:58.817377800 +0200 @@ -1,29 +1,11 @@ -Metadata-Version: 1.1 +Metadata-Version: 2.1 Name: typing_extensions -Version: 3.10.0.0 +Version: 3.10.0.2 Summary: Backported and Experimental Type Hints for Python 3.5+ Home-page: https://github.com/python/typing/blob/master/typing_extensions/README.rst Author: Guido van Rossum, Jukka Lehtosalo, ??ukasz Langa, Michael Lee Author-email: levkivs...@gmail.com License: PSF -Description: Typing Extensions -- Backported and Experimental Type Hints for Python - - The ``typing`` module was added to the standard library in Python 3.5, but - many new features have been added to the module since then. - This means users of Python 3.5 - 3.6 who are unable to upgrade will not be - able to take advantage of new types added to the ``typing`` module, such as - ``typing.Protocol`` or ``typing.TypedDict``. - - The ``typing_extensions`` module contains backports of these changes. - Experimental types that will eventually be added to the ``typing`` - module are also included in ``typing_extensions``, such as - ``typing.ParamSpec`` and ``typing.TypeGuard``. - - Users of Python versions before 3.5 should install and use - the ``typing`` module from PyPI instead of using this one, unless specifically - writing code that must be compatible with multiple Python versions or requires - experimental types. - Keywords: typing function annotations type hints hinting checking checker typehints typehinting typechecking backport Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha @@ -40,3 +22,24 @@ Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Topic :: Software Development +License-File: LICENSE + +Typing Extensions -- Backported and Experimental Type Hints for Python + +The ``typing`` module was added to the standard library in Python 3.5, but +many new features have been added to the module since then. +This means users of Python 3.5 - 3.6 who are unable to upgrade will not be +able to take advantage of new types added to the ``typing`` module, such as +``typing.Protocol`` or ``typing.TypedDict``. + +The ``typing_extensions`` module contains backports of these changes. +Experimental types that will eventually be added to the ``typing`` +module are also included in ``typing_extensions``, such as +``typing.ParamSpec`` and ``typing.TypeGuard``. + +Users of Python versions before 3.5 should install and use +the ``typing`` module from PyPI instead of using this one, unless specifically +writing code that must be compatible with multiple Python versions or requires +experimental types. + + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/README.rst new/typing_extensions-3.10.0.2/README.rst --- old/typing_extensions-3.10.0.0/README.rst 2021-05-01 19:50:21.000000000 +0200 +++ new/typing_extensions-3.10.0.2/README.rst 2021-08-29 17:36:03.000000000 +0200 @@ -90,8 +90,8 @@ Certain types have incorrect runtime behavior due to limitations of older versions of the typing module. For example, ``ParamSpec`` and ``Concatenate`` -will not work with ``get_args``, ``get_origin`` or user-defined ``Generic``\ s -because they need to be lists to work with older versions of ``Callable``. +will not work with ``get_args``, ``get_origin``. Certain PEP 612 special cases +in user-defined ``Generic``\ s are also not available. These types are only guaranteed to work for static type checking. Running tests diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/setup.py new/typing_extensions-3.10.0.2/setup.py --- old/typing_extensions-3.10.0.0/setup.py 2021-05-01 19:50:21.000000000 +0200 +++ new/typing_extensions-3.10.0.2/setup.py 2021-08-30 20:43:17.000000000 +0200 @@ -9,7 +9,7 @@ 'to install the typing package.\n') exit(1) -version = '3.10.0.0' +version = '3.10.0.2' description = 'Backported and Experimental Type Hints for Python 3.5+' long_description = '''\ Typing Extensions -- Backported and Experimental Type Hints for Python diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py2/typing_extensions.egg-info/PKG-INFO new/typing_extensions-3.10.0.2/src_py2/typing_extensions.egg-info/PKG-INFO --- old/typing_extensions-3.10.0.0/src_py2/typing_extensions.egg-info/PKG-INFO 2021-05-01 19:56:08.000000000 +0200 +++ new/typing_extensions-3.10.0.2/src_py2/typing_extensions.egg-info/PKG-INFO 1970-01-01 01:00:00.000000000 +0100 @@ -1,42 +0,0 @@ -Metadata-Version: 1.1 -Name: typing-extensions -Version: 3.10.0.0 -Summary: Backported and Experimental Type Hints for Python 3.5+ -Home-page: https://github.com/python/typing/blob/master/typing_extensions/README.rst -Author: Guido van Rossum, Jukka Lehtosalo, ??ukasz Langa, Michael Lee -Author-email: levkivs...@gmail.com -License: PSF -Description: Typing Extensions -- Backported and Experimental Type Hints for Python - - The ``typing`` module was added to the standard library in Python 3.5, but - many new features have been added to the module since then. - This means users of Python 3.5 - 3.6 who are unable to upgrade will not be - able to take advantage of new types added to the ``typing`` module, such as - ``typing.Protocol`` or ``typing.TypedDict``. - - The ``typing_extensions`` module contains backports of these changes. - Experimental types that will eventually be added to the ``typing`` - module are also included in ``typing_extensions``, such as - ``typing.ParamSpec`` and ``typing.TypeGuard``. - - Users of Python versions before 3.5 should install and use - the ``typing`` module from PyPI instead of using this one, unless specifically - writing code that must be compatible with multiple Python versions or requires - experimental types. - -Keywords: typing function annotations type hints hinting checking checker typehints typehinting typechecking backport -Platform: UNKNOWN -Classifier: Development Status :: 3 - Alpha -Classifier: Environment :: Console -Classifier: Intended Audience :: Developers -Classifier: License :: OSI Approved :: Python Software Foundation License -Classifier: Operating System :: OS Independent -Classifier: Programming Language :: Python :: 2.7 -Classifier: Programming Language :: Python :: 3.4 -Classifier: Programming Language :: Python :: 3.5 -Classifier: Programming Language :: Python :: 3.6 -Classifier: Programming Language :: Python :: 3.7 -Classifier: Programming Language :: Python :: 3.8 -Classifier: Programming Language :: Python :: 3.9 -Classifier: Programming Language :: Python :: 3.10 -Classifier: Topic :: Software Development diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py2/typing_extensions.egg-info/SOURCES.txt new/typing_extensions-3.10.0.2/src_py2/typing_extensions.egg-info/SOURCES.txt --- old/typing_extensions-3.10.0.0/src_py2/typing_extensions.egg-info/SOURCES.txt 2021-05-01 19:56:08.000000000 +0200 +++ new/typing_extensions-3.10.0.2/src_py2/typing_extensions.egg-info/SOURCES.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1,14 +0,0 @@ -LICENSE -MANIFEST.in -README.rst -setup.cfg -setup.py -src_py2/test_typing_extensions.py -src_py2/typing_extensions.py -src_py2/typing_extensions.egg-info/PKG-INFO -src_py2/typing_extensions.egg-info/SOURCES.txt -src_py2/typing_extensions.egg-info/dependency_links.txt -src_py2/typing_extensions.egg-info/requires.txt -src_py2/typing_extensions.egg-info/top_level.txt -src_py3/test_typing_extensions.py -src_py3/typing_extensions.py \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py2/typing_extensions.egg-info/dependency_links.txt new/typing_extensions-3.10.0.2/src_py2/typing_extensions.egg-info/dependency_links.txt --- old/typing_extensions-3.10.0.0/src_py2/typing_extensions.egg-info/dependency_links.txt 2021-05-01 19:56:08.000000000 +0200 +++ new/typing_extensions-3.10.0.2/src_py2/typing_extensions.egg-info/dependency_links.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1 +0,0 @@ - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py2/typing_extensions.egg-info/requires.txt new/typing_extensions-3.10.0.2/src_py2/typing_extensions.egg-info/requires.txt --- old/typing_extensions-3.10.0.0/src_py2/typing_extensions.egg-info/requires.txt 2021-05-01 19:56:08.000000000 +0200 +++ new/typing_extensions-3.10.0.2/src_py2/typing_extensions.egg-info/requires.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1,3 +0,0 @@ - -[:python_version < "3.5"] -typing>=3.7.4 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py2/typing_extensions.egg-info/top_level.txt new/typing_extensions-3.10.0.2/src_py2/typing_extensions.egg-info/top_level.txt --- old/typing_extensions-3.10.0.0/src_py2/typing_extensions.egg-info/top_level.txt 2021-05-01 19:56:08.000000000 +0200 +++ new/typing_extensions-3.10.0.2/src_py2/typing_extensions.egg-info/top_level.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1 +0,0 @@ -typing_extensions diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py3/test_typing_extensions.py new/typing_extensions-3.10.0.2/src_py3/test_typing_extensions.py --- old/typing_extensions-3.10.0.0/src_py3/test_typing_extensions.py 2021-05-01 19:50:21.000000000 +0200 +++ new/typing_extensions-3.10.0.2/src_py3/test_typing_extensions.py 2021-08-30 20:39:51.000000000 +0200 @@ -53,6 +53,7 @@ TYPING_3_5_3 = TYPING_LATEST or sys.version_info[:3] >= (3, 5, 3) TYPING_3_6_1 = TYPING_LATEST or sys.version_info[:3] >= (3, 6, 1) TYPING_3_10_0 = TYPING_LATEST or sys.version_info[:3] >= (3, 10, 0) +TYPING_3_11_0 = TYPING_LATEST or sys.version_info[:3] >= (3, 11, 0) # For typing versions where issubclass(...) and # isinstance(...) checks are forbidden. @@ -466,6 +467,10 @@ @skipUnless(PY36, 'Python 3.6 required') def test_get_type_hints_modules(self): ann_module_type_hints = {1: 2, 'f': Tuple[int, int], 'x': int, 'y': str} + if (TYPING_3_11_0 + or (TYPING_3_10_0 and sys.version_info.releaselevel in {'candidate', 'final'})): + # More tests were added in 3.10rc1. + ann_module_type_hints['u'] = int | float self.assertEqual(gth(ann_module), ann_module_type_hints) self.assertEqual(gth(ann_module2), {}) self.assertEqual(gth(ann_module3), {}) @@ -2012,25 +2017,38 @@ P = ParamSpec('P') T = TypeVar('T') C1 = typing.Callable[P, int] + # Callable in Python 3.5.2 might be bugged when collecting __args__. + # https://github.com/python/cpython/blob/91185fe0284a04162e0b3425b53be49bdbfad67d/Lib/typing.py#L1026 + PY_3_5_2 = sys.version_info[:3] == (3, 5, 2) + if not PY_3_5_2: + self.assertEqual(C1.__args__, (P, int)) + self.assertEqual(C1.__parameters__, (P,)) C2 = typing.Callable[P, T] + if not PY_3_5_2: + self.assertEqual(C2.__args__, (P, T)) + self.assertEqual(C2.__parameters__, (P, T)) - # Note: no tests for Callable.__args__ and Callable.__parameters__ here - # because pre-3.10 Callable sees ParamSpec as a plain list, not a - # TypeVar. # Test collections.abc.Callable too. if sys.version_info[:2] >= (3, 9): + # Note: no tests for Callable.__parameters__ here + # because types.GenericAlias Callable is hardcoded to search + # for tp_name "TypeVar" in C. This was changed in 3.10. C3 = collections.abc.Callable[P, int] + self.assertEqual(C3.__args__, (P, int)) C4 = collections.abc.Callable[P, T] + self.assertEqual(C4.__args__, (P, T)) # ParamSpec instances should also have args and kwargs attributes. - self.assertIn('args', dir(P)) - self.assertIn('kwargs', dir(P)) + # Note: not in dir(P) because of __class__ hacks + self.assertTrue(hasattr(P, 'args')) + self.assertTrue(hasattr(P, 'kwargs')) def test_args_kwargs(self): P = ParamSpec('P') - self.assertIn('args', dir(P)) - self.assertIn('kwargs', dir(P)) + # Note: not in dir(P) because of __class__ hacks + self.assertTrue(hasattr(P, 'args')) + self.assertTrue(hasattr(P, 'kwargs')) self.assertIsInstance(P.args, ParamSpecArgs) self.assertIsInstance(P.kwargs, ParamSpecKwargs) self.assertIs(P.args.__origin__, P) @@ -2038,8 +2056,32 @@ self.assertEqual(repr(P.args), "P.args") self.assertEqual(repr(P.kwargs), "P.kwargs") - # Note: ParamSpec doesn't work for pre-3.10 user-defined Generics due - # to type checks inside Generic. + def test_user_generics(self): + T = TypeVar("T") + P = ParamSpec("P") + P_2 = ParamSpec("P_2") + + class X(Generic[T, P]): + pass + + G1 = X[int, P_2] + self.assertEqual(G1.__args__, (int, P_2)) + self.assertEqual(G1.__parameters__, (P_2,)) + + G2 = X[int, Concatenate[int, P_2]] + self.assertEqual(G2.__args__, (int, Concatenate[int, P_2])) + self.assertEqual(G2.__parameters__, (P_2,)) + + # The following are some valid uses cases in PEP 612 that don't work: + # These do not work in 3.9, _type_check blocks the list and ellipsis. + # G3 = X[int, [int, bool]] + # G4 = X[int, ...] + # G5 = Z[[int, str, bool]] + # Not working because this is special-cased in 3.10. + # G6 = Z[int, str, bool] + + class Z(Generic[P]): + pass def test_pickle(self): global P, P_co, P_contra @@ -2191,6 +2233,10 @@ self.assertIn('Protocol', a) self.assertIn('runtime', a) + # Check that all objects in `__all__` are present in the module + for name in a: + self.assertTrue(hasattr(typing_extensions, name)) + def test_typing_extensions_defers_when_possible(self): exclude = { 'overload', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py3/typing_extensions.egg-info/PKG-INFO new/typing_extensions-3.10.0.2/src_py3/typing_extensions.egg-info/PKG-INFO --- old/typing_extensions-3.10.0.0/src_py3/typing_extensions.egg-info/PKG-INFO 1970-01-01 01:00:00.000000000 +0100 +++ new/typing_extensions-3.10.0.2/src_py3/typing_extensions.egg-info/PKG-INFO 2021-08-30 20:43:58.000000000 +0200 @@ -0,0 +1,45 @@ +Metadata-Version: 2.1 +Name: typing-extensions +Version: 3.10.0.2 +Summary: Backported and Experimental Type Hints for Python 3.5+ +Home-page: https://github.com/python/typing/blob/master/typing_extensions/README.rst +Author: Guido van Rossum, Jukka Lehtosalo, ??ukasz Langa, Michael Lee +Author-email: levkivs...@gmail.com +License: PSF +Keywords: typing function annotations type hints hinting checking checker typehints typehinting typechecking backport +Platform: UNKNOWN +Classifier: Development Status :: 3 - Alpha +Classifier: Environment :: Console +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: Python Software Foundation License +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: 3.8 +Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 +Classifier: Topic :: Software Development +License-File: LICENSE + +Typing Extensions -- Backported and Experimental Type Hints for Python + +The ``typing`` module was added to the standard library in Python 3.5, but +many new features have been added to the module since then. +This means users of Python 3.5 - 3.6 who are unable to upgrade will not be +able to take advantage of new types added to the ``typing`` module, such as +``typing.Protocol`` or ``typing.TypedDict``. + +The ``typing_extensions`` module contains backports of these changes. +Experimental types that will eventually be added to the ``typing`` +module are also included in ``typing_extensions``, such as +``typing.ParamSpec`` and ``typing.TypeGuard``. + +Users of Python versions before 3.5 should install and use +the ``typing`` module from PyPI instead of using this one, unless specifically +writing code that must be compatible with multiple Python versions or requires +experimental types. + + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py3/typing_extensions.egg-info/SOURCES.txt new/typing_extensions-3.10.0.2/src_py3/typing_extensions.egg-info/SOURCES.txt --- old/typing_extensions-3.10.0.0/src_py3/typing_extensions.egg-info/SOURCES.txt 1970-01-01 01:00:00.000000000 +0100 +++ new/typing_extensions-3.10.0.2/src_py3/typing_extensions.egg-info/SOURCES.txt 2021-08-30 20:43:58.000000000 +0200 @@ -0,0 +1,14 @@ +LICENSE +MANIFEST.in +README.rst +setup.cfg +setup.py +src_py2/test_typing_extensions.py +src_py2/typing_extensions.py +src_py3/test_typing_extensions.py +src_py3/typing_extensions.py +src_py3/typing_extensions.egg-info/PKG-INFO +src_py3/typing_extensions.egg-info/SOURCES.txt +src_py3/typing_extensions.egg-info/dependency_links.txt +src_py3/typing_extensions.egg-info/requires.txt +src_py3/typing_extensions.egg-info/top_level.txt \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py3/typing_extensions.egg-info/dependency_links.txt new/typing_extensions-3.10.0.2/src_py3/typing_extensions.egg-info/dependency_links.txt --- old/typing_extensions-3.10.0.0/src_py3/typing_extensions.egg-info/dependency_links.txt 1970-01-01 01:00:00.000000000 +0100 +++ new/typing_extensions-3.10.0.2/src_py3/typing_extensions.egg-info/dependency_links.txt 2021-08-30 20:43:58.000000000 +0200 @@ -0,0 +1 @@ + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py3/typing_extensions.egg-info/requires.txt new/typing_extensions-3.10.0.2/src_py3/typing_extensions.egg-info/requires.txt --- old/typing_extensions-3.10.0.0/src_py3/typing_extensions.egg-info/requires.txt 1970-01-01 01:00:00.000000000 +0100 +++ new/typing_extensions-3.10.0.2/src_py3/typing_extensions.egg-info/requires.txt 2021-08-30 20:43:58.000000000 +0200 @@ -0,0 +1,3 @@ + +[:python_version < "3.5"] +typing>=3.7.4 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py3/typing_extensions.egg-info/top_level.txt new/typing_extensions-3.10.0.2/src_py3/typing_extensions.egg-info/top_level.txt --- old/typing_extensions-3.10.0.0/src_py3/typing_extensions.egg-info/top_level.txt 1970-01-01 01:00:00.000000000 +0100 +++ new/typing_extensions-3.10.0.2/src_py3/typing_extensions.egg-info/top_level.txt 2021-08-30 20:43:58.000000000 +0200 @@ -0,0 +1 @@ +typing_extensions diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-3.10.0.0/src_py3/typing_extensions.py new/typing_extensions-3.10.0.2/src_py3/typing_extensions.py --- old/typing_extensions-3.10.0.0/src_py3/typing_extensions.py 2021-05-01 19:50:21.000000000 +0200 +++ new/typing_extensions-3.10.0.2/src_py3/typing_extensions.py 2021-08-30 20:39:51.000000000 +0200 @@ -18,6 +18,7 @@ if PEP_560: GenericMeta = TypingMeta = type + from typing import _GenericAlias else: from typing import GenericMeta, TypingMeta OLD_GENERICS = False @@ -136,7 +137,7 @@ 'Counter', 'Deque', 'DefaultDict', - 'OrderedDict' + 'OrderedDict', 'TypedDict', # Structural checks, a.k.a. protocols. @@ -1399,7 +1400,7 @@ elif PEP_560: - from typing import _type_check, _GenericAlias, _collect_type_vars # noqa + from typing import _type_check, _collect_type_vars # noqa def _no_init(self, *args, **kwargs): if type(self)._is_protocol: @@ -1694,7 +1695,8 @@ class _TypedDictMeta(type): def __init__(cls, name, bases, ns, total=True): - # In Python 3.4 and 3.5 the __init__ method also needs to support the keyword arguments. + # In Python 3.4 and 3.5 the __init__ method also needs to support the + # keyword arguments. # See https://www.python.org/dev/peps/pep-0487/#implementation-details super(_TypedDictMeta, cls).__init__(name, bases, ns) @@ -2072,7 +2074,6 @@ get_origin = typing.get_origin get_args = typing.get_args elif PEP_560: - from typing import _GenericAlias try: # 3.9+ from typing import _BaseGenericAlias @@ -2329,6 +2330,9 @@ be pickled. """ + # Trick Generic __parameters__. + __class__ = TypeVar + @property def args(self): return ParamSpecArgs(self) @@ -2377,14 +2381,32 @@ def __call__(self, *args, **kwargs): pass - # Note: Can't fake ParamSpec as a TypeVar to get it to work - # with Generics. ParamSpec isn't an instance of TypeVar in 3.10. - # So encouraging code like isinstance(ParamSpec('P'), TypeVar)) - # will lead to breakage in 3.10. - # This also means no accurate __parameters__ for GenericAliases. + if not PEP_560: + # Only needed in 3.6 and lower. + def _get_type_vars(self, tvars): + if self not in tvars: + tvars.append(self) + # Inherits from list as a workaround for Callable checks in Python < 3.9.2. class _ConcatenateGenericAlias(list): + + # Trick Generic into looking into this for __parameters__. + if PEP_560: + __class__ = typing._GenericAlias + elif sys.version_info[:3] == (3, 5, 2): + __class__ = typing.TypingMeta + else: + __class__ = typing._TypingBase + + # Flag in 3.8. + _special = False + # Attribute in 3.6 and earlier. + if sys.version_info[:3] == (3, 5, 2): + _gorg = typing.GenericMeta + else: + _gorg = typing.Generic + def __init__(self, origin, args): super().__init__(args) self.__origin__ = origin @@ -2399,6 +2421,21 @@ def __hash__(self): return hash((self.__origin__, self.__args__)) + # Hack to get typing._type_check to pass in Generic. + def __call__(self, *args, **kwargs): + pass + + @property + def __parameters__(self): + return tuple(tp for tp in self.__args__ if isinstance(tp, (TypeVar, ParamSpec))) + + if not PEP_560: + # Only required in 3.6 and lower. + def _get_type_vars(self, tvars): + if self.__origin__ and self.__parameters__: + typing._get_type_vars(self.__parameters__, tvars) + + @_tp_cache def _concatenate_getitem(self, parameters): if parameters == (): @@ -2439,7 +2476,8 @@ def __getitem__(self, parameters): return _concatenate_getitem(self, parameters) - Concatenate = _ConcatenateForm('Concatenate', + Concatenate = _ConcatenateForm( + 'Concatenate', doc="""Used in conjunction with ``ParamSpec`` and ``Callable`` to represent a higher order function which adds, removes or transforms parameters of a callable. @@ -2582,8 +2620,8 @@ return _GenericAlias(self, (item,)) TypeGuard = _TypeGuardForm( - 'TypeGuard', - doc="""Special typing form used to annotate the return type of a user-defined + 'TypeGuard', + doc="""Special typing form used to annotate the return type of a user-defined type guard function. ``TypeGuard`` only accepts a single type argument. At runtime, functions marked this way should return a boolean.