Jelle Zijlstra
016f4b5975
gh-119180: Improvements to ForwardRef.evaluate ( #122210 )
...
Noticed some issues while writing documentation for this method.
2024-08-11 23:42:57 +00:00
Xie Yanbo
b6c80e21c7
Fix typos in comments and docstring ( #122720 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-08-07 07:39:16 +01:00
Jelle Zijlstra
7b7b90d1ce
gh-119180: Add `annotationlib` module to support PEP 649 ( #119891 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-07-23 21:16:50 +00:00
Alex Waygood
2d3187bf20
gh-114053: Fix another edge case involving `get_type_hints`, PEP 695 and PEP 563 ( #120272 )
2024-06-25 16:53:18 +01:00
Jelle Zijlstra
9b8611eeea
gh-119180: PEP 649 compiler changes ( #119361 )
2024-06-11 13:06:49 +00:00
Jelle Zijlstra
e9875ecb5d
gh-119180: PEP 649: Add __annotate__ attributes ( #119209 )
2024-05-22 04:38:12 +02:00
Jelle Zijlstra
ec9d12be96
Rename typing._collect_parameters ( #118900 )
...
Unfortunately, released versions of typing_extensions
monkeypatch this function without the extra parameter, which makes
it so things break badly if current main is used with typing_extensions.
Fortunately, the monkeypatching is not needed on Python 3.13, because CPython
now implements PEP 696. By renaming the function, we prevent the monkeypatch
from breaking typing.py internals.
We keep the old name (raising a DeprecationWarning) to help other external users who call it.
2024-05-10 16:55:49 +00:00
Nikita Sobolev
2f4db5a04d
gh-118803: Remove `ByteString` from `typing` and `collections.abc` ( #118804 )
2024-05-09 00:37:55 +01:00
Jelle Zijlstra
aac6b019fe
gh-118772: Allow TypeVars without a default to follow those with a default when constructing aliases ( #118774 )
2024-05-08 09:54:51 -07:00
Jelle Zijlstra
71080b8a0f
gh-118660: Add second type parameter to (Async)ContextManager ( #118681 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-05-07 14:16:05 +00:00
Alex Waygood
0f8a07d158
gh-118418: Deprecate failing to pass a value to the *type_params* parameter of some private `typing` APIs ( #118695 )
2024-05-07 11:12:28 +00:00
Jelle Zijlstra
8419f01673
gh-118647: Add defaults to typing.Generator and typing.AsyncGenerator ( #118648 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-05-06 22:35:06 +00:00
Serhiy Storchaka
153b3f7530
gh-118465: Add __firstlineno__ attribute to class (GH-118475)
...
It is set by compiler with the line number of the first line of
the class definition.
2024-05-06 12:02:37 +03:00
Jelle Zijlstra
ca269e58c2
gh-116126: Implement PEP 696 ( #116129 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2024-05-03 06:17:32 -07:00
Nikita Sobolev
4a5ad8469a
gh-118418: Use a default value for `type_params` in `typing._eval_type` ( #118431 )
2024-04-30 15:44:37 +00:00
Jelle Zijlstra
d0b664ee06
gh-118168: Fix Unpack interaction with builtin aliases ( #118169 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-04-23 13:40:26 +00:00
Alex Waygood
1e3e7ce11e
gh-114053: Fix bad interaction of PEP-695, PEP-563 and ``get_type_hints`` ( #118009 )
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-04-19 13:03:44 +00:00
Jelle Zijlstra
f2132fcd2a
gh-117516: Implement typing.TypeIs ( #117517 )
...
See PEP 742.
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-04-09 10:50:37 +00:00
Jelle Zijlstra
b32789ccb9
gh-117521: Improve typing.TypeGuard docstring ( #117522 )
2024-04-04 06:39:16 -04:00
傅立业(Chris Fu)
8eec7ed714
gh-117110: Fix subclasses of typing.Any with custom constructors ( #117111 )
2024-03-29 00:19:20 +00:00
Irit Katriel
79be75735c
gh-115775: Compiler adds __static_attributes__ field to classes ( #115913 )
2024-03-26 15:18:17 +00:00
Nikita Sobolev
df4784b3b7
gh-116127: PEP-705: Add `ReadOnly` support for `TypedDict` ( #116350 )
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-03-12 07:49:39 -07:00
Mehdi Drissi
d308d33e09
gh-89547: Support for nesting special forms like Final ( #116096 )
2024-03-11 23:11:56 -07:00
Nikita Sobolev
a29998a06b
gh-116325: Raise `SyntaxError` rather than `IndexError` on ForwardRef with empty string arg ( #116341 )
2024-03-05 09:14:18 +00:00
Nikita Sobolev
a7549b03ce
gh-112281: Allow `Union` with unhashable `Annotated` metadata ( #112283 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-03-01 16:19:24 +00:00
dave-shawley
564385612c
gh-115165: Fix `typing.Annotated` for immutable types ( #115213 )
...
The return value from an annotated callable can raise any exception from
__setattr__ for the `__orig_class__` property.
2024-02-09 22:11:37 +00:00
Carl Meyer
a225520af9
gh-112903: Handle non-types in _BaseGenericAlias.__mro_entries__() ( #115191 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-02-09 12:19:09 -07:00
Alex Waygood
ed6ea3ea79
gh-113320: Reduce the number of dangerous `getattr()` calls when constructing protocol classes ( #113401 )
...
- Only attempt to figure out whether protocol members are "method members" or not if the class is marked as a runtime protocol. This information is irrelevant for non-runtime protocols; we can safely skip the risky introspection for them.
- Only do the risky getattr() calls in one place (the runtime_checkable class decorator), rather than in three places (_ProtocolMeta.__init__, _ProtocolMeta.__instancecheck__ and _ProtocolMeta.__subclasscheck__). This reduces the number of locations in typing.py where the risky introspection could go wrong.
- For runtime protocols, if determining whether a protocol member is callable or not fails, give a better error message. I think it's reasonable for us to reject runtime protocols that have members which raise strange exceptions when you try to access them. PEP-544 clearly states that all protocol member must be callable for issubclass() calls against the protocol to be valid -- and if a member raises when we try to access it, there's no way for us to figure out whether it's a callable member or not!
2024-01-05 01:01:48 +00:00
Kir
11ee912327
gh-113255: Clarify docs for `typing.reveal_type` ( #113286 )
...
Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
2023-12-20 17:21:23 +00:00
Alex Waygood
2ed20d3bd8
gh-74690: Avoid a costly type check where possible in `_ProtocolMeta.__subclasscheck__` ( #112717 )
2023-12-04 19:35:46 +00:00
Alex Waygood
c718ab92a5
gh-74690: Optimise `isinstance()` and `issubclass()` calls against runtime-checkable protocols by avoiding costly `super()` calls ( #112708 )
2023-12-04 15:41:41 +00:00
Nikita Sobolev
a35a305098
gh-112618: Make `Annotated` cache typed ( #112619 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-12-02 16:10:19 +00:00
Jelle Zijlstra
4038869423
gh-112509: Fix keys being present in both required_keys and optional_keys in TypedDict ( #112512 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-29 09:36:48 -08:00
Alex Waygood
22e411e1d1
gh-111874: Call `__set_name__` on objects that define the method inside a `typing.NamedTuple` class dictionary as part of the creation of that class ( #111876 )
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-11-27 16:34:44 +00:00
Randolf Scholz
e9d1360c9a
gh-112345: `typing.Protocol`: Let failed subclasscheck show non-method members ( #112344 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-24 09:46:08 +00:00
Nikita Sobolev
949b2cc6ea
gh-112194: Convert more examples to doctests in `typing.py` ( #112195 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-17 17:56:31 +00:00
Nikita Sobolev
7680da4583
gh-112155: Run `typing.py` doctests as part of `test_typing` ( #112156 )
2023-11-16 15:40:09 +00:00
Qua27
12c7e9d573
GH-112152: Fix typo in `typing.override` docstring ( #112158 )
2023-11-16 15:16:04 +00:00
Nikita Sobolev
5257ade0bc
gh-110682: Ignore `__match_args__` from `__instancecheck__` in protocols ( #110683 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-10-11 19:20:20 -07:00
Alex Waygood
d642c5bbf5
gh-110180: Remove unused `_PickleUsingNameMixin` class from `typing` ( #110181 )
2023-10-01 16:28:02 +01:00
Alex Waygood
e8be0c9c5a
gh-109653: `typing.py`: improve import time by creating soft-deprecated members on demand ( #109651 )
...
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
2023-09-23 08:46:35 +01:00
Jelle Zijlstra
1293fcc3c6
gh-109543: Remove unnecessary hasattr check ( #109544 )
...
Also added a new test case covering the scenario I thought this
might be about.
2023-09-19 20:15:52 -07:00
Alex Waygood
a1cbace91b
gh-105509: Simplify implementation of `typing.Annotated` ( #105510 )
2023-09-01 13:57:25 -07:00
Alex Waygood
32718f908c
gh-106309: Deprecate typing.no_type_check_decorator ( #106312 )
2023-07-13 14:30:35 +01:00
Alex Waygood
9499b0f138
gh-105974: Revert unintentional behaviour change for protocols with non-callable members and custom `__subclasshook__` methods ( #105976 )
2023-06-23 14:59:25 +00:00
Alex Waygood
7b1f0f204a
gh-105570: Deprecate unusual ways of creating empty TypedDicts ( #105780 )
...
Deprecate two methods of creating typing.TypedDict classes with 0 fields using the functional syntax: `TD = TypedDict("TD")` and `TD = TypedDict("TD", None)`. Both will be disallowed in Python 3.15. To create a TypedDict class with 0 fields, either use `class TD(TypedDict): pass` or `TD = TypedDict("TD", {})`.
2023-06-14 14:58:41 +00:00
Alex Waygood
ad56340b66
gh-105566: Deprecate unusual ways of creating `typing.NamedTuple` classes ( #105609 )
...
Deprecate creating a typing.NamedTuple class using keyword arguments to denote the fields (`NT = NamedTuple("NT", x=int, y=str)`). This will be disallowed in Python 3.15. Use the class-based syntax or the functional syntax instead.
Two methods of creating `NamedTuple` classes with 0 fields using the functional syntax are also deprecated, and will be disallowed in Python 3.15: `NT = NamedTuple("NT")` and `NT = NamedTuple("NT", None)`. To create a `NamedTuple` class with 0 fields, either use `class NT(NamedTuple): pass` or `NT = NamedTuple("NT", [])`.
2023-06-14 13:38:49 +01:00
Jelle Zijlstra
fc8037d84c
gh-104873: Add typing.get_protocol_members and typing.is_protocol ( #104878 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-14 05:35:06 -07:00
Alex Waygood
8e755923c9
Miscellaneous improvements to the typing docs ( #105529 )
...
Mostly, these are changes so that we use shorter sentences and shorter paragraphs. In particular, I've tried to make the first sentence introducing each object in the typing API short and declarative.
2023-06-09 15:08:57 +00:00
Alex Waygood
d213c2990f
Further improve docs for `typing.Annotated` ( #105498 )
2023-06-08 14:36:30 +00:00