summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.10] gh-102721: Improve coverage of ↵Nikita Sobolev2023-03-171-7/+30
| | | | | | | `_collections_abc._CallableGenericAlias` (GH-102790) This is a manual backport of https://github.com/python/cpython/pull/102722 but without `typing.py` changes and without `TypeVarTuple` case, because it was added in 3.11 Automerge-Triggered-By: GH:AlexWaygood
* gh-102433: Add tests for how classes with properties interact with ↵Miss Islington (bot)2023-03-111-0/+88
| | | | | | | | `isinstance()` checks on `typing.runtime_checkable` protocols (GH-102449) (cherry picked from commit 5ffdaf748d98da6065158534720f1996a45a0072) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Carl Meyer <carl@oddbird.net>
* [3.10] gh-102444: Fix minor bugs in `test_typing` highlighted by pyflakes ↵Alex Waygood2023-03-051-11/+1
| | | | | (#102445) (#102452) (cherry picked from commit 96e1022)
* Fix unused classes in a typing test (GH-102437)Miss Islington (bot)2023-03-051-2/+2
| | | | | | | As part of investigation issue https://github.com/python/cpython/issues/102433, I discovered what I believe to be an error where two classes `CI` and `DI` are not being used. The assertions beneath them act on `C` and `D`, duplicating existing assertions in this test. (cherry picked from commit 7894bbe94ba319eb650f383cb5196424c77b2cfd) Co-authored-by: JosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com> Automerge-Triggered-By: GH:AlexWaygood
* `test_typing`: use all pickle protocols (GH-99154)Miss Islington (bot)2022-11-061-1/+1
| | | | | (cherry picked from commit a0bc75e2fdd53680cb147881bcb3754bd56aa2fa) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.10] gh-98852: Fix subscription of types.GenericAlias instances (GH-98920) ↵Serhiy Storchaka2022-11-011-0/+55
| | | | | | | (GH-98969) Fix subscription of types.GenericAlias instances containing bare generic types: for example tuple[A, T][int], where A is a generic type, and T is a type variable.
* Use more precise exception types in `assertRaises` in typing tests (GH-98650)Miss Islington (bot)2022-10-251-3/+3
| | | | | (cherry picked from commit 45c89358b71e4638455e75ba6e60b42c511bbc2a) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* gh-94245: Test pickling and copying of typing.Tuple[()] (GH-94259) (GH-94268)Miss Islington (bot)2022-06-261-2/+4
| | | | | | (cherry picked from commit 75cb3abc3bf10c7be3b374bfb4c060c36d251411) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-92106: Add test that subscription works on arbitrary TypedDicts (GH-92176)Miss Islington (bot)2022-05-031-0/+13
| | | | | (cherry picked from commit 81fb3548be5a18bf40a6f4505a02cc7fb72c9c34) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.10] bpo-46581: Propagate private vars via _GenericAlias.copy_with ↵Matt Bogosian2022-03-111-0/+21
| | | | | | | | | | | | | | | | | (GH-31061) (GH-31821) (Cherry-picked from 32bf3597922ac3f613989582afa2bff43bea8a2f.) GH-26091 added the _typevar_types and _paramspec_tvars instance variables to _GenericAlias. However, they were not propagated consistently. This commit addresses the most prominent deficiency identified in bpo-46581 (namely their absence from _GenericAlias.copy_with), but there could be others. Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-46643: Fix stringized P.args/P.kwargs with get_type_hints (GH-31238)Miss Islington (bot)2022-03-031-0/+12
| | | | | (cherry picked from commit 75d2d945b4e28ca34506b2d4902367b61a8dff82) Co-authored-by: Gregory Beauregard <greg@greg.red>
* bpo-46603: improve coverage of `typing._strip_annotations` (GH-31063)Miss Islington (bot)2022-02-191-0/+9
| | | | | (cherry picked from commit 25c0b9d243b64ccd2eeab483089eaf7e4b4d5834) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.10] bpo-46333: Honor `module` parameter in ForwardRef (GH-30536) (GH-31379)Miss Islington (bot)2022-02-171-0/+12
| | | | | | | | | | | | | | | The `module` parameter carries semantic information about the forward ref. Forward refs are different if they refer to different module even if they have the same name. This affects the `__eq__`, `__repr__` and `__hash__` methods. Co-authored-by: Andreas Hangauer <andreas.hangauer@siemens.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit 6e7b813195f9bd6a2a15c1f00ef2c0180f6c751a) Co-authored-by: aha79 <34090357+aha79@users.noreply.github.com> Automerge-Triggered-By: GH:JelleZijlstra
* bpo-46685: cover `TypeError` of `ForwardRef(1)` in `test_typing` (GH-31223)Miss Islington (bot)2022-02-091-0/+4
| | | | | (cherry picked from commit d2d1d49eaccaa83eb8873ba15f2fc9562143bc56) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.10] bpo-46676: Make ParamSpec args and kwargs equal to themselves ↵Gregory Beauregard2022-02-081-0/+8
| | | | | | | (GH-31203) (GH-31210) (cherry picked from commit c8b62bbe46e20d4b6dd556f2fa85960d1269aa45) Co-authored-by: Gregory Beauregard <greg@greg.red>
* [3.10] bpo-46655: allow stringized TypeAlias with get_type_hints (GH-31156). ↵Gregory Beauregard2022-02-071-0/+5
| | | | | | | (#31175) (cherry picked from commit 77b025be4a4cd5a3bfc1b1af560cc57e8e956c98) Co-authored-by: Gregory Beauregard <greg@greg.red>
* [3.10] bpo-46611: add coverage to instance and class checks in `typing.py` ↵Nikita Sobolev2022-02-071-0/+3
| | | | | | | (GH-31078) (GH-31182) (cherry picked from commit 067c03bf40d13393209f0138fa9c4d5980c4ff8a) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* Add more tests for variable substitution in generics (GH-31170)Miss Islington (bot)2022-02-061-0/+27
| | | | | (cherry picked from commit 3da5526136034188185d6a3fdba71e2b56577ee2) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-46482: add a test for `typing.Annotation.__new__` (GH-30821)Miss Islington (bot)2022-02-011-0/+7
| | | | | (cherry picked from commit 4c0612ad00ba45dbea2a86f7db6d21546cf243f8) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* bpo-46539: Pass status of special typeforms to forward references (GH-30926)Miss Islington (bot)2022-01-271-0/+14
| | | | | | | | | | | Previously this didn't matter because there weren't any valid code paths that could trigger a type check with a special form, but after the bug fix for `Annotated` wrapping special forms it's now possible to annotate something like `Annotated['ClassVar[int]', (3, 4)]`. This change would also be needed for proposed future changes, such as allowing `ClassVar` and `Final` to nest each other in dataclasses. (cherry picked from commit ced50051bb752a7c1e616f4b0c001f37f0354f32) Co-authored-by: Gregory Beauregard <greg@greg.red>
* bpo-44791: Fix substitution of ParamSpec in Concatenate with different ↵Miss Islington (bot)2022-01-271-3/+45
| | | | | | | | | | | parameter expressions (GH-27518) * Substitution with a list of types returns now a tuple of types. * Substitution with Concatenate returns now a Concatenate with concatenated lists of arguments. * Substitution with Ellipsis is not supported. (cherry picked from commit ecfacc362dd7fef7715dcd94f2e2ca6c622ef115) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-46529: increase coverage of `typing.Union.__repr__` method (GH-30911)Miss Islington (bot)2022-01-261-0/+9
| | | | | (cherry picked from commit d0c690b5f85c679de6059cf353fe0524e905530e) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.10] bpo-46445, bpo-46519: Re-import typing.NewType (GH-30886)Ken Jin2022-01-251-0/+1
| | | Partially reverts 65b88d5e01c845c0cfa3ff61bc8b2faec8f67a57.
* bpo-46491: Allow Annotated on outside of Final/ClassVar (GH-30864)Miss Islington (bot)2022-01-251-0/+8
| | | | | | | | We treat Annotated type arg as class-level annotation. This exempts it from checks against Final and ClassVar in order to allow using them in any nesting order. Automerge-Triggered-By: GH:gvanrossum (cherry picked from commit e1abffca45b60729c460e3e2ad50c8c1946cfd4e) Co-authored-by: Gregory Beauregard <greg@greg.red>
* [3.10] bpo-46416: Allow direct invocation of `Lib/test/test_typing.py` ↵Nikita Sobolev2022-01-241-3/+3
| | | | | | | | (GH-30641) (GH-30697) Use `__name__` (cherry picked from commit 2792d6d18eab3efeb71e6397f88db86e610541f1) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* bpo-46445: Cover multiple inheritance of `TypedDict` in `test_typing` (GH-30719)Miss Islington (bot)2022-01-211-1/+87
| | | | | (cherry picked from commit 65b88d5e01c845c0cfa3ff61bc8b2faec8f67a57) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* bpo-46437: remove useless `hasattr` from `test_typing` (GH-30704)Miss Islington (bot)2022-01-191-9/+7
| | | | | (cherry picked from commit 263c0dd16017613c5ea2fbfc270be4de2b41b5ad) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.10] bpo-46413: properly test `__{r}or__` code paths in ↵Miss Islington (bot)2022-01-191-0/+8
| | | | | | | | | | | `_SpecialGenericAlias` (GH-30640) (GH-30694) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit 0a49148e87cca11e3820cbff2abfd316986a68c6) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Automerge-Triggered-By: GH:Fidget-Spinner
* bpo-46424: [typing] cover `Annotation[arg]` invalid usage in tests (GH-30663)Miss Islington (bot)2022-01-191-0/+4
| | | | | (cherry picked from commit 32398294fb3fcf4ee74da54722fd0221c4e6cb74) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* bpo-46345: Add a test case for implicit `Optional` class attribute (GH-30535)Miss Islington (bot)2022-01-131-0/+6
| | | | | (cherry picked from commit 1de60155d5d01be2924e72fb68dd13d4fd00acd7) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* bpo-45755: [typing] Reveal class attributes of generic in generic aliases in ↵Miss Islington (bot)2021-12-171-0/+11
| | | | | | | `dir()` (GH-29962) (cherry picked from commit d6e13747161d7b634b47d2d3d212ed3be4a21fab) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-45679: Fix caching of multi-value typing.Literal (GH-29334)Miss Islington (bot)2021-10-311-0/+4
| | | | | | Literal[True, 2] is no longer equal to Literal[1, 2]. (cherry picked from commit 634984d7dbdd91e0a51a793eed4d870e139ae1e0) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-45280: Add test for empty `NamedTuple` in `test_typing` (GH-28559) ↵Miss Islington (bot)2021-09-261-0/+13
| | | | | | | | (GH-28571) Co-authored-by: Dong-hee Na <donghee.na92@gmail.com> (cherry picked from commit f56268a2cd38b3fe2be1e4361d3d8b581e73559b) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* bpo-45166: fixes `get_type_hints` failure on `Final` (GH-28279) (GH-28560)Miss Islington (bot)2021-09-251-1/+17
| | | | | | | Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit 784905dbeff68cf788bbeefe0a675af1af04affc) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* bpo-45121: Fix RecursionError when calling Protocol.__init__ from a ↵Miss Islington (bot)2021-09-081-0/+10
| | | | | | | subclass' __init__ (GH-28206) (GH-28232) (cherry picked from commit c11956a8bddd75f02ccc7b4da7e4d8123e1f3c5f) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44524: Fix cryptic TypeError message when trying to subclass special ↵Miss Islington (bot)2021-08-281-0/+16
| | | | | | | | forms in `typing` (GH-27710) This was a Python 3.9 regression. (cherry picked from commit a3a4d20d6798aa2975428d51f3a4f890248810cb) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44524: Don't modify MRO when inheriting from typing.Annotated (GH-27841)Miss Islington (bot)2021-08-251-0/+5
| | | | | (cherry picked from commit 23384a1749359f0ae7aaae052073d44b59e715a1) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-44524: Do not set _name of _SpecialForm without need (GH-27861) (GH-27871)Miss Islington (bot)2021-08-211-1/+0
| | | | | | | | | Because setting non-empty _name affects behavior of other code. In most cases __name__ can be derived from __origin__.__name__. (cherry picked from commit 4ceec495598e78f0776dd46d511dcc612a434dc3) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44524: Fix an issue wherein `_GenericAlias._name` was not properly set ↵Miss Islington (bot)2021-08-061-54/+173
| | | | | | | | | for specialforms (GH-27614) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 8bdf12e99a3dc7ada5f85bba79c2a9eb9931f5b0) Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
* bpo-44801: Check arguments in substitution of ParamSpec in Callable (GH-27585)Miss Islington (bot)2021-08-041-3/+42
| | | | | (cherry picked from commit 3875a6954741065b136650db67ac533bc70a3eac) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44806: Fix __init__ in subclasses of protocols (GH-27545)Miss Islington (bot)2021-08-021-0/+36
| | | | | | | Non-protocol subclasses of protocol ignore now the __init__ method inherited from protocol base classes. (cherry picked from commit 043cd60abed09edddc7185bcf7d039771acc734d) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44793: Fix checking the number of arguments when subscribe a generic ↵Miss Islington (bot)2021-08-021-2/+4
| | | | | | | | | | | type with ParamSpec parameter. (GH-27515) For example Callable[P, T][[int], str, float] will now raise an error. Use also term "arguments" instead of "parameters" in error message for too few/many arguments. (cherry picked from commit f92b9133ef67e77605cbd315b6b6c81036ce110e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44794: Merge tests for typing.Callable and collection.abc.Callable ↵Miss Islington (bot)2021-07-311-25/+140
| | | | | | | (GH-27507) (cherry picked from commit be4cb9089aaf58d5f90da5f9fa66dc3c6763b5a2) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44761: Change default value of NewType __module__ attr (GH-27406) (GH-27477)Miss Islington (bot)2021-07-301-0/+6
| | | | | (cherry picked from commit 7b975f81e4dba70a42c6279539a7fcfe4211b4c0) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44662: Add ability to annotate types.Union (GH-27214) (GH-27461)Miss Islington (bot)2021-07-301-0/+10
| | | | | | Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit 8182c8329c709f42218a8a17d81639ece5b7b627) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44732: Rename types.Union to types.UnionType (GH-27342)Miss Islington (bot)2021-07-261-1/+1
| | | | | | | Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit 2b8ad9e6c5f0a66e9ca2d15f85336d8a3eefefb0) Co-authored-by: Hasan <hasan.aleeyev@gmail.com>
* bpo-44353: Improve tests covering typing.NewType pickling (GH-27302) (GH-27328)Miss Islington (bot)2021-07-241-8/+9
| | | | | (cherry picked from commit a22b05da87bdfb081d6aaecfce136ae8dbb8680c) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* [3.10] bpo-44353: Expand NewType tests for complex __qualname__ (GH-27311) ↵Łukasz Langa2021-07-241-14/+42
| | | | | | | | (GH-27326) Make NewType pickleable by name. (cherry picked from commit e89ef0ad2a299770a88ece8f7a316f7d3eb65c9f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44353: Add test to cover __or__ of two NewType (GH-27259) (#27261)Miss Islington (bot)2021-07-201-4/+7
| | | | | (cherry picked from commit 4868b94c6089d457673b1ba5b5b64c2f38c435af) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44353: Refactor typing.NewType into callable class (GH-27250) (#27258)Miss Islington (bot)2021-07-201-0/+20
| | | | | (cherry picked from commit 965dd76e9060e27e2253ba8c8d21a142b178720d) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>