Commit Graph

89 Commits

Author SHA1 Message Date
Mariatta 7799dd38e7
[3.8] Fix typo in typing.py (GH-22121) (GH-22158)
This is a trivial PR to fix a typo in a docstring in typing.py. From reverences -> references.
(cherry picked from commit 84ef33c511)

Co-authored-by: Graham Bleaney <gbleaney@gmail.com>

Automerge-Triggered-By: @Mariatta
2020-09-08 16:28:02 -07:00
Serhiy Storchaka a629d4c63c
[3.8] bpo-40398: Fix typing.get_args() for special generic aliases. (GH-19720) (GH-19857)
(cherry picked from commit 6292be7adf)
2020-05-02 11:08:00 +03:00
Miss Islington (bot) 41660cac63
bpo-39942:Fix failure in `TypeVar` when missing `__name__` (GH-19616)
https://bugs.python.org/issue39942
(cherry picked from commit a25a04fea5)

Co-authored-by: HongWeipeng <hongweichen8888@sina.com>
2020-04-20 13:24:35 -07:00
Miss Islington (bot) 44c690112d
bpo-39572: Document ’total’ flag of TypedDict (GH-18554)
(cherry picked from commit ab6423fe2d)

Co-authored-by: ananthan-123 <ananthakrishnan15.2001@gmail.com>
2020-02-18 21:24:51 -08:00
Miss Islington (bot) 58076df0c5
bpo-39493: Fix definition of IO.closed in typing.py (GH-18265)
(cherry picked from commit 2e6569b669)

Co-authored-by: Shantanu <hauntsaninja@users.noreply.github.com>
2020-01-29 21:42:38 -08:00
Miss Islington (bot) 9458c5c42b
bpo-37838: get_type_hints for wrapped functions with forward reference (GH-17126)
https://bugs.python.org/issue37838
(cherry picked from commit 0aca3a3a1e)

Co-authored-by: benedwards14 <53377856+benedwards14@users.noreply.github.com>
2019-11-21 09:43:42 -08:00
Miss Islington (bot) 7162440a72
bpo-38407: Add docstrings for typing.SupportsXXX classes. (GH-16644)
(cherry picked from commit 8252c52e57)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2019-10-08 07:14:57 -07:00
Miss Islington (bot) 10b475a151
bpo-38405: Make nested subclasses of typing.NamedTuple pickleable. (GH-16641)
(cherry picked from commit 13abda4100)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2019-10-08 07:12:38 -07:00
Miss Islington (bot) b2c2a0c02c
cleanup ababstractproperty in typing.py (GH-16432)
(cherry picked from commit 6ce03ec627)

Co-authored-by: HongWeipeng <961365124@qq.com>
2019-09-27 01:13:38 -07:00
Serhiy Storchaka 2adcd79bf9
bpo-38191: Use positional-only parameters in TypedDict(). (GH-16240) 2019-09-18 09:08:01 +03:00
Miss Islington (bot) 54ba5f19d4
bpo-38191: Accept arbitrary keyword names in NamedTuple() and TypedDict(). (GH-16222)
This includes such names as "cls", "self", "typename", "_typename",
"fields" and "_fields".
Passing positional arguments by keyword is deprecated.
(cherry picked from commit 2bf31ccab3)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2019-09-17 11:41:55 -07:00
Miss Islington (bot) e91edfed42
bpo-37953: Fix ForwardRef hash and equality checks (GH-15400)
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
(cherry picked from commit e082e7cbe4)

Co-authored-by: plokmijnuhby <39633434+plokmijnuhby@users.noreply.github.com>
2019-09-13 13:00:39 -07:00
Miss Islington (bot) 52baf90a74
bpo-38008: Move builtin protocol whitelist to mapping instead of list (GH-15647)
Fixes https://bugs.python.org/issue38008
(cherry picked from commit 692a0dc915)

Co-authored-by: Divij Rajkumar <drajkuma1@gmail.com>
2019-09-12 03:32:36 -07:00
Serhiy Storchaka 2085bd0877
bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-13700) 2019-06-01 11:00:15 +03:00
Ivan Levkivskyi 4c23aff065
bpo-29262: Add get_origin() and get_args() introspection helpers to typing (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.
2019-05-31 00:10:07 +01:00
Anthony Sottile d30da5dd9a bpo-36983: Fix typing.__all__ and add test for exported names (GH-13456)
https://bugs.python.org/issue36983
2019-05-29 11:19:37 -07:00
Ivan Levkivskyi 74d7f76e2c
bpo-37058: PEP 544: Add Protocol to typing module (GH-13585)
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.
2019-05-28 08:40:15 +01:00
Ivan Levkivskyi 135c6a56e5
bpo-37049: PEP 589: Add TypedDict to typing module (GH-13573)
The implementation is straightforward and essentially is just copied from `typing_extensions`.
2019-05-26 09:39:24 +01:00
Ivan Levkivskyi b891c465bb
bpo-37046: PEP 586: Add Literal to typing module (#13572)
The implementation is straightforward and essentially is just copied from `typing_extensions`.
2019-05-26 09:37:48 +01:00
Ivan Levkivskyi f367242d10
bpo-37045: PEP 591: Add final qualifiers to typing module (GH-13571)
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`.
2019-05-26 09:37:07 +01:00
Paul Dagnelie 4c7a46eb3c bpo-36972: Add SupportsIndex (GH-13448)
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.
2019-05-22 15:23:01 +01:00
Raymond Hettinger f7b57df0c0 bpo-36320: Switch typing.NamedTuple from OrderedDict to regular dict (GH-12396)
Also,  deprecate the *_field_types* attributes which duplicated the information in *\__annotations__*.


https://bugs.python.org/issue36320
2019-03-18 09:53:56 -07:00
Ismo Toijala 68b56d02ef bpo-35341: Add generic version of OrderedDict to typing (GH-10850) 2018-12-02 15:53:14 +00:00
Srinivas Thatiparthy (శ్రీనివాస్ తాటిపర్తి) 2d1bc537fe bpo-35202: Remove unused imports in Lib directory. (GH-10445) 2018-11-10 07:45:28 +02:00
Noah Wood 5eea0ad50c bpo-34921: Allow escaped NoReturn in get_type_hints (GH-9750) 2018-10-08 20:50:16 +02:00
Tim McNamara 5265b3a98b Fix typo in typing.py module docstring (#9014)
"explicitelly" → "explicitly"
2018-09-01 09:56:58 +01:00
João D. Ferreira 86bfed372b Fix typo in TypeVar docstring (#8142)
"can be used do declare" → "can be used to declare"
2018-07-07 16:41:20 +01:00
Serhiy Storchaka 97b523db7c bpo-33652: Remove __getstate__ and __setstate__ methods in typing. (GH-7144) 2018-05-28 11:54:56 +01:00
Serhiy Storchaka 09f3221fbb bpo-33652: Improve pickle support in the typing module. (GH-7123)
Pickles of type variables and subscripted generics are now future-proof
and compatible with older Python versions.
2018-05-26 11:19:26 -07:00
Nina Zakharenko 0e61dffdba Reverse the meaning of is_argument when used for type check (GH-7039) 2018-05-22 20:32:10 -07:00
Ivan Levkivskyi f65e31fee3
bpo-28556: Don't simplify unions at runtime (GH-6841) 2018-05-18 16:00:38 -07:00
Nina Zakharenko 2d2d3b170b Fix ClassVar as string fails when getting type hints (GH-6824) 2018-05-16 12:27:03 -04:00
Ivan Levkivskyi b551e9f0ff
Fix a bug in Generic.__new__ (GH-6758) 2018-05-10 23:10:10 -04:00
Ivan Levkivskyi 43d12a6bd8
bpo-28556: Minor fixes for typing module (GH-6732)
This also fixes https://bugs.python.org/issue33420
2018-05-09 02:23:46 +01:00
Ville Skyttä 61f82e0e33 Spelling fixes to docs, docstrings, and comments (GH-6374) 2018-04-20 16:08:45 -04:00
Ivan Levkivskyi 2a363d2930
bpo-32873: Remove a name hack for generic aliases in typing module (GH-6376)
This removes a hack and replaces it with a proper
mapping {'list': 'List', 'dict': 'Dict', ...}.
2018-04-05 01:25:15 +01:00
Ivan Levkivskyi ee566fe526
Call super in Generic.__init_subclass__ (#6356) 2018-04-04 17:00:15 +01:00
Ivan Levkivskyi 834940375a
bpo-32873: Treat type variables and special typing forms as immutable by 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
2018-03-26 23:01:12 +01:00
aetracht 4573820d2a bpo-33061: Add missing 'NoReturn' to __all__ in typing.py (GH-6127) 2018-03-19 18:41:32 +00:00
Ivan Levkivskyi d911e40e78
bpo-32226: PEP 560: improve typing module (#4906)
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.
2018-01-20 11:23:59 +00:00
Ivan Levkivskyi 29bc193210 [bpo-28556] Minor fixes for typing module (#4710) 2017-12-04 21:43:58 -05:00
Łukasz Langa f350a268a7 bpo-28556: typing.get_type_hints: better globalns for classes and modules (#3582)
This makes the default behavior (without specifying `globalns` manually) more
predictable for users, finds the right globalns automatically.

Implementation for classes assumes has a `__module__` attribute and that module
is present in `sys.modules`.  It does this recursively for all bases in the
MRO.  For modules, the implementation just uses their `__dict__` directly.

This is backwards compatible, will just raise fewer exceptions in naive user
code.

Originally implemented and reviewed at https://github.com/python/typing/pull/470.
2017-09-14 14:33:00 -04:00
Ivan Levkivskyi 65bc62052f bpo-28556: Minor updates to typing module (#3550)
* Copy changes to typing from upstream repo
* Add NEWS entry
2017-09-13 19:25:15 -04:00
Ivan Levkivskyi 29fda8db16 bpo-28556: Updates to typing module (#2076)
This PR contains two updates to typing module:

- Support ContextManager on all versions (original PR by Jelle Zijlstra).
- Add generic AsyncContextManager.
2017-06-10 12:57:56 -07:00
Ivan Levkivskyi f06e0218ef bpo-28556: Routine updates to typing (#1366)
- Add NoReturn type
- Use WrapperDescriptorType (original PR by Jim Fasarakis-Hilliard)
- Minor bug-fixes
2017-05-02 10:14:07 -07:00
Ivan Levkivskyi 365cb5bb90 bpo-28556: Fix regression that sneaked into recent typing updates (GH-270) 2017-02-24 09:28:26 -08:00
Ivan Levkivskyi abb3b8ad94 Update to typing: treat subscripted generics as proxies (#265) 2017-02-23 19:03:28 -08:00
Ivan Levkivskyi b692dc8475 bpo-28556: Various updates to typing (#28)
various updates from upstream python/typing repo:

- Added typing.Counter and typing.ChainMap generics
- More flexible typing.NamedTuple
- Improved generic ABC caching
- More tests
- Bugfixes
- Other updates

* Add Misc/NEWS entry

* Add issue number
2017-02-13 13:50:14 -08:00
Guido van Rossum 95919c096c Issue #28556: Allow defining methods in NamedTuple class syntax (#362) 2017-01-22 17:47:20 -08:00
Guido van Rossum d7adfe129c Issue #28556: various style fixes for typing.py 2017-01-22 17:43:53 -08:00