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
Nikita Sobolev
95ebd45613
Remove outdated comment about py3.6 in `test_typing` ( #115318 )
2024-02-12 06:23:54 -08: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
Brett Cannon
03f7839703
GH-114013: fix setting `HOSTRUNNER` for `Tools/wasm/wasi.py` (GH-114097)
...
Also fix tests found failing under a pydebug build of WASI thanks to `make test` working due to this change.
2024-01-16 11:36:41 -08: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
Alex Waygood
2ed20d3bd8
gh-74690: Avoid a costly type check where possible in `_ProtocolMeta.__subclasscheck__` ( #112717 )
2023-12-04 19:35:46 +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
Brett Cannon
f489ace9e7
GH-111808: Make the default value for `test.support.infinite_recursion()` conditional on compiler optimizations (GH-112223)
...
Co-authored-by: Victor Stinner <vstinner@python.org>
2023-11-17 15:52:11 -08:00
Nikita Sobolev
7680da4583
gh-112155: Run `typing.py` doctests as part of `test_typing` ( #112156 )
2023-11-16 15:40:09 +00:00
Nikita Sobolev
82e36dba45
gh-108303: Move more `typing` related files to `Lib/test/typinganndata` ( #111825 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-08 14:19:34 +00:00
Nikita Sobolev
0e83d941be
gh-111808: Fix recursion error on WASM in `test_typing` (GH-111819)
2023-11-07 11:23:57 -08:00
Nikita Sobolev
ccc8caa858
gh-111681: minor fixes to typing doctests; remove unused imports in `test_typing` ( #111682 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-03 12:23:33 +00:00
Nikita Sobolev
ea7c26e4b8
gh-111126: Use `isinstance` instead of `assert[Not]IsInstance` in `test_typing` ( #111127 )
2023-10-20 18:03:32 +00:00
Jelle Zijlstra
d2a536b170
gh-110782: Fix crash when TypeVar is constructed with keyword args ( #110784 )
2023-10-12 16:00:12 -07: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
014aacda62
Enable ruff on `Lib/test/test_typing.py` ( #110179 )
2023-10-02 14:13:48 -06:00
Jelle Zijlstra
732ad44cec
gh-110178: Use fewer weakrefs in test_typing.py ( #110194 )
...
Confirmed that without the C changes from #108517 , this test still segfaults with only 10 weakrefs.
2023-10-02 08:03:53 -07: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
Jelle Zijlstra
482fad7f01
gh-108295: Fix crashes with TypeVar weakrefs ( #108517 )
2023-08-26 17:13:33 -07:00
Nikita Sobolev
3f61cf646d
gh-108303: Move `ann_module*.py` files to `typinganndata/` folder ( #108354 )
2023-08-23 17:42:08 +02:00
Nikita Sobolev
d93b4ac2ff
gh-101162: Forbid using issubclass() with GenericAlias as the 1st arg (GH-103369)
2023-08-11 22:12:11 +03: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
70c075c194
gh-105834: Add tests for calling `issubclass()` between two protocols ( #105835 )
...
Some parts of the implementation of `typing.Protocol` had poor test coverage
2023-06-16 15:47:55 +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
Nikita Sobolev
9d35a71a76
gh-105431: Remove unused stuff from `test_typing.NewTypeTests` ( #105432 )
2023-06-08 07:30:42 +01:00
Alex Waygood
f5df347fcf
gh-103171: Forward-port new tests for runtime-checkable protocols dec orated with `@final` ( #105473 )
...
Forward-port of the tests that were added to the 3.11 branch in #105445
2023-06-07 22:25:17 +00:00
Alex Waygood
08756dbba6
gh-105280: Ensure `isinstance([], collections.abc.Mapping)` always evaluates to `False` ( #105281 )
2023-06-05 14:10:49 +00:00
Alex Waygood
cdfb201bfa
gh-105237: Allow calling `issubclass(X, typing.Protocol)` again ( #105239 )
2023-06-05 06:36:51 -07:00
Alex Waygood
c05c31db8c
gh-105144: Runtime-checkable protocols: move all 'sanity checks' to `_ProtocolMeta.__subclasscheck__` ( #105152 )
2023-05-31 17:02:25 +00:00
Jelle Zijlstra
2cb445635e
Remove raw asserts in test_typing.py ( #104951 )
2023-05-26 15:03:02 +01:00
Tomas R
fea8632ec6
gh-104786: Remove kwargs-based TypedDict creation ( #104891 )
...
Deprecated since Python 3.11.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-25 21:14:58 +01:00
Jelle Zijlstra
2b7027d0b2
gh-104935: typing: Fix interactions between `@runtime_checkable` and `Generic` ( #104939 )
...
---------
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-25 16:43:40 +00:00
Jelle Zijlstra
fe77a99fc8
gh-104879: Fix TypeAliasType.__module__ in exec() ( #104881 )
2023-05-24 11:48:13 -07:00
Jelle Zijlstra
1497607a8e
Improve test coverage for is_typeddict ( #104884 )
...
In particular, it's important to test that is_typeddict(TypedDict)
returns False.
2023-05-24 11:46:00 -07:00
Jelle Zijlstra
c0ab7d401c
gh-104797: Allow Protocols to inherit from collections.abc.Buffer ( #104827 )
2023-05-24 08:24:53 +00:00
Sebastian Rittau
abdda5b133
gh-92871: Remove typing.{io,re} namespaces ( #92873 )
...
Closes #92871
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-05-23 13:44:26 +00:00
Alex Waygood
b870b1fa75
gh-74690: Make a typing test more resilient ( #104691 )
2023-05-20 17:13:37 -07:00
Jelle Zijlstra
8f1f3b9abd
gh-104600: Make type.__type_params__ writable ( #104634 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-19 09:04:47 -07:00
Alex Waygood
f7835fc7e9
gh-74690: Don't set special protocol attributes on non-protocol subclasses of protocols ( #104622 )
...
Don't set special protocol attributes on non-protocol subclasses of protocols
2023-05-19 00:34:40 +01:00
Alex Waygood
b27fe67f3c
gh-104555: Runtime-checkable protocols: Don't let previous calls to `isinstance()` influence whether `issubclass()` raises an exception ( #104559 )
...
Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-05-17 23:43:12 +00:00
Jelle Zijlstra
26931944dd
typing: Add more tests for TypeVar ( #104571 )
...
During the PEP 695 implementation at one point I made
TypeVar.__name__ return garbage, and all of test_typing passed.
So I decided to add a few more tests. In the process I discovered
a minor incompatibility from the C implementation of TypeVar:
empty constraints were returned as None instead of an empty tuple.
2023-05-17 06:08:21 -07:00
Alex Waygood
1163782868
gh-104555: Fix isinstance() and issubclass() for runtime-checkable protocols that use PEP 695 ( #104556 )
...
Fixes #104555
2023-05-16 16:38:10 +00:00
Jelle Zijlstra
24d8b88420
gh-103763: Implement PEP 695 ( #103764 )
...
This implements PEP 695, Type Parameter Syntax. It adds support for:
- Generic functions (def func[T](): ...)
- Generic classes (class X[T](): ...)
- Type aliases (type X = ...)
- New scoping when the new syntax is used within a class body
- Compiler and interpreter changes to support the new syntax and scoping rules
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Eric Traut <eric@traut.com>
Co-authored-by: Larry Hastings <larry@hastings.org>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-15 20:36:23 -07:00
Alex Waygood
c527eb1c2a
gh-91896: Revert some very noisy DeprecationWarnings for `ByteString` ( #104424 )
2023-05-13 09:55:35 +01:00
Alex Waygood
f0f5bb3204
gh-91896: Improve visibility of `ByteString` deprecation warnings ( #104294 )
2023-05-11 23:01:31 -07:00
Franek Magiera
2d526cd32f
GH-103629: Update Unpack's repr in compliance with PEP 692 ( #104048 )
2023-05-01 17:58:50 +00:00
Kirill Podoprigora
4181d078fc
gh-104036: Fix direct invocation of test_typing ( #104037 )
...
Previously, `python -m test test_typing` worked, but `python Lib/test/test_typing.py` did not.
2023-05-01 13:42:59 +00:00
Nikita Sobolev
3d29edaf0a
gh-103746: Test `types.UnionType` and `Literal` types together ( #103747 )
2023-04-24 10:55:16 -06:00
Nikita Sobolev
5041c2ba6e
gh-103592: Add tests of `Literal` with `Enum` and `Union` of `Literal`s ( #103706 )
2023-04-23 11:50:23 -06:00
Adrian Garcia Badaracco
0056701aa3
GH-103699: Add `__orig_bases__` to various typing classes ( #103698 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-04-23 08:33:39 -06:00
Nikita Sobolev
a28e2ce3fb
gh-103395: Improve `typing._GenericAlias.__dir__` coverage ( #103396 )
2023-04-10 12:09:19 +01:00
Alex Waygood
800382a2b0
gh-74690: Add more tests for runtime-checkable protocols ( #103347 )
2023-04-07 18:21:19 +01:00
Alex Waygood
6d59c9e32e
gh-102433: Use `inspect.getattr_static` in `typing._ProtocolMeta.__instancecheck__` ( #103034 )
2023-04-02 14:22:19 +01:00
Nikita Sobolev
60bdc16b45
gh-103054: typing: Improve `Callable` type substitution tests ( #103055 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Eclips4 <80244920+Eclips4@users.noreply.github.com>
2023-03-28 20:04:26 -07:00
Nikita Sobolev
adb0621652
gh-88965: typing: fix type substitution of a list of types after initial `ParamSpec` substitution ( #102808 )
...
Previously, this used to fail:
```py
from typing import *
T = TypeVar("T")
P = ParamSpec("P")
class X(Generic[P]):
f: Callable[P, int]
Y = X[[int, T]]
Z = Y[str]
```
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-23 16:26:11 +00:00
Nikita Sobolev
fbe82fdd77
gh-102721: Improve coverage of `_collections_abc._CallableGenericAlias` ( #102722 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-16 14:47:30 +00:00
Nikita Sobolev
2b5781d659
gh-102615: Use `list` instead of `tuple` in `repr` of paramspec ( #102637 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-15 09:33:41 +00:00
Alex Waygood
5ffdaf748d
gh-102433: Add tests for how classes with properties interact with `isinstance()` checks on `typing.runtime_checkable` protocols ( #102449 )
...
Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-03-11 01:20:20 +00:00
Alex Waygood
96e1022929
gh-102444: Fix minor bugs in `test_typing` highlighted by pyflakes ( #102445 )
2023-03-05 21:37:29 +00:00
JosephSBoyle
7894bbe94b
Fix unused classes in a typing test (GH-102437)
...
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.
Automerge-Triggered-By: GH:AlexWaygood
2023-03-05 07:07:44 -08:00
Nikita Sobolev
12011dd8ba
gh-102324: Improve tests of `typing.override` ( #102325 )
...
Fixes #101564
2023-03-02 19:59:05 -08:00
Steven Troxler
0f89acf6cc
gh-101561: Add typing.override decorator ( #101564 )
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-02-27 13:16:11 -08:00
Eclips4
b96b344f25
gh-101562: typing: add tests for inheritance with NotRequired & Required in parent fields ( #101563 )
2023-02-06 11:28:24 -08:00
Nikita Sobolev
807d6b576f
gh-101015: Fix `typing.get_type_hints` with unpacked `*tuple` (PEP 646) ( #101031 )
2023-01-23 07:52:58 +00:00
Erik De Bonte
5c19050546
gh-99957: Add `frozen_default` parameter on `dataclass_transform` ( #99958 )
2022-12-05 19:35:43 -08:00
Serhiy Storchaka
8f2fb7dfe7
gh-99344, gh-99379, gh-99382: Fix issues in substitution of ParamSpec and TypeVarTuple (GH-99412)
...
* Fix substitution of TypeVarTuple and ParamSpec together in user generics.
* Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases.
* Check the number of arguments in substitution in user generics containing a
TypeVarTuple and one or more TypeVar.
2022-11-29 09:46:52 +02:00
Nikita Sobolev
a0bc75e2fd
`test_typing`: use all pickle protocols ( #99154 )
2022-11-06 11:53:57 +00:00
Serhiy Storchaka
0e15c31c7e
gh-98852: Fix subscription of type aliases (GH-98920)
...
Fix subscription of type aliases containing bare generic types or types
like TypeVar: for example tuple[A, T][int] and tuple[TypeVar, T][int],
where A is a generic type, and T is a type variable.
2022-11-01 09:33:09 +02:00
Nikita Sobolev
9495360c72
gh-98713: Use `@cpython_only` for a test that fails on PyPy ( #98714 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2022-10-26 14:15:39 +01:00
Matthew Rahtz
cb95cc24ef
GH-87390: Add remaining tests for PEP 646 ( #98267 )
...
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
2022-10-25 07:44:30 -07:00
Nikita Sobolev
45c89358b7
Use more precise exception types in `assertRaises` in typing tests ( #98650 )
2022-10-25 06:33:34 -07:00
Nikita Sobolev
1ca6647f22
typing tests: `_overload_dummy` raises `NotImplementedError`, not `RuntimeError` ( #98351 )
2022-10-19 17:53:36 -07:00
Nikita Sobolev
f2d749a2c2
gh-96784: Cover more typing special forms in `get_args()` ( #96791 )
2022-09-13 19:35:52 -07:00
Nikita Sobolev
9b3d2d008a
gh-96769: Cover more typing special forms to be unsubclassable ( #96772 )
2022-09-13 19:35:16 -07:00
Jelle Zijlstra
f0d9136c69
gh-96478: Fix new test when run in refleak mode ( #96615 )
...
./python.exe -m test -R : test.test_typing would fail, apparently
because the dictionary used in the @patch decorator was modified.
2022-09-06 09:33:09 -07:00
Nikita Sobolev
f177f6f29b
gh-96478: Test `@overload` on C functions ( #96479 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2022-09-05 14:35:05 -07:00
Anh71me
0cd33e11fe
GH-96079 Fix missing field name for _AnnotatedAlias ( #96080 )
2022-08-31 16:02:24 -07:00
Nikita Sobolev
4217393aee
gh-95987: Fix `repr` of `Any` type subclasses ( #96412 )
2022-08-30 10:36:16 -07:00
Nikita Sobolev
75177358a6
gh-96385: Correctly raise error on `[*T, *V]` substitution (GH-96386)
2022-08-30 10:34:55 +03:00
Nikita Sobolev
675e3470cc
gh-96357: Improve `typing.get_overloads` coverage ( #96358 )
2022-08-28 17:45:24 -07:00
Ken Jin
6442a9dd21
gh-94607: Fix subclassing generics (GH-94610)
...
Co-authored-by: Serhiy Storchaka <3659035+serhiy-storchaka@users.noreply.github.com>
2022-07-09 12:18:01 +08:00
Serhiy Storchaka
75cb3abc3b
gh-94245: Test pickling and copying of typing.Tuple[()] (GH-94259)
2022-06-25 18:46:33 +03:00
Gregory Beauregard
81e91c95a5
bpo-46642: Explicitly disallow subclassing of instaces of TypeVar, ParamSpec, etc (GH-31148)
...
The existing test covering this case passed only incidentally. We
explicitly disallow doing this and add a proper error message.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-06-25 09:35:33 +03:00
Serhiy Storchaka
3473817106
gh-91162: Support splitting of unpacked arbitrary-length tuple over TypeVar and TypeVarTuple parameters (alt) (GH-93412)
...
For example:
A[T, *Ts][*tuple[int, ...]] -> A[int, *tuple[int, ...]]
A[*Ts, T][*tuple[int, ...]] -> A[*tuple[int, ...], int]
2022-06-12 16:22:01 +03:00
Serhiy Storchaka
f545fc955a
gh-93345: Fix a crash in substitution of nested TypeVar after TypeVarTuple (GH-93346)
...
For example: tuple[*Ts, list[T]][int, str, bool]
2022-05-31 08:46:16 +03:00
Serhiy Storchaka
9d25db9db1
gh-91162: Fix substitution of unpacked tuples in generic aliases (GH-92335)
2022-05-08 18:32:32 +03:00
Matthew Rahtz
4739997e14
gh-92261: Disallow iteration of Union (and other special forms) (GH-92262)
2022-05-08 16:21:28 +03:00
Serhiy Storchaka
9d20e1af40
gh-92107: Add tests that subscription works on arbitrary named tuple types (GH-92304)
2022-05-04 17:06:50 +03:00