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 2023-02-25 19:54:55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-typing_extensions (Old) and /work/SRC/openSUSE:Factory/.python-typing_extensions.new.31432 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-typing_extensions" Sat Feb 25 19:54:55 2023 rev:18 rq:1067476 version:4.5.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-typing_extensions/python-typing_extensions.changes 2022-11-22 16:09:21.141776865 +0100 +++ /work/SRC/openSUSE:Factory/.python-typing_extensions.new.31432/python-typing_extensions.changes 2023-02-25 19:55:07.255269989 +0100 @@ -1,0 +2,7 @@ +Thu Feb 23 09:31:47 UTC 2023 - Adrian Schröter <adr...@suse.de> + +- update to version 4.5.0 + Details can be found here: https://pypi.org/project/typing-extensions/4.5.0/ +- obsoletes _typed_dict_test_helper.py hack + +------------------------------------------------------------------- Old: ---- _typed_dict_test_helper.py typing_extensions-4.4.0.tar.gz New: ---- typing_extensions-4.5.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-typing_extensions.spec ++++++ --- /var/tmp/diff_new_pack.4LzniP/_old 2023-02-25 19:55:07.915274057 +0100 +++ /var/tmp/diff_new_pack.4LzniP/_new 2023-02-25 19:55:07.923274106 +0100 @@ -1,7 +1,7 @@ # # spec file # -# Copyright (c) 2022 SUSE LLC +# Copyright (c) 2023 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -26,14 +26,12 @@ %endif Name: python-typing_extensions%{psuffix} -Version: 4.4.0 +Version: 4.5.0 Release: 0 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/typing_extensions-%{version}.tar.gz -# See https://github.com/python/typing_extensions/issues/61 -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} @@ -74,8 +72,6 @@ %prep %setup -q -n typing_extensions-%{version} -# This should not be necessary in the next release -[ ! -f src/_typed_dict_test_helper.py ] && cp %{SOURCE1} src/ || exit 1 %if !%{with test} %build ++++++ typing_extensions-4.4.0.tar.gz -> typing_extensions-4.5.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-4.4.0/CHANGELOG.md new/typing_extensions-4.5.0/CHANGELOG.md --- old/typing_extensions-4.4.0/CHANGELOG.md 2022-10-07 00:38:03.079741000 +0200 +++ new/typing_extensions-4.5.0/CHANGELOG.md 2023-02-15 01:16:30.774229500 +0100 @@ -1,7 +1,19 @@ +# Release 4.5.0 (February 14, 2023) + +- Runtime support for PEP 702, adding `typing_extensions.deprecated`. Patch + by Jelle Zijlstra. +- Add better default value for TypeVar `default` parameter, PEP 696. Enables + runtime check if `None` was passed as default. Patch by Marc Mueller (@cdce8p). +- The `@typing_extensions.override` decorator now sets the `.__override__` + attribute. Patch by Steven Troxler. +- Fix `get_type_hints()` on cross-module inherited `TypedDict` in 3.9 and 3.10. + Patch by Carl Meyer. +- Add `frozen_default` parameter on `dataclass_transform`. Patch by Erik De Bonte. + # 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 + 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). diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-4.4.0/PKG-INFO new/typing_extensions-4.5.0/PKG-INFO --- old/typing_extensions-4.4.0/PKG-INFO 1970-01-01 01:00:00.000000000 +0100 +++ new/typing_extensions-4.5.0/PKG-INFO 1970-01-01 01:00:00.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: typing_extensions -Version: 4.4.0 +Version: 4.5.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" <levkivs...@gmail.com> @@ -17,6 +17,7 @@ Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 +Classifier: Programming Language :: Python :: 3.11 Classifier: Topic :: Software Development Project-URL: Bug Tracker, https://github.com/python/typing_extensions/issues Project-URL: Changes, https://github.com/python/typing_extensions/blob/main/CHANGELOG.md @@ -62,48 +63,49 @@ - Experimental features - - `override` (see PEP 698) - - The `default=` argument to `TypeVar`, `ParamSpec`, and `TypeVarTuple` (see PEP 696) - - The `infer_variance=` argument to `TypeVar` (see PEP 695) + - `override` (see [PEP 698](https://peps.python.org/pep-0698/)) + - The `default=` argument to `TypeVar`, `ParamSpec`, and `TypeVarTuple` (see [PEP 696](https://peps.python.org/pep-0696/)) + - The `infer_variance=` argument to `TypeVar` (see [PEP 695](https://peps.python.org/pep-0695/)) + - The `@deprecated` decorator (see [PEP 702](https://peps.python.org/pep-0702/)) - In `typing` since Python 3.11 - `assert_never` - `assert_type` - `clear_overloads` - - `@dataclass_transform()` (see PEP 681) + - `@dataclass_transform()` (see [PEP 681](https://peps.python.org/pep-0681/)) - `get_overloads` - - `LiteralString` (see PEP 675) + - `LiteralString` (see [PEP 675](https://peps.python.org/pep-0675/)) - `Never` - - `NotRequired` (see PEP 655) + - `NotRequired` (see [PEP 655](https://peps.python.org/pep-0655/)) - `reveal_type` - - `Required` (see PEP 655) - - `Self` (see PEP 673) - - `TypeVarTuple` (see PEP 646; the `typing_extensions` version supports the `default=` argument from PEP 696) - - `Unpack` (see PEP 646) + - `Required` (see [PEP 655](https://peps.python.org/pep-0655/)) + - `Self` (see [PEP 673](https://peps.python.org/pep-0673/)) + - `TypeVarTuple` (see [PEP 646](https://peps.python.org/pep-0646/); the `typing_extensions` version supports the `default=` argument from [PEP 696](https://peps.python.org/pep-0696/)) + - `Unpack` (see [PEP 646](https://peps.python.org/pep-0646/)) - In `typing` since Python 3.10 - - `Concatenate` (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) - - `TypeGuard` (see PEP 647) + - `Concatenate` (see [PEP 612](https://peps.python.org/pep-0612/)) + - `ParamSpec` (see [PEP 612](https://peps.python.org/pep-0612/); the `typing_extensions` version supports the `default=` argument from [PEP 696](https://peps.python.org/pep-0696/)) + - `ParamSpecArgs` (see [PEP 612](https://peps.python.org/pep-0612/)) + - `ParamSpecKwargs` (see [PEP 612](https://peps.python.org/pep-0612/)) + - `TypeAlias` (see [PEP 613](https://peps.python.org/pep-0613/)) + - `TypeGuard` (see [PEP 647](https://peps.python.org/pep-0647/)) - `is_typeddict` - In `typing` since Python 3.9 - - `Annotated` (see PEP 593) + - `Annotated` (see [PEP 593](https://peps.python.org/pep-0593/)) - In `typing` since Python 3.8 - - `final` (see PEP 591) - - `Final` (see PEP 591) - - `Literal` (see PEP 586) - - `Protocol` (see PEP 544) - - `runtime_checkable` (see PEP 544) - - `TypedDict` (see PEP 589) + - `final` (see [PEP 591](https://peps.python.org/pep-0591/)) + - `Final` (see [PEP 591](https://peps.python.org/pep-0591/)) + - `Literal` (see [PEP 586](https://peps.python.org/pep-0586/)) + - `Protocol` (see [PEP 544](https://peps.python.org/pep-0544/)) + - `runtime_checkable` (see [PEP 544](https://peps.python.org/pep-0544/)) + - `TypedDict` (see [PEP 589](https://peps.python.org/pep-0589/)) - `get_origin` (`typing_extensions` provides this function only in Python 3.7+) - `get_args` (`typing_extensions` provides this function only in Python 3.7+) @@ -119,7 +121,7 @@ - `AsyncIterator` - `Awaitable` - `ChainMap` - - `ClassVar` (see PEP 526) + - `ClassVar` (see [PEP 526](https://peps.python.org/pep-0526/)) - `ContextManager` - `Coroutine` - `Counter` @@ -138,7 +140,7 @@ - `Any` (supports inheritance since Python 3.11) - `NamedTuple` (supports multiple inheritance with `Generic` since Python 3.11) - - `TypeVar` (see PEPs 695 and 696) + - `TypeVar` (see PEPs [695](https://peps.python.org/pep-0695/) and [696](https://peps.python.org/pep-0696/)) # Other Notes and Limitations @@ -163,7 +165,7 @@ - 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 the draft PEPs [695](https://peps.python.org/pep-0695/) and [696](https://peps.python.org/pep-0696/), which are being considered for inclusion in Python 3.12. There are a few types whose interface was modified between different @@ -177,7 +179,7 @@ versions of the typing module: - `ParamSpec` and `Concatenate` will not work with `get_args` and - `get_origin`. Certain PEP 612 special cases in user-defined + `get_origin`. Certain [PEP 612](https://peps.python.org/pep-0612/) special cases in user-defined `Generic`s are also not available. These types are only guaranteed to work for static type checking. @@ -186,4 +188,3 @@ To run tests, navigate into the appropriate source directory and run `test_typing_extensions.py`. - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-4.4.0/README.md new/typing_extensions-4.5.0/README.md --- old/typing_extensions-4.4.0/README.md 2022-10-07 00:35:51.300909800 +0200 +++ new/typing_extensions-4.5.0/README.md 2023-02-15 01:13:43.618730800 +0100 @@ -35,48 +35,49 @@ - Experimental features - - `override` (see PEP 698) - - The `default=` argument to `TypeVar`, `ParamSpec`, and `TypeVarTuple` (see PEP 696) - - The `infer_variance=` argument to `TypeVar` (see PEP 695) + - `override` (see [PEP 698](https://peps.python.org/pep-0698/)) + - The `default=` argument to `TypeVar`, `ParamSpec`, and `TypeVarTuple` (see [PEP 696](https://peps.python.org/pep-0696/)) + - The `infer_variance=` argument to `TypeVar` (see [PEP 695](https://peps.python.org/pep-0695/)) + - The `@deprecated` decorator (see [PEP 702](https://peps.python.org/pep-0702/)) - In `typing` since Python 3.11 - `assert_never` - `assert_type` - `clear_overloads` - - `@dataclass_transform()` (see PEP 681) + - `@dataclass_transform()` (see [PEP 681](https://peps.python.org/pep-0681/)) - `get_overloads` - - `LiteralString` (see PEP 675) + - `LiteralString` (see [PEP 675](https://peps.python.org/pep-0675/)) - `Never` - - `NotRequired` (see PEP 655) + - `NotRequired` (see [PEP 655](https://peps.python.org/pep-0655/)) - `reveal_type` - - `Required` (see PEP 655) - - `Self` (see PEP 673) - - `TypeVarTuple` (see PEP 646; the `typing_extensions` version supports the `default=` argument from PEP 696) - - `Unpack` (see PEP 646) + - `Required` (see [PEP 655](https://peps.python.org/pep-0655/)) + - `Self` (see [PEP 673](https://peps.python.org/pep-0673/)) + - `TypeVarTuple` (see [PEP 646](https://peps.python.org/pep-0646/); the `typing_extensions` version supports the `default=` argument from [PEP 696](https://peps.python.org/pep-0696/)) + - `Unpack` (see [PEP 646](https://peps.python.org/pep-0646/)) - In `typing` since Python 3.10 - - `Concatenate` (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) - - `TypeGuard` (see PEP 647) + - `Concatenate` (see [PEP 612](https://peps.python.org/pep-0612/)) + - `ParamSpec` (see [PEP 612](https://peps.python.org/pep-0612/); the `typing_extensions` version supports the `default=` argument from [PEP 696](https://peps.python.org/pep-0696/)) + - `ParamSpecArgs` (see [PEP 612](https://peps.python.org/pep-0612/)) + - `ParamSpecKwargs` (see [PEP 612](https://peps.python.org/pep-0612/)) + - `TypeAlias` (see [PEP 613](https://peps.python.org/pep-0613/)) + - `TypeGuard` (see [PEP 647](https://peps.python.org/pep-0647/)) - `is_typeddict` - In `typing` since Python 3.9 - - `Annotated` (see PEP 593) + - `Annotated` (see [PEP 593](https://peps.python.org/pep-0593/)) - In `typing` since Python 3.8 - - `final` (see PEP 591) - - `Final` (see PEP 591) - - `Literal` (see PEP 586) - - `Protocol` (see PEP 544) - - `runtime_checkable` (see PEP 544) - - `TypedDict` (see PEP 589) + - `final` (see [PEP 591](https://peps.python.org/pep-0591/)) + - `Final` (see [PEP 591](https://peps.python.org/pep-0591/)) + - `Literal` (see [PEP 586](https://peps.python.org/pep-0586/)) + - `Protocol` (see [PEP 544](https://peps.python.org/pep-0544/)) + - `runtime_checkable` (see [PEP 544](https://peps.python.org/pep-0544/)) + - `TypedDict` (see [PEP 589](https://peps.python.org/pep-0589/)) - `get_origin` (`typing_extensions` provides this function only in Python 3.7+) - `get_args` (`typing_extensions` provides this function only in Python 3.7+) @@ -92,7 +93,7 @@ - `AsyncIterator` - `Awaitable` - `ChainMap` - - `ClassVar` (see PEP 526) + - `ClassVar` (see [PEP 526](https://peps.python.org/pep-0526/)) - `ContextManager` - `Coroutine` - `Counter` @@ -111,7 +112,7 @@ - `Any` (supports inheritance since Python 3.11) - `NamedTuple` (supports multiple inheritance with `Generic` since Python 3.11) - - `TypeVar` (see PEPs 695 and 696) + - `TypeVar` (see PEPs [695](https://peps.python.org/pep-0695/) and [696](https://peps.python.org/pep-0696/)) # Other Notes and Limitations @@ -136,7 +137,7 @@ - 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 the draft PEPs [695](https://peps.python.org/pep-0695/) and [696](https://peps.python.org/pep-0696/), which are being considered for inclusion in Python 3.12. There are a few types whose interface was modified between different @@ -150,7 +151,7 @@ versions of the typing module: - `ParamSpec` and `Concatenate` will not work with `get_args` and - `get_origin`. Certain PEP 612 special cases in user-defined + `get_origin`. Certain [PEP 612](https://peps.python.org/pep-0612/) special cases in user-defined `Generic`s are also not available. These types are only guaranteed to work for static type checking. @@ -158,4 +159,4 @@ ## Running tests To run tests, navigate into the appropriate source directory and run -`test_typing_extensions.py`. +`test_typing_extensions.py`. \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-4.4.0/pyproject.toml new/typing_extensions-4.5.0/pyproject.toml --- old/typing_extensions-4.4.0/pyproject.toml 2022-10-07 00:38:03.080420700 +0200 +++ new/typing_extensions-4.5.0/pyproject.toml 2023-02-15 01:16:30.774688000 +0100 @@ -6,7 +6,7 @@ # Project metadata [project] name = "typing_extensions" -version = "4.4.0" +version = "4.5.0" description = "Backported and Experimental Type Hints for Python 3.7+" readme = "README.md" requires-python = ">=3.7" @@ -38,6 +38,7 @@ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Topic :: Software Development", ] @@ -56,5 +57,5 @@ email = "levkivs...@gmail.com" [tool.flit.sdist] -include = ["CHANGELOG.md", "README.md", "*/test*.py"] +include = ["CHANGELOG.md", "README.md", "*/*test*.py"] exclude = [] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-4.4.0/src/_typed_dict_test_helper.py new/typing_extensions-4.5.0/src/_typed_dict_test_helper.py --- old/typing_extensions-4.4.0/src/_typed_dict_test_helper.py 1970-01-01 01:00:00.000000000 +0100 +++ new/typing_extensions-4.5.0/src/_typed_dict_test_helper.py 2022-12-31 20:31:45.655964100 +0100 @@ -0,0 +1,18 @@ +from __future__ import annotations + +from typing import Generic, Optional, T +from typing_extensions import TypedDict + + +# this class must not be imported into test_typing_extensions.py at top level, otherwise +# the test_get_type_hints_cross_module_subclass test will pass for the wrong reason +class _DoNotImport: + pass + + +class Foo(TypedDict): + a: _DoNotImport + + +class FooGeneric(TypedDict, Generic[T]): + a: Optional[T] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-4.4.0/src/test_typing_extensions.py new/typing_extensions-4.5.0/src/test_typing_extensions.py --- old/typing_extensions-4.4.0/src/test_typing_extensions.py 2022-10-07 00:05:54.835511200 +0200 +++ new/typing_extensions-4.5.0/src/test_typing_extensions.py 2023-02-15 01:13:43.620018500 +0100 @@ -29,8 +29,9 @@ 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 +from typing_extensions import override, deprecated +from _typed_dict_test_helper import Foo, FooGeneric +import warnings # Flags used to mark tests that only apply after a specific # version of the typing module. @@ -41,6 +42,10 @@ # 3.11 makes runtime type checks (_type_check) more lenient. TYPING_3_11_0 = sys.version_info[:3] >= (3, 11, 0) +# https://github.com/python/cpython/pull/27017 was backported into some 3.9 and 3.10 +# versions, but not all +HAS_FORWARD_MODULE = "module" in inspect.signature(typing._type_check).parameters + class BaseTestCase(TestCase): def assertIsSubclass(self, cls, class_or_tuple, msg=None): @@ -164,16 +169,184 @@ class OverrideTests(BaseTestCase): def test_override(self): class Base: - def foo(self): ... + def normal_method(self): ... + @staticmethod + def static_method_good_order(): ... + @staticmethod + def static_method_bad_order(): ... + @staticmethod + def decorator_with_slots(): ... class Derived(Base): @override - def foo(self): + def normal_method(self): + return 42 + + @staticmethod + @override + def static_method_good_order(): return 42 + @override + @staticmethod + def static_method_bad_order(): + return 42 + + self.assertIsSubclass(Derived, Base) - self.assertEqual(Derived().foo(), 42) - self.assertEqual(dir(Base.foo), dir(Derived.foo)) + instance = Derived() + self.assertEqual(instance.normal_method(), 42) + self.assertIs(True, instance.normal_method.__override__) + self.assertEqual(Derived.static_method_good_order(), 42) + self.assertIs(True, Derived.static_method_good_order.__override__) + self.assertEqual(Derived.static_method_bad_order(), 42) + self.assertIs(False, hasattr(Derived.static_method_bad_order, "__override__")) + + +class DeprecatedTests(BaseTestCase): + def test_dunder_deprecated(self): + @deprecated("A will go away soon") + class A: + pass + + self.assertEqual(A.__deprecated__, "A will go away soon") + self.assertIsInstance(A, type) + + @deprecated("b will go away soon") + def b(): + pass + + self.assertEqual(b.__deprecated__, "b will go away soon") + self.assertIsInstance(b, types.FunctionType) + + @overload + @deprecated("no more ints") + def h(x: int) -> int: ... + @overload + def h(x: str) -> str: ... + def h(x): + return x + + overloads = get_overloads(h) + self.assertEqual(len(overloads), 2) + self.assertEqual(overloads[0].__deprecated__, "no more ints") + + def test_class(self): + @deprecated("A will go away soon") + class A: + pass + + with self.assertWarnsRegex(DeprecationWarning, "A will go away soon"): + A() + with self.assertRaises(TypeError): + A(42) + + @deprecated("HasInit will go away soon") + class HasInit: + def __init__(self, x): + self.x = x + + with self.assertWarnsRegex(DeprecationWarning, "HasInit will go away soon"): + instance = HasInit(42) + self.assertEqual(instance.x, 42) + + has_new_called = False + + @deprecated("HasNew will go away soon") + class HasNew: + def __new__(cls, x): + nonlocal has_new_called + has_new_called = True + return super().__new__(cls) + + def __init__(self, x) -> None: + self.x = x + + with self.assertWarnsRegex(DeprecationWarning, "HasNew will go away soon"): + instance = HasNew(42) + self.assertEqual(instance.x, 42) + self.assertTrue(has_new_called) + new_base_called = False + + class NewBase: + def __new__(cls, x): + nonlocal new_base_called + new_base_called = True + return super().__new__(cls) + + def __init__(self, x) -> None: + self.x = x + + @deprecated("HasInheritedNew will go away soon") + class HasInheritedNew(NewBase): + pass + + with self.assertWarnsRegex(DeprecationWarning, "HasInheritedNew will go away soon"): + instance = HasInheritedNew(42) + self.assertEqual(instance.x, 42) + self.assertTrue(new_base_called) + + def test_function(self): + @deprecated("b will go away soon") + def b(): + pass + + with self.assertWarnsRegex(DeprecationWarning, "b will go away soon"): + b() + + def test_method(self): + class Capybara: + @deprecated("x will go away soon") + def x(self): + pass + + instance = Capybara() + with self.assertWarnsRegex(DeprecationWarning, "x will go away soon"): + instance.x() + + def test_property(self): + class Capybara: + @property + @deprecated("x will go away soon") + def x(self): + pass + + @property + def no_more_setting(self): + return 42 + + @no_more_setting.setter + @deprecated("no more setting") + def no_more_setting(self, value): + pass + + instance = Capybara() + with self.assertWarnsRegex(DeprecationWarning, "x will go away soon"): + instance.x + + with warnings.catch_warnings(): + warnings.simplefilter("error") + self.assertEqual(instance.no_more_setting, 42) + + with self.assertWarnsRegex(DeprecationWarning, "no more setting"): + instance.no_more_setting = 42 + + def test_category(self): + @deprecated("c will go away soon", category=RuntimeWarning) + def c(): + pass + + with self.assertWarnsRegex(RuntimeWarning, "c will go away soon"): + c() + + def test_turn_off_warnings(self): + @deprecated("d will go away soon", category=None) + def d(): + pass + + with warnings.catch_warnings(): + warnings.simplefilter("error") + d() class AnyTests(BaseTestCase): @@ -509,6 +682,10 @@ blah() + @skipIf( + sys.implementation.name == "pypy", + "sum() and print() are not compiled in pypy" + ) @patch( f"{registry_holder.__name__}._overload_registry", defaultdict(lambda: defaultdict(dict)) @@ -900,14 +1077,14 @@ pass def test_async_iterable(self): - base_it = range(10) # type: Iterator[int] + base_it: Iterator[int] = range(10) it = AsyncIteratorWrapper(base_it) self.assertIsInstance(it, typing_extensions.AsyncIterable) self.assertIsInstance(it, typing_extensions.AsyncIterable) self.assertNotIsInstance(42, typing_extensions.AsyncIterable) def test_async_iterator(self): - base_it = range(10) # type: Iterator[int] + base_it: Iterator[int] = range(10) it = AsyncIteratorWrapper(base_it) self.assertIsInstance(it, typing_extensions.AsyncIterator) self.assertNotIsInstance(42, typing_extensions.AsyncIterator) @@ -1667,7 +1844,7 @@ def test_none_treated_correctly(self): @runtime class P(Protocol): - x = None # type: int + x: int = None class B(object): pass self.assertNotIsInstance(B(), P) class C: @@ -1687,7 +1864,7 @@ def test_protocols_in_unions(self): class P(Protocol): - x = None # type: int + x: int = None Alias = typing.Union[typing.Iterable, P] Alias2 = typing.Union[P, typing.Iterable] self.assertEqual(Alias, Alias2) @@ -1748,6 +1925,10 @@ b: T +class Bar(Foo): + b: int + + class BarGeneric(FooGeneric[T], total=False): b: int @@ -1952,6 +2133,14 @@ assert is_typeddict(PointDict2D) is True assert is_typeddict(PointDict3D) is True + @skipUnless(HAS_FORWARD_MODULE, "ForwardRef.__forward_module__ was added in 3.9") + def test_get_type_hints_cross_module_subclass(self): + self.assertNotIn("_DoNotImport", globals()) + self.assertEqual( + {k: v.__name__ for k, v in get_type_hints(Bar).items()}, + {'a': "_DoNotImport", 'b': "int"} + ) + def test_get_type_hints_generic(self): self.assertEqual( get_type_hints(BarGeneric), @@ -2346,7 +2535,7 @@ exec('Alias: TypeAlias = Employee', globals(), ns) def test_canonical_usage_with_type_comment(self): - Alias = Employee # type: TypeAlias + Alias: TypeAlias = Employee def test_cannot_instantiate(self): with self.assertRaises(TypeError): @@ -2967,6 +3156,7 @@ "eq_default": True, "order_default": False, "kw_only_default": True, + "frozen_default": False, "field_specifiers": (), "kwargs": {}, } @@ -2997,6 +3187,7 @@ "eq_default": True, "order_default": True, "kw_only_default": False, + "frozen_default": False, "field_specifiers": (), "kwargs": {"make_everything_awesome": True}, } @@ -3028,6 +3219,7 @@ "eq_default": True, "order_default": True, "kw_only_default": False, + "frozen_default": False, "field_specifiers": (Field,), "kwargs": {}, } @@ -3095,6 +3287,7 @@ def test_typing_extensions_defers_when_possible(self): exclude = { + 'dataclass_transform', 'overload', 'ParamSpec', 'Text', @@ -3435,6 +3628,12 @@ class A(Generic[T]): ... Alias = Optional[T] + def test_typevar_none(self): + U = typing_extensions.TypeVar('U') + U_None = typing_extensions.TypeVar('U_None', default=None) + self.assertEqual(U.__default__, None) + self.assertEqual(U_None.__default__, type(None)) + def test_paramspec(self): P = ParamSpec('P', default=(str, int)) self.assertEqual(P.__default__, (str, int)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/typing_extensions-4.4.0/src/typing_extensions.py new/typing_extensions-4.5.0/src/typing_extensions.py --- old/typing_extensions-4.4.0/src/typing_extensions.py 2022-10-07 00:35:51.302703000 +0200 +++ new/typing_extensions-4.5.0/src/typing_extensions.py 2023-02-15 01:13:43.620782100 +0100 @@ -2,10 +2,12 @@ import collections import collections.abc import functools +import inspect import operator import sys import types as _types import typing +import warnings __all__ = [ @@ -51,6 +53,7 @@ 'assert_type', 'clear_overloads', 'dataclass_transform', + 'deprecated', 'get_overloads', 'final', 'get_args', @@ -728,6 +731,8 @@ _typeddict_new.__text_signature__ = ('($cls, _typename, _fields=None,' ' /, *, total=True, **kwargs)') + _TAKES_MODULE = "module" in inspect.signature(typing._type_check).parameters + class _TypedDictMeta(type): def __init__(cls, name, bases, ns, total=True): super().__init__(name, bases, ns) @@ -753,8 +758,10 @@ annotations = {} own_annotations = ns.get('__annotations__', {}) msg = "TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a type" + kwds = {"module": tp_dict.__module__} if _TAKES_MODULE else {} own_annotations = { - n: typing._type_check(tp, msg) for n, tp in own_annotations.items() + n: typing._type_check(tp, msg, **kwds) + for n, tp in own_annotations.items() } required_keys = set() optional_keys = set() @@ -1157,7 +1164,7 @@ if isinstance(default, (tuple, list)): self.__default__ = tuple((typing._type_check(d, "Default must be a type") for d in default)) - elif default: + elif default != _marker: self.__default__ = typing._type_check(default, "Default must be a type") else: self.__default__ = None @@ -1171,7 +1178,7 @@ def __init__(self, name, *constraints, bound=None, covariant=False, contravariant=False, - default=None, infer_variance=False): + default=_marker, infer_variance=False): super().__init__(name, *constraints, bound=bound, covariant=covariant, contravariant=contravariant) _DefaultMixin.__init__(self, default) @@ -1258,7 +1265,7 @@ __module__ = 'typing' def __init__(self, name, *, bound=None, covariant=False, contravariant=False, - default=None): + default=_marker): super().__init__(name, bound=bound, covariant=covariant, contravariant=contravariant) _DefaultMixin.__init__(self, default) @@ -1334,7 +1341,7 @@ return ParamSpecKwargs(self) def __init__(self, name, *, bound=None, covariant=False, contravariant=False, - default=None): + default=_marker): super().__init__([self]) self.__name__ = name self.__covariant__ = bool(covariant) @@ -1850,7 +1857,7 @@ class TypeVarTuple(typing.TypeVarTuple, _DefaultMixin, _root=True): """Type variable tuple.""" - def __init__(self, name, *, default=None): + def __init__(self, name, *, default=_marker): super().__init__(name) _DefaultMixin.__init__(self, default) @@ -1913,7 +1920,7 @@ def __iter__(self): yield self.__unpacked__ - def __init__(self, name, *, default=None): + def __init__(self, name, *, default=_marker): self.__name__ = name _DefaultMixin.__init__(self, default) @@ -1993,7 +2000,8 @@ raise AssertionError("Expected code to be unreachable") -if hasattr(typing, 'dataclass_transform'): +if sys.version_info >= (3, 12): + # dataclass_transform exists in 3.11 but lacks the frozen_default parameter dataclass_transform = typing.dataclass_transform else: def dataclass_transform( @@ -2001,6 +2009,7 @@ eq_default: bool = True, order_default: bool = False, kw_only_default: bool = False, + frozen_default: bool = False, field_specifiers: typing.Tuple[ typing.Union[typing.Type[typing.Any], typing.Callable[..., typing.Any]], ... @@ -2057,6 +2066,8 @@ assumed to be True or False if it is omitted by the caller. - ``kw_only_default`` indicates whether the ``kw_only`` parameter is assumed to be True or False if it is omitted by the caller. + - ``frozen_default`` indicates whether the ``frozen`` parameter is + assumed to be True or False if it is omitted by the caller. - ``field_specifiers`` specifies a static list of supported classes or functions that describe fields, similar to ``dataclasses.field()``. @@ -2071,6 +2082,7 @@ "eq_default": eq_default, "order_default": order_default, "kw_only_default": kw_only_default, + "frozen_default": frozen_default, "field_specifiers": field_specifiers, "kwargs": kwargs, } @@ -2102,12 +2114,103 @@ This helps prevent bugs that may occur when a base class is changed without an equivalent change to a child class. + There is no runtime checking of these properties. The decorator + sets the ``__override__`` attribute to ``True`` on the decorated object + to allow runtime introspection. + See PEP 698 for details. """ + try: + __arg.__override__ = True + except (AttributeError, TypeError): + # Skip the attribute silently if it is not writable. + # AttributeError happens if the object has __slots__ or a + # read-only property, TypeError if it's a builtin class. + pass return __arg +if hasattr(typing, "deprecated"): + deprecated = typing.deprecated +else: + _T = typing.TypeVar("_T") + + def deprecated( + __msg: str, + *, + category: typing.Optional[typing.Type[Warning]] = DeprecationWarning, + stacklevel: int = 1, + ) -> typing.Callable[[_T], _T]: + """Indicate that a class, function or overload is deprecated. + + Usage: + + @deprecated("Use B instead") + class A: + pass + + @deprecated("Use g instead") + def f(): + pass + + @overload + @deprecated("int support is deprecated") + def g(x: int) -> int: ... + @overload + def g(x: str) -> int: ... + + When this decorator is applied to an object, the type checker + will generate a diagnostic on usage of the deprecated object. + + No runtime warning is issued. The decorator sets the ``__deprecated__`` + attribute on the decorated object to the deprecation message + passed to the decorator. If applied to an overload, the decorator + must be after the ``@overload`` decorator for the attribute to + exist on the overload as returned by ``get_overloads()``. + + See PEP 702 for details. + + """ + def decorator(__arg: _T) -> _T: + if category is None: + __arg.__deprecated__ = __msg + return __arg + elif isinstance(__arg, type): + original_new = __arg.__new__ + has_init = __arg.__init__ is not object.__init__ + + @functools.wraps(original_new) + def __new__(cls, *args, **kwargs): + warnings.warn(__msg, category=category, stacklevel=stacklevel + 1) + # Mirrors a similar check in object.__new__. + if not has_init and (args or kwargs): + raise TypeError(f"{cls.__name__}() takes no arguments") + if original_new is not object.__new__: + return original_new(cls, *args, **kwargs) + else: + return original_new(cls) + + __arg.__new__ = staticmethod(__new__) + __arg.__deprecated__ = __new__.__deprecated__ = __msg + return __arg + elif callable(__arg): + @functools.wraps(__arg) + def wrapper(*args, **kwargs): + warnings.warn(__msg, category=category, stacklevel=stacklevel + 1) + return __arg(*args, **kwargs) + + __arg.__deprecated__ = wrapper.__deprecated__ = __msg + return wrapper + else: + raise TypeError( + "@deprecated decorator with non-None category must be applied to " + f"a class or callable, not {__arg!r}" + ) + + return decorator + + # 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