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 2022-10-27 13:53:27
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-typing_extensions (Old)
and /work/SRC/openSUSE:Factory/.python-typing_extensions.new.2275 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-typing_extensions"
Thu Oct 27 13:53:27 2022 rev:16 rq:1031001 version:4.4.0
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-typing_extensions/python-typing_extensions.changes
2022-09-07 11:05:36.412340984 +0200
+++
/work/SRC/openSUSE:Factory/.python-typing_extensions.new.2275/python-typing_extensions.changes
2022-10-27 13:53:46.872447796 +0200
@@ -1,0 +2,22 @@
+Mon Oct 24 18:14:28 UTC 2022 - Ben Greiner <[email protected]>
+
+- Clean specfile from old cruft.
+- Requires Python 3.7+
+- Fix testsuite: Must test as module; don't need multibuild.
+- Update Summary and Description
+
+-------------------------------------------------------------------
+Tue Oct 18 12:07:27 UTC 2022 - John Paul Adrian Glaubitz
<[email protected]>
+
+- Update to version 4.4.0
+ * Add `typing_extensions.Any` a backport of python 3.11's Any class which is
+ subclassable at runtime. (backport from python/cpython#31841, by Shantanu
+ and Jelle Zijlstra). Patch by James Hilton-Balfe (@Gobot1234).
+ * Add initial support for TypeVarLike `default` parameter, PEP 696.
+ Patch by Marc Mueller (@cdce8p).
+ * Runtime support for PEP 698, adding `typing_extensions.override`. Patch by
+ Jelle Zijlstra.
+ * Add the `infer_variance` parameter to `TypeVar`, as specified in PEP 695.
+ Patch by Jelle Zijlstra.
+
+-------------------------------------------------------------------
Old:
----
_multibuild
typing_extensions-4.3.0.tar.gz
New:
----
typing_extensions-4.4.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-typing_extensions.spec ++++++
--- /var/tmp/diff_new_pack.9ffa0W/_old 2022-10-27 13:53:47.420450591 +0200
+++ /var/tmp/diff_new_pack.9ffa0W/_new 2022-10-27 13:53:47.424450612 +0200
@@ -1,5 +1,5 @@
#
-# spec file for python-typing_extensions
+# spec file for package python-typing_extensions
#
# Copyright (c) 2022 SUSE LLC
#
@@ -16,64 +16,53 @@
#
-%define modname typing_extensions
-%{?!python_module:%define python_module() python-%{**} python3-%{**}}
-%bcond_without python2
-%global flavor @BUILD_FLAVOR@%{nil}
-%if "%{flavor}" == "test"
-%define psuffix -test
-%bcond_without test
-%else
-%define psuffix %{nil}
-%bcond_with test
-%endif
-Name: python-typing_extensions%{psuffix}
-Version: 4.3.0
+Name: python-typing_extensions
+Version: 4.4.0
Release: 0
-Summary: Backported and Experimental Type Hints for Python 35+
+Summary: Backported and Experimental Type Hints for Python 3.7+
License: Python-2.0
URL: https://github.com/python/typing/
-Source0:
https://files.pythonhosted.org/packages/source/t/typing_extensions/%{modname}-%{version}.tar.gz
+Source0:
https://files.pythonhosted.org/packages/source/t/typing_extensions/typing_extensions-%{version}.tar.gz
# See https://github.com/python/typing_extensions/issues/61
-Source1:
https://raw.githubusercontent.com/python/typing_extensions/main/src/_typed_dict_test_helper.py
-BuildRequires: %{python_module flit-core < 4}
-BuildRequires: %{python_module flit-core >= 3.4}
+Source1:
https://raw.githubusercontent.com/python/typing_extensions/%{version}/src/_typed_dict_test_helper.py
+BuildRequires: %{python_module base >= 3.7}
+BuildRequires: %{python_module flit-core >= 3.4 with %python-flit-core < 4}
BuildRequires: %{python_module pip}
+BuildRequires: %{python_module testsuite}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
+Provides: python-typing-extensions = %{version}-%{release}
BuildArch: noarch
-Provides: python-typing-extensions = %{version}
-%if 0%{?suse_version} > 1320 && %{with test}
-BuildRequires: %{python_module testsuite}
-%endif
-%if %{with python2}
-BuildRequires: python-typing >= 3.7.4
-%endif
-BuildRequires: (python3-typing >= 3.7.4 if python3-base < 3.5)
-%if %{python_version_nodots} < 35
-Requires: python-typing >= 3.7.4
-%endif
%python_subpackages
%description
-The ``typing`` module was added to the standard library in Python
-3.5 on a provisional basis and will no longer be provisional in
-Python 3.7. However, 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.Text`` or
-``typing.Coroutine``.
-
-The ``typing_extensions`` module contains both backports of these
-changes as well as experimental types that will eventually be
-added to the ``typing`` module, such as ``Protocol``.
-
-Users of other Python versions should continue to 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.
+The typing_extensions module serves two related purposes:
+
+ * Enable use of new type system features on older Python versions.
+ For example, typing.TypeGuard is new in Python 3.10, but
+ typing_extensions allows users on previous Python versions to use
+ it too.
+ * Enable experimentation with new type system PEPs before they are
+ accepted and added to the typing module.
+
+New features may be added to typing_extensions as soon as they are
+specified in a PEP that has been added to the python/peps repository.
+If the PEP is accepted, the feature will then be added to typing for
+the next CPython release. No typing PEP has been rejected so far, so
+we haven't yet figured out how to deal with that possibility.
+
+Starting with version 4.0.0, typing_extensions uses Semantic Versioning.
+The major version is incremented for all backwards-incompatible changes.
+Therefore, it's safe to depend on typing_extensions like this:
+typing_extensions >=x.y, <(x+1),
+where x.y is the first version that includes all features you need.
+
+typing_extensions supports Python versions 3.7 and higher.
+In the future, support for older Python versions will be dropped some time
+after that version reaches end of life.
%prep
-%setup -q -n %{modname}-%{version}
+%setup -q -n typing_extensions-%{version}
# This should not be necessary in the next release
if [ -f src/_typed_dict_test_helper.py ]; then
exit 1
@@ -83,24 +72,20 @@
%build
%pyproject_wheel
-%if ! %{with test}
%install
%pyproject_install
%python_expand %fdupes %{buildroot}%{$python_sitelib}
-%endif
-%if %{with test}
%check
-%python_exec src/test_typing_extensions.py
-%endif
+pushd src
+%pyunittest -v test_typing_extensions
+popd
-%if ! %{with test}
%files %{python_files}
%license LICENSE
%doc CHANGELOG.md README.md
%{python_sitelib}/typing_extensions.py*
%pycache_only %{python_sitelib}/__pycache__/typing_extensions*
%{python_sitelib}/typing_extensions-%{version}*-info
-%endif
%changelog
++++++ typing_extensions-4.3.0.tar.gz -> typing_extensions-4.4.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/typing_extensions-4.3.0/CHANGELOG.md
new/typing_extensions-4.4.0/CHANGELOG.md
--- old/typing_extensions-4.3.0/CHANGELOG.md 2022-07-01 16:52:33.376041400
+0200
+++ new/typing_extensions-4.4.0/CHANGELOG.md 2022-10-07 00:38:03.079741000
+0200
@@ -1,3 +1,15 @@
+# Release 4.4.0 (October 6, 2022)
+
+- Add `typing_extensions.Any` a backport of python 3.11's Any class which is
+ subclassable at runtime. (backport from python/cpython#31841, by Shantanu
+ and Jelle Zijlstra). Patch by James Hilton-Balfe (@Gobot1234).
+- Add initial support for TypeVarLike `default` parameter, PEP 696.
+ Patch by Marc Mueller (@cdce8p).
+- Runtime support for PEP 698, adding `typing_extensions.override`. Patch by
+ Jelle Zijlstra.
+- Add the `infer_variance` parameter to `TypeVar`, as specified in PEP 695.
+ Patch by Jelle Zijlstra.
+
# Release 4.3.0 (July 1, 2022)
- Add `typing_extensions.NamedTuple`, allowing for generic `NamedTuple`s on
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/typing_extensions-4.3.0/LICENSE
new/typing_extensions-4.4.0/LICENSE
--- old/typing_extensions-4.3.0/LICENSE 2022-05-19 15:23:25.111670300 +0200
+++ new/typing_extensions-4.4.0/LICENSE 2022-10-05 02:04:11.270059300 +0200
@@ -13,12 +13,11 @@
In May 2000, Guido and the Python core development team moved to
BeOpen.com to form the BeOpen PythonLabs team. In October of the same
-year, the PythonLabs team moved to Digital Creations (now Zope
-Corporation, see http://www.zope.com). In 2001, the Python Software
-Foundation (PSF, see http://www.python.org/psf/) was formed, a
-non-profit organization created specifically to own Python-related
-Intellectual Property. Zope Corporation is a sponsoring member of
-the PSF.
+year, the PythonLabs team moved to Digital Creations, which became
+Zope Corporation. In 2001, the Python Software Foundation (PSF, see
+https://www.python.org/psf/) was formed, a non-profit organization
+created specifically to own Python-related Intellectual Property.
+Zope Corporation was a sponsoring member of the PSF.
All Python releases are Open Source (see http://www.opensource.org for
the Open Source Definition). Historically, most, but not all, Python
@@ -74,8 +73,9 @@
distribute, and otherwise use Python alone or in any derivative version,
provided, however, that PSF's License Agreement and PSF's notice of copyright,
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2010,
-2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are
-retained in Python alone or in any derivative version prepared by Licensee.
+2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Python
Software Foundation;
+All Rights Reserved" are retained in Python alone or in any derivative version
+prepared by Licensee.
3. In the event Licensee prepares a derivative work that is based on
or incorporates Python or any part thereof, and wants to make
@@ -180,9 +180,9 @@
Agreement, Licensee may substitute the following text (omitting the
quotes): "Python 1.6.1 is made available subject to the terms and
conditions in CNRI's License Agreement. This Agreement together with
-Python 1.6.1 may be located on the Internet using the following
+Python 1.6.1 may be located on the internet using the following
unique, persistent identifier (known as a handle): 1895.22/1013. This
-Agreement may also be obtained from a proxy server on the Internet
+Agreement may also be obtained from a proxy server on the internet
using the following URL: http://hdl.handle.net/1895.22/1013".
3. In the event Licensee prepares a derivative work that is based on
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/typing_extensions-4.3.0/PKG-INFO
new/typing_extensions-4.4.0/PKG-INFO
--- old/typing_extensions-4.3.0/PKG-INFO 1970-01-01 01:00:00.000000000
+0100
+++ new/typing_extensions-4.4.0/PKG-INFO 1970-01-01 01:00:00.000000000
+0100
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: typing_extensions
-Version: 4.3.0
+Version: 4.4.0
Summary: Backported and Experimental Type Hints for Python 3.7+
Keywords:
annotations,backport,checker,checking,function,hinting,hints,type,typechecking,typehinting,typehints,typing
Author-email: "Guido van Rossum, Jukka Lehtosalo, ??ukasz Langa, Michael Lee"
<[email protected]>
@@ -35,7 +35,7 @@
- Enable use of new type system features on older Python versions. For example,
`typing.TypeGuard` is new in Python 3.10, but `typing_extensions` allows
- users on Python 3.6 through 3.9 to use it too.
+ users on previous Python versions to use it too.
- Enable experimentation with new type system PEPs before they are accepted and
added to the `typing` module.
@@ -62,7 +62,9 @@
- Experimental features
- - (Currently none)
+ - `override` (see PEP 698)
+ - The `default=` argument to `TypeVar`, `ParamSpec`, and `TypeVarTuple` (see
PEP 696)
+ - The `infer_variance=` argument to `TypeVar` (see PEP 695)
- In `typing` since Python 3.11
@@ -77,13 +79,13 @@
- `reveal_type`
- `Required` (see PEP 655)
- `Self` (see PEP 673)
- - `TypeVarTuple` (see PEP 646)
+ - `TypeVarTuple` (see PEP 646; the `typing_extensions` version supports the
`default=` argument from PEP 696)
- `Unpack` (see PEP 646)
- In `typing` since Python 3.10
- `Concatenate` (see PEP 612)
- - `ParamSpec` (see PEP 612)
+ - `ParamSpec` (see PEP 612; the `typing_extensions` version supports the
`default=` argument from PEP 696)
- `ParamSpecArgs` (see PEP 612)
- `ParamSpecKwargs` (see PEP 612)
- `TypeAlias` (see PEP 613)
@@ -123,7 +125,6 @@
- `Counter`
- `DefaultDict`
- `Deque`
- - `NamedTuple`
- `NewType`
- `NoReturn`
- `overload`
@@ -132,6 +133,13 @@
- `TYPE_CHECKING`
- `get_type_hints`
+- The following have always been present in `typing`, but the
`typing_extensions` versions provide
+ additional features:
+
+ - `Any` (supports inheritance since Python 3.11)
+ - `NamedTuple` (supports multiple inheritance with `Generic` since Python
3.11)
+ - `TypeVar` (see PEPs 695 and 696)
+
# Other Notes and Limitations
Certain objects were changed after they were added to `typing`, and
@@ -152,6 +160,11 @@
`@typing_extensions.overload`.
- `NamedTuple` was changed in Python 3.11 to allow for multiple inheritance
with `typing.Generic`.
+- Since Python 3.11, it has been possible to inherit from `Any` at
+ runtime. `typing_extensions.Any` also provides this capability.
+- `TypeVar` gains two additional parameters, `default=` and `infer_variance=`,
+ in the draft PEPs 695 and 696, which are being considered for inclusion
+ in Python 3.12.
There are a few types whose interface was modified between different
versions of typing. For example, `typing.Sequence` was modified to
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/typing_extensions-4.3.0/README.md
new/typing_extensions-4.4.0/README.md
--- old/typing_extensions-4.3.0/README.md 2022-07-01 16:47:32.490316600
+0200
+++ new/typing_extensions-4.4.0/README.md 2022-10-07 00:35:51.300909800
+0200
@@ -8,7 +8,7 @@
- Enable use of new type system features on older Python versions. For example,
`typing.TypeGuard` is new in Python 3.10, but `typing_extensions` allows
- users on Python 3.6 through 3.9 to use it too.
+ users on previous Python versions to use it too.
- Enable experimentation with new type system PEPs before they are accepted and
added to the `typing` module.
@@ -35,7 +35,9 @@
- Experimental features
- - (Currently none)
+ - `override` (see PEP 698)
+ - The `default=` argument to `TypeVar`, `ParamSpec`, and `TypeVarTuple` (see
PEP 696)
+ - The `infer_variance=` argument to `TypeVar` (see PEP 695)
- In `typing` since Python 3.11
@@ -50,13 +52,13 @@
- `reveal_type`
- `Required` (see PEP 655)
- `Self` (see PEP 673)
- - `TypeVarTuple` (see PEP 646)
+ - `TypeVarTuple` (see PEP 646; the `typing_extensions` version supports the
`default=` argument from PEP 696)
- `Unpack` (see PEP 646)
- In `typing` since Python 3.10
- `Concatenate` (see PEP 612)
- - `ParamSpec` (see PEP 612)
+ - `ParamSpec` (see PEP 612; the `typing_extensions` version supports the
`default=` argument from PEP 696)
- `ParamSpecArgs` (see PEP 612)
- `ParamSpecKwargs` (see PEP 612)
- `TypeAlias` (see PEP 613)
@@ -96,7 +98,6 @@
- `Counter`
- `DefaultDict`
- `Deque`
- - `NamedTuple`
- `NewType`
- `NoReturn`
- `overload`
@@ -105,6 +106,13 @@
- `TYPE_CHECKING`
- `get_type_hints`
+- The following have always been present in `typing`, but the
`typing_extensions` versions provide
+ additional features:
+
+ - `Any` (supports inheritance since Python 3.11)
+ - `NamedTuple` (supports multiple inheritance with `Generic` since Python
3.11)
+ - `TypeVar` (see PEPs 695 and 696)
+
# Other Notes and Limitations
Certain objects were changed after they were added to `typing`, and
@@ -125,6 +133,11 @@
`@typing_extensions.overload`.
- `NamedTuple` was changed in Python 3.11 to allow for multiple inheritance
with `typing.Generic`.
+- Since Python 3.11, it has been possible to inherit from `Any` at
+ runtime. `typing_extensions.Any` also provides this capability.
+- `TypeVar` gains two additional parameters, `default=` and `infer_variance=`,
+ in the draft PEPs 695 and 696, which are being considered for inclusion
+ in Python 3.12.
There are a few types whose interface was modified between different
versions of typing. For example, `typing.Sequence` was modified to
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/typing_extensions-4.3.0/pyproject.toml
new/typing_extensions-4.4.0/pyproject.toml
--- old/typing_extensions-4.3.0/pyproject.toml 2022-07-01 16:52:33.377626700
+0200
+++ new/typing_extensions-4.4.0/pyproject.toml 2022-10-07 00:38:03.080420700
+0200
@@ -6,11 +6,11 @@
# Project metadata
[project]
name = "typing_extensions"
-version = "4.3.0"
+version = "4.4.0"
description = "Backported and Experimental Type Hints for Python 3.7+"
readme = "README.md"
requires-python = ">=3.7"
-license.file = "LICENSE"
+license = { file = "LICENSE" }
keywords = [
"annotations",
"backport",
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/typing_extensions-4.3.0/src/test_typing_extensions.py
new/typing_extensions-4.4.0/src/test_typing_extensions.py
--- old/typing_extensions-4.3.0/src/test_typing_extensions.py 2022-07-01
16:47:32.493123500 +0200
+++ new/typing_extensions-4.4.0/src/test_typing_extensions.py 2022-10-07
00:05:54.835511200 +0200
@@ -15,13 +15,13 @@
from unittest.mock import patch
from test import ann_module, ann_module2, ann_module3
import typing
-from typing import TypeVar, Optional, Union, Any, AnyStr
+from typing import TypeVar, Optional, Union, AnyStr
from typing import T, KT, VT # Not in __all__.
from typing import Tuple, List, Dict, Iterable, Iterator, Callable
from typing import Generic
from typing import no_type_check
import typing_extensions
-from typing_extensions import NoReturn, ClassVar, Final, IntVar, Literal,
Type, NewType, TypedDict, Self
+from typing_extensions import NoReturn, Any, ClassVar, Final, IntVar, Literal,
Type, NewType, TypedDict, Self
from typing_extensions import TypeAlias, ParamSpec, Concatenate,
ParamSpecArgs, ParamSpecKwargs, TypeGuard
from typing_extensions import Awaitable, AsyncIterator, AsyncContextManager,
Required, NotRequired
from typing_extensions import Protocol, runtime, runtime_checkable, Annotated,
final, is_typeddict
@@ -29,6 +29,7 @@
from typing_extensions import assert_type, get_type_hints, get_origin, get_args
from typing_extensions import clear_overloads, get_overloads, overload
from typing_extensions import NamedTuple
+from typing_extensions import override
from _typed_dict_test_helper import FooGeneric
# Flags used to mark tests that only apply after a specific
@@ -160,6 +161,63 @@
assert_never(None)
+class OverrideTests(BaseTestCase):
+ def test_override(self):
+ class Base:
+ def foo(self): ...
+
+ class Derived(Base):
+ @override
+ def foo(self):
+ return 42
+
+ self.assertIsSubclass(Derived, Base)
+ self.assertEqual(Derived().foo(), 42)
+ self.assertEqual(dir(Base.foo), dir(Derived.foo))
+
+
+class AnyTests(BaseTestCase):
+ def test_can_subclass(self):
+ class Mock(Any): pass
+ self.assertTrue(issubclass(Mock, Any))
+ self.assertIsInstance(Mock(), Mock)
+
+ class Something: pass
+ self.assertFalse(issubclass(Something, Any))
+ self.assertNotIsInstance(Something(), Mock)
+
+ class MockSomething(Something, Mock): pass
+ self.assertTrue(issubclass(MockSomething, Any))
+ ms = MockSomething()
+ self.assertIsInstance(ms, MockSomething)
+ self.assertIsInstance(ms, Something)
+ self.assertIsInstance(ms, Mock)
+
+ class SubclassesAny(Any):
+ ...
+
+ def test_repr(self):
+ if sys.version_info >= (3, 11):
+ mod_name = 'typing'
+ else:
+ mod_name = 'typing_extensions'
+ self.assertEqual(repr(Any), f"{mod_name}.Any")
+ if sys.version_info < (3, 11): # skip for now on 3.11+ see
python/cpython#95987
+ self.assertEqual(repr(self.SubclassesAny), "<class
'test_typing_extensions.AnyTests.SubclassesAny'>")
+
+ def test_instantiation(self):
+ with self.assertRaises(TypeError):
+ Any()
+
+ self.SubclassesAny()
+
+ def test_isinstance(self):
+ with self.assertRaises(TypeError):
+ isinstance(object(), Any)
+
+ isinstance(object(), self.SubclassesAny)
+
+
class ClassVarTests(BaseTestCase):
def test_basics(self):
@@ -451,6 +509,23 @@
blah()
+ @patch(
+ f"{registry_holder.__name__}._overload_registry",
+ defaultdict(lambda: defaultdict(dict))
+ )
+ def test_overload_on_compiled_functions(self):
+ registry = registry_holder._overload_registry
+ # The registry starts out empty:
+ self.assertEqual(registry, {})
+
+ # This should just not fail:
+ overload(sum)
+ overload(print)
+
+ # No overloads are recorded:
+ self.assertEqual(get_overloads(sum), [])
+ self.assertEqual(get_overloads(print), [])
+
def set_up_overloads(self):
def blah():
pass
@@ -488,6 +563,9 @@
other_overload = some_other_func
def some_other_func(): pass
self.assertEqual(list(get_overloads(some_other_func)),
[other_overload])
+ # Unrelated function still has no overloads:
+ def not_overloaded(): pass
+ self.assertEqual(list(get_overloads(not_overloaded)), [])
# Make sure that after we clear all overloads, the registry is
# completely empty.
@@ -2401,18 +2479,20 @@
pass
def test_pickle(self):
- global P, P_co, P_contra
+ global P, P_co, P_contra, P_default
P = ParamSpec('P')
P_co = ParamSpec('P_co', covariant=True)
P_contra = ParamSpec('P_contra', contravariant=True)
+ P_default = ParamSpec('P_default', default=int)
for proto in range(pickle.HIGHEST_PROTOCOL):
with self.subTest(f'Pickle protocol {proto}'):
- for paramspec in (P, P_co, P_contra):
+ for paramspec in (P, P_co, P_contra, P_default):
z = pickle.loads(pickle.dumps(paramspec, proto))
self.assertEqual(z.__name__, paramspec.__name__)
self.assertEqual(z.__covariant__, paramspec.__covariant__)
self.assertEqual(z.__contravariant__,
paramspec.__contravariant__)
self.assertEqual(z.__bound__, paramspec.__bound__)
+ self.assertEqual(z.__default__, paramspec.__default__)
def test_eq(self):
P = ParamSpec('P')
@@ -2778,6 +2858,17 @@
self.assertEqual(t.__args__, (Unpack[Ts],))
self.assertEqual(t.__parameters__, (Ts,))
+ def test_pickle(self):
+ global Ts, Ts_default # pickle wants to reference the class by name
+ Ts = TypeVarTuple('Ts')
+ Ts_default = TypeVarTuple('Ts_default', default=Unpack[Tuple[int,
str]])
+
+ for proto in range(pickle.HIGHEST_PROTOCOL):
+ for typevartuple in (Ts, Ts_default):
+ z = pickle.loads(pickle.dumps(typevartuple, proto))
+ self.assertEqual(z.__name__, typevartuple.__name__)
+ self.assertEqual(z.__default__, typevartuple.__default__)
+
class FinalDecoratorTests(BaseTestCase):
def test_final_unmodified(self):
@@ -3005,8 +3096,11 @@
def test_typing_extensions_defers_when_possible(self):
exclude = {
'overload',
+ 'ParamSpec',
'Text',
'TypedDict',
+ 'TypeVar',
+ 'TypeVarTuple',
'TYPE_CHECKING',
'Final',
'get_type_hints',
@@ -3015,7 +3109,7 @@
if sys.version_info < (3, 10):
exclude |= {'get_args', 'get_origin'}
if sys.version_info < (3, 11):
- exclude |= {'final', 'NamedTuple'}
+ exclude |= {'final', 'NamedTuple', 'Any'}
for item in typing_extensions.__all__:
if item not in exclude and hasattr(typing, item):
self.assertIs(
@@ -3333,5 +3427,66 @@
)
+class TypeVarLikeDefaultsTests(BaseTestCase):
+ def test_typevar(self):
+ T = typing_extensions.TypeVar('T', default=int)
+ self.assertEqual(T.__default__, int)
+
+ class A(Generic[T]): ...
+ Alias = Optional[T]
+
+ def test_paramspec(self):
+ P = ParamSpec('P', default=(str, int))
+ self.assertEqual(P.__default__, (str, int))
+
+ class A(Generic[P]): ...
+ Alias = typing.Callable[P, None]
+
+ def test_typevartuple(self):
+ Ts = TypeVarTuple('Ts', default=Unpack[Tuple[str, int]])
+ self.assertEqual(Ts.__default__, Unpack[Tuple[str, int]])
+
+ class A(Generic[Unpack[Ts]]): ...
+ Alias = Optional[Unpack[Ts]]
+
+ def test_pickle(self):
+ global U, U_co, U_contra, U_default # pickle wants to reference the
class by name
+ U = typing_extensions.TypeVar('U')
+ U_co = typing_extensions.TypeVar('U_co', covariant=True)
+ U_contra = typing_extensions.TypeVar('U_contra', contravariant=True)
+ U_default = typing_extensions.TypeVar('U_default', default=int)
+ for proto in range(pickle.HIGHEST_PROTOCOL):
+ for typevar in (U, U_co, U_contra, U_default):
+ z = pickle.loads(pickle.dumps(typevar, proto))
+ self.assertEqual(z.__name__, typevar.__name__)
+ self.assertEqual(z.__covariant__, typevar.__covariant__)
+ self.assertEqual(z.__contravariant__,
typevar.__contravariant__)
+ self.assertEqual(z.__bound__, typevar.__bound__)
+ self.assertEqual(z.__default__, typevar.__default__)
+
+
+class TypeVarInferVarianceTests(BaseTestCase):
+ def test_typevar(self):
+ T = typing_extensions.TypeVar('T')
+ self.assertFalse(T.__infer_variance__)
+ T_infer = typing_extensions.TypeVar('T_infer', infer_variance=True)
+ self.assertTrue(T_infer.__infer_variance__)
+ T_noinfer = typing_extensions.TypeVar('T_noinfer',
infer_variance=False)
+ self.assertFalse(T_noinfer.__infer_variance__)
+
+ def test_pickle(self):
+ global U, U_infer # pickle wants to reference the class by name
+ U = typing_extensions.TypeVar('U')
+ U_infer = typing_extensions.TypeVar('U_infer', infer_variance=True)
+ for proto in range(pickle.HIGHEST_PROTOCOL):
+ for typevar in (U, U_infer):
+ z = pickle.loads(pickle.dumps(typevar, proto))
+ self.assertEqual(z.__name__, typevar.__name__)
+ self.assertEqual(z.__covariant__, typevar.__covariant__)
+ self.assertEqual(z.__contravariant__,
typevar.__contravariant__)
+ self.assertEqual(z.__bound__, typevar.__bound__)
+ self.assertEqual(z.__infer_variance__,
typevar.__infer_variance__)
+
+
if __name__ == '__main__':
main()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/typing_extensions-4.3.0/src/typing_extensions.py
new/typing_extensions-4.4.0/src/typing_extensions.py
--- old/typing_extensions-4.3.0/src/typing_extensions.py 2022-07-01
16:47:32.495242600 +0200
+++ new/typing_extensions-4.4.0/src/typing_extensions.py 2022-10-07
00:35:51.302703000 +0200
@@ -8,9 +8,9 @@
import typing
-# Please keep __all__ alphabetized within each category.
__all__ = [
# Super-special typing primitives.
+ 'Any',
'ClassVar',
'Concatenate',
'Final',
@@ -20,6 +20,7 @@
'ParamSpecKwargs',
'Self',
'Type',
+ 'TypeVar',
'TypeVarTuple',
'Unpack',
@@ -60,6 +61,7 @@
'Literal',
'NewType',
'overload',
+ 'override',
'Protocol',
'reveal_type',
'runtime',
@@ -149,6 +151,37 @@
T_co = typing.TypeVar('T_co', covariant=True) # Any type covariant containers.
T_contra = typing.TypeVar('T_contra', contravariant=True) # Ditto
contravariant.
+
+if sys.version_info >= (3, 11):
+ from typing import Any
+else:
+
+ class _AnyMeta(type):
+ def __instancecheck__(self, obj):
+ if self is Any:
+ raise TypeError("typing_extensions.Any cannot be used with
isinstance()")
+ return super().__instancecheck__(obj)
+
+ def __repr__(self):
+ if self is Any:
+ return "typing_extensions.Any"
+ return super().__repr__()
+
+ class Any(metaclass=_AnyMeta):
+ """Special type indicating an unconstrained type.
+ - Any is compatible with every type.
+ - Any assumed to have all methods.
+ - All values assumed to be instances of Any.
+ Note that all the above statements are true from the point of view of
+ static type checkers. At runtime, Any should not be used with instance
+ checks.
+ """
+ def __new__(cls, *args, **kwargs):
+ if cls is Any:
+ raise TypeError("Any cannot be instantiated")
+ return super().__new__(cls, *args, **kwargs)
+
+
ClassVar = typing.ClassVar
# On older versions of typing there is an internal class named "Final".
@@ -431,7 +464,7 @@
if type(self)._is_protocol:
raise TypeError('Protocols cannot be instantiated')
- class _ProtocolMeta(abc.ABCMeta):
+ class _ProtocolMeta(abc.ABCMeta): # noqa: B024
# This metaclass is a bit unfortunate and exists only because of the
lack
# of __instancehook__.
def __instancecheck__(cls, instance):
@@ -1115,6 +1148,44 @@
above.""")
+class _DefaultMixin:
+ """Mixin for TypeVarLike defaults."""
+
+ __slots__ = ()
+
+ def __init__(self, default):
+ if isinstance(default, (tuple, list)):
+ self.__default__ = tuple((typing._type_check(d, "Default must be a
type")
+ for d in default))
+ elif default:
+ self.__default__ = typing._type_check(default, "Default must be a
type")
+ else:
+ self.__default__ = None
+
+
+# Add default and infer_variance parameters from PEP 696 and 695
+class TypeVar(typing.TypeVar, _DefaultMixin, _root=True):
+ """Type variable."""
+
+ __module__ = 'typing'
+
+ def __init__(self, name, *constraints, bound=None,
+ covariant=False, contravariant=False,
+ default=None, infer_variance=False):
+ super().__init__(name, *constraints, bound=bound, covariant=covariant,
+ contravariant=contravariant)
+ _DefaultMixin.__init__(self, default)
+ self.__infer_variance__ = infer_variance
+
+ # for pickling:
+ try:
+ def_mod = sys._getframe(1).f_globals.get('__name__', '__main__')
+ except (AttributeError, ValueError):
+ def_mod = None
+ if def_mod != 'typing_extensions':
+ self.__module__ = def_mod
+
+
# Python 3.10+ has PEP 612
if hasattr(typing, 'ParamSpecArgs'):
ParamSpecArgs = typing.ParamSpecArgs
@@ -1179,12 +1250,32 @@
# 3.10+
if hasattr(typing, 'ParamSpec'):
- ParamSpec = typing.ParamSpec
+
+ # Add default Parameter - PEP 696
+ class ParamSpec(typing.ParamSpec, _DefaultMixin, _root=True):
+ """Parameter specification variable."""
+
+ __module__ = 'typing'
+
+ def __init__(self, name, *, bound=None, covariant=False,
contravariant=False,
+ default=None):
+ super().__init__(name, bound=bound, covariant=covariant,
+ contravariant=contravariant)
+ _DefaultMixin.__init__(self, default)
+
+ # for pickling:
+ try:
+ def_mod = sys._getframe(1).f_globals.get('__name__',
'__main__')
+ except (AttributeError, ValueError):
+ def_mod = None
+ if def_mod != 'typing_extensions':
+ self.__module__ = def_mod
+
# 3.7-3.9
else:
# Inherits from list as a workaround for Callable checks in Python < 3.9.2.
- class ParamSpec(list):
+ class ParamSpec(list, _DefaultMixin):
"""Parameter specification variable.
Usage::
@@ -1242,7 +1333,8 @@
def kwargs(self):
return ParamSpecKwargs(self)
- def __init__(self, name, *, bound=None, covariant=False,
contravariant=False):
+ def __init__(self, name, *, bound=None, covariant=False,
contravariant=False,
+ default=None):
super().__init__([self])
self.__name__ = name
self.__covariant__ = bool(covariant)
@@ -1251,6 +1343,7 @@
self.__bound__ = typing._type_check(bound, 'Bound must be a
type.')
else:
self.__bound__ = None
+ _DefaultMixin.__init__(self, default)
# for pickling:
try:
@@ -1752,9 +1845,25 @@
if hasattr(typing, "TypeVarTuple"): # 3.11+
- TypeVarTuple = typing.TypeVarTuple
+
+ # Add default Parameter - PEP 696
+ class TypeVarTuple(typing.TypeVarTuple, _DefaultMixin, _root=True):
+ """Type variable tuple."""
+
+ def __init__(self, name, *, default=None):
+ super().__init__(name)
+ _DefaultMixin.__init__(self, default)
+
+ # for pickling:
+ try:
+ def_mod = sys._getframe(1).f_globals.get('__name__',
'__main__')
+ except (AttributeError, ValueError):
+ def_mod = None
+ if def_mod != 'typing_extensions':
+ self.__module__ = def_mod
+
else:
- class TypeVarTuple:
+ class TypeVarTuple(_DefaultMixin):
"""Type variable tuple.
Usage::
@@ -1804,8 +1913,9 @@
def __iter__(self):
yield self.__unpacked__
- def __init__(self, name):
+ def __init__(self, name, *, default=None):
self.__name__ = name
+ _DefaultMixin.__init__(self, default)
# for pickling:
try:
@@ -1968,6 +2078,36 @@
return decorator
+if hasattr(typing, "override"):
+ override = typing.override
+else:
+ _F = typing.TypeVar("_F", bound=typing.Callable[..., typing.Any])
+
+ def override(__arg: _F) -> _F:
+ """Indicate that a method is intended to override a method in a base
class.
+
+ Usage:
+
+ class Base:
+ def method(self) -> None: ...
+ pass
+
+ class Child(Base):
+ @override
+ def method(self) -> None:
+ super().method()
+
+ When this decorator is applied to a method, the type checker will
+ validate that it overrides a method with the same name on a base class.
+ This helps prevent bugs that may occur when a base class is changed
+ without an equivalent change to a child class.
+
+ See PEP 698 for details.
+
+ """
+ return __arg
+
+
# We have to do some monkey patching to deal with the dual nature of
# Unpack/TypeVarTuple:
# - We want Unpack to be a kind of TypeVar so it gets accepted in