summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-42345: Fix hash implementation of typing.Literal (GH-23383)Miss Islington (bot)2020-11-191-0/+5
| | | | | | | | | | Fix hash implementation of `typing.Literal`. Update docs regarding `typing.Litaral` caching. Base implementation was done in PR GH-23294. (cherry picked from commit 1b54077ff6f5c1379e097e9f8e8648da9826d6ec) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* [3.9] bpo-42345: Fix three issues with typing.Literal parameters (GH-23294) ↵Yurii Karabas2020-11-171-0/+25
| | | | | | | | | | | | | (GH-23335) Literal equality no longer depends on the order of arguments. Fix issue related to `typing.Literal` caching by adding `typed` parameter to `typing._tp_cache` function. Add deduplication of `typing.Literal` arguments. (cherry picked from commit f03d318ca42578e45405717aedd4ac26ea52aaed) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-42233: Correctly repr GenericAlias when used with typing module (GH-23081)Miss Islington (bot)2020-11-071-0/+7
| | | | | | | | | | | | | | | | | | Noticed by @serhiy-storchaka in the bpo. `typing`'s types were not showing the parameterized generic. Eg. previously: ```python >>> typing.Union[dict[str, float], list[int]] 'typing.Union[dict, list]' ``` Now: ```python >>> typing.Union[dict[str, float], list[int]] 'typing.Union[dict[str, float], list[int]]' ``` Automerge-Triggered-By: GH:gvanrossum (cherry picked from commit 1f7dfb277e5b88cddc13e5024766be787a3e9127) Co-authored-by: kj <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-41341: Recursive evaluation of ForwardRef in get_type_hints (GH-21553)Miss Islington (bot)2020-07-261-0/+6
| | | | | | | | The issue raised by recursive evaluation is infinite recursion with recursive types. In that case, only the first recursive ForwardRef is evaluated. (cherry picked from commit 653f420b53a3aa87316cef59de8d3f5d9e11deb4) Co-authored-by: wyfo <joperez@hotmail.fr>
* bpo-39168: Remove the __new__ method of typing.Generic (GH-21327)Miss Islington (bot)2020-07-051-2/+0
| | | | | | Automerge-Triggered-By: @gvanrossum (cherry picked from commit 7fed75597fac11f9a6c769e2b6c6548fe0e4049d) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
* bpo-40397: Fix subscription of nested generic alias without parameters. ↵Serhiy Storchaka2020-05-101-1/+12
| | | | (GH-20021)
* bpo-40389: Improve repr of typing.Optional (#19714)Vlad Serebrennikov2020-04-301-1/+1
|
* bpo-40443: Remove unused imports in tests (GH-19805)Victor Stinner2020-04-291-1/+1
|
* bpo-40398: Fix typing.get_args() for special generic aliases. (GH-19720)Serhiy Storchaka2020-04-271-2/+7
|
* bpo-40396: Support GenericAlias in the typing functions. (GH-19718)Serhiy Storchaka2020-04-261-1/+41
|
* bpo-39942:Fix failure in `TypeVar` when missing `__name__` (GH-19616)HongWeipeng2020-04-201-0/+7
| | | https://bugs.python.org/issue39942
* bpo-40185: Refactor typing.NamedTuple (GH-19371)Serhiy Storchaka2020-04-081-17/+11
|
* bpo-39481: Implementation for PEP 585 (#18239)Guido van Rossum2020-04-071-9/+10
| | | | | | | | | | | | This implements things like `list[int]`, which returns an object of type `types.GenericAlias`. This object mostly acts as a proxy for `list`, but has attributes `__origin__` and `__args__` that allow recovering the parts (with values `list` and `(int,)`. There is also an approximate notion of type variables; e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`. Type variables are objects of type `typing.TypeVar`.
* bpo-40182: Remove the _field_types attribute of the NamedTuple class (GH-19368)Serhiy Storchaka2020-04-041-4/+2
|
* bpo-36517: Raise error on multiple inheritance with NamedTuple (GH-19363)Serhiy Storchaka2020-04-041-0/+7
|
* bpo-40086: Update/fix test_etree test case in test_typing (GH-19189)Furkan Önder2020-03-281-4/+2
|
* bpo-39627: Fix TypedDict totality check for inherited keys (#18503)Vlad Emelianov2020-02-131-0/+32
| | | (Adapted from https://github.com/python/typing/pull/700)
* bpo-39491: Merge PEP 593 (typing.Annotated) support (#18260)Jakub Stasiak2020-02-051-0/+234
| | | | | | | | | | | | | | | | | | | | | | | | | * bpo-39491: Merge PEP 593 (typing.Annotated) support PEP 593 has been accepted some time ago. I got a green light for merging this from Till, so I went ahead and combined the code contributed to typing_extensions[1] and the documentation from the PEP 593 text[2]. My changes were limited to: * removing code designed for typing_extensions to run on older Python versions * removing some irrelevant parts of the PEP text when copying it over as documentation and otherwise changing few small bits to better serve the purpose * changing the get_type_hints signature to match reality (parameter names) I wasn't entirely sure how to go about crediting the authors but I used my best judgment, let me know if something needs changing in this regard. [1] https://github.com/python/typing/blob/8280de241fd8c8afe727c7860254b753e383b360/typing_extensions/src_py3/typing_extensions.py [2] https://github.com/python/peps/blob/17710b879882454d55f82c2d44596e8e9f8e4bff/pep-0593.rst
* Better runtime TypedDict (GH-17214)Zac Hatfield-Dodds2019-11-241-0/+7
| | | | | This patch enables downstream projects inspecting a TypedDict subclass at runtime to tell which keys are optional. This is essential for generating test data with Hypothesis or validating inputs with typeguard or pydantic.
* bpo-37838: get_type_hints for wrapped functions with forward reference ↵benedwards142019-11-211-0/+15
| | | | | | (GH-17126) https://bugs.python.org/issue37838
* bpo-38405: Make nested subclasses of typing.NamedTuple pickleable. (GH-16641)Serhiy Storchaka2019-10-081-7/+21
|
* bpo-38191: Turn warnings into errors in NamedTuple() and TypedDict(). (GH-16238)Serhiy Storchaka2019-09-171-19/+8
|
* bpo-38191: Accept arbitrary keyword names in NamedTuple() and TypedDict(). ↵Serhiy Storchaka2019-09-171-0/+60
| | | | | | | | (GH-16222) This includes such names as "cls", "self", "typename", "_typename", "fields" and "_fields". Passing positional arguments by keyword is deprecated.
* bpo-37953: Fix deprecation warnings in test_typing (GH-16133)Zackery Spytz2019-09-141-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | self.assertEquals() is deprecated. ``` ./python -We -m test test_typing Run tests sequentially 0:00:00 load avg: 0.23 [1/1] test_typing test test_typing failed -- Traceback (most recent call last): File "/home/lubuntu2/cpython/Lib/test/test_typing.py", line 2382, in test_forward_equality_gth self.assertEquals(Union[c1, c1_gth], Union[c1]) File "/home/lubuntu2/cpython/Lib/unittest/case.py", line 1390, in deprecated_func warnings.warn( DeprecationWarning: Please use assertEqual instead. test_typing failed == Tests result: FAILURE == 1 test failed: test_typing Total duration: 140 ms Tests result: FAILURE ``` https://bugs.python.org/issue37953
* bpo-37953: Fix ForwardRef hash and equality checks (GH-15400)plokmijnuhby2019-09-131-0/+116
| | | | | Ideally if we stick a ForwardRef in a dictionary we would like to reliably be able to get it out again. https://bugs.python.org/issue37953
* bpo-38008: Move builtin protocol whitelist to mapping instead of list (GH-15647)Divij Rajkumar2019-09-121-0/+8
| | | | Fixes https://bugs.python.org/issue38008
* bpo-28556: Add a regression test to typing (GH-15396)Ivan Levkivskyi2019-08-221-0/+17
| | | | | | This adds a regression test for the issue found in the Python 2 backport, see https://github.com/python/typing/issues/656 https://bugs.python.org/issue28556
* closes bpo-33758: Skip test_get_type_hints_modules_forwardref. (GH-13977)Benjamin Peterson2019-06-111-2/+2
| | | This test "works" if things are run in the right order, so it's better to use @skip than @expectedFailure here.
* bpo-29262: Add get_origin() and get_args() introspection helpers to typing ↵Ivan Levkivskyi2019-05-301-0/+37
| | | | | | | | | | (GH-13685) This is an old feature request that appears from time to time. After a year of experimenting with various introspection capabilities in `typing_inspect` on PyPI, I propose to add these two most commonly used functions: `get_origin()` and `get_args()`. These are essentially thin public wrappers around private APIs: `__origin__` and `__args__`. As discussed in the issue and on the typing tracker, exposing some public helpers instead of `__origin__` and `__args__` directly will give us more flexibility if we will decide to update the internal representation, while still maintaining backwards compatibility. The implementation is very simple an is essentially a copy from `typing_inspect` with one exception: `ClassVar` was special-cased in `typing_inspect`, but I think this special-casing doesn't really help and only makes things more complicated.
* bpo-36983: Fix typing.__all__ and add test for exported names (GH-13456)Anthony Sottile2019-05-291-0/+24
| | | https://bugs.python.org/issue36983
* bpo-37058: PEP 544: Add Protocol to typing module (GH-13585)Ivan Levkivskyi2019-05-281-7/+724
| | | | | I tried to get rid of the `_ProtocolMeta`, but unfortunately it didn'y work. My idea to return a generic alias from `@runtime_checkable` made runtime protocols unpickleable. I am not sure what is worse (a custom metaclass or having some classes unpickleable), so I decided to stick with the status quo (since there were no complains so far). So essentially this is a copy of the implementation in `typing_extensions` with two modifications: * Rename `@runtime` to `@runtime_checkable` (plus corresponding updates). * Allow protocols that extend `collections.abc.Iterable` etc.
* Add one more test for typing.Final (GH-13588)Ivan Levkivskyi2019-05-261-0/+8
|
* bpo-37049: PEP 589: Add TypedDict to typing module (GH-13573)Ivan Levkivskyi2019-05-261-1/+104
| | | | The implementation is straightforward and essentially is just copied from `typing_extensions`.
* bpo-37046: PEP 586: Add Literal to typing module (#13572)Ivan Levkivskyi2019-05-261-1/+63
| | | | The implementation is straightforward and essentially is just copied from `typing_extensions`.
* bpo-37045: PEP 591: Add final qualifiers to typing module (GH-13571)Ivan Levkivskyi2019-05-261-1/+48
| | | | The implementation is straightforward, it just mimics `ClassVar` (since the latter is also a name/access qualifier, not really a type). Also it is essentially copied from `typing_extensions`.
* bpo-36972: Add SupportsIndex (GH-13448)Paul Dagnelie2019-05-221-0/+4
| | | | In order to support typing checks calling hex(), oct() and bin() on user-defined classes, a SupportIndex protocol is required. The ability to check these at runtime would be good to add for completeness sake. This is pretty much just a copy of SupportsInt with the names tweaked.
* bpo-36921: Deprecate @coroutine for sake of async def (GH-13346)Andrew Svetlov2019-05-161-3/+2
| | | | | | The second attempt. Now deprecate `@coroutine` only, keep `yield from fut` as is. https://bugs.python.org/issue36921
* bpo-35341: Add generic version of OrderedDict to typing (GH-10850)Ismo Toijala2018-12-021-0/+16
|
* bpo-34181: Fix running Lib/test/test_typing.py as a script. (GH-8380)Serhiy Storchaka2018-07-211-2/+2
|
* bpo-28556: Don't simplify unions at runtime (GH-6841)Ivan Levkivskyi2018-05-181-12/+12
|
* Fix ClassVar as string fails when getting type hints (GH-6824)Nina Zakharenko2018-05-161-0/+24
|
* Fix a bug in Generic.__new__ (GH-6758)Ivan Levkivskyi2018-05-111-0/+3
|
* bpo-28556: Minor fixes for typing module (GH-6732)Ivan Levkivskyi2018-05-091-0/+68
| | | | This also fixes https://bugs.python.org/issue33420
* bpo-32873: Remove a name hack for generic aliases in typing module (GH-6376)Ivan Levkivskyi2018-04-051-2/+3
| | | | This removes a hack and replaces it with a proper mapping {'list': 'List', 'dict': 'Dict', ...}.
* Call super in Generic.__init_subclass__ (#6356)Ivan Levkivskyi2018-04-041-0/+19
|
* bpo-32873: Treat type variables and special typing forms as immutable by ↵Ivan Levkivskyi2018-03-261-6/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | copy and pickle (GH-6216) This also fixes python/typing#512 This also fixes python/typing#511 As was discussed in both issues, some typing forms deserve to be treated as immutable by copy and pickle modules, so that: * copy(X) is X * deepcopy(X) is X * loads(dumps(X)) is X # pickled by reference This PR adds such behaviour to: * Type variables * Special forms like Union, Any, ClassVar * Unsubscripted generic aliases to containers like List, Mapping, Iterable This not only resolves inconsistencies mentioned in the issues, but also improves backwards compatibility with previous versions of Python (including 3.6). Note that this requires some dances with __module__ for type variables (similar to NamedTuple) because the class TypeVar itself is define in typing, while type variables should get module where they were defined. https://bugs.python.org/issue32873
* bpo-31333: Re-implement ABCMeta in C (#5273)Ivan Levkivskyi2018-02-181-2/+2
| | | | This adds C versions of methods used by ABCMeta that improve performance of various ABC operations.
* bpo-32226: PEP 560: improve typing module (#4906)Ivan Levkivskyi2018-01-201-148/+90
| | | | This PR re-designs the internal typing API using the new PEP 560 features. However, there are only few minor changes in the public API.
* [bpo-28556] Minor fixes for typing module (#4710)Ivan Levkivskyi2017-12-051-2/+48
|
* bpo-31567: more decorator markup fixes in docs (GH-3959) (#3966)Éric Araujo2017-10-121-2/+2
|