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
Samodya Abey
f6f36cc269
bpo-44863: Allow generic typing.TypedDict ( #27663 )
...
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-05-03 07:21:42 -06:00
Shantanu
ebb8b512e9
gh-91621: Fix typing.get_type_hints for collections.abc.Callable ( #91656 )
...
This mirrors logic in typing.get_args. The trickiness comes from how we
flatten args in collections.abc.Callable, see
https://bugs.python.org/issue42195
2022-05-02 17:08:28 -06:00
Serhiy Storchaka
b04e02c57f
bpo-43923: Add support for generic typing.NamedTuple ( #92027 )
2022-05-02 16:41:23 -06:00
Serhiy Storchaka
81fb3548be
gh-92106: Add test that subscription works on arbitrary TypedDicts ( #92176 )
2022-05-02 16:38:39 -06:00
Serhiy Storchaka
e8c2f72b94
bpo-43224: Implement substitution of unpacked TypeVarTuple in C (GH-31828)
...
Co-authored-by: Matthew Rahtz <mrahtz@gmail.com>
2022-04-30 08:22:46 +03:00
Dennis Sweeney
a29aa76a3f
gh-92064: Fix global variable name collision in test_typing ( #92067 )
...
Fixes #92064
2022-04-29 21:18:38 -06:00
Serhiy Storchaka
81120b6754
bpo-44791: Accept ellipsis as the last argument of typing.Concatenate ( #30969 )
2022-04-29 15:01:40 -06:00
Matthew Rahtz
f6656163de
gh-87390: Add tests demonstrating current type variable substitution behaviour ( #32341 )
2022-04-29 14:03:21 -06:00
Jelle Zijlstra
5397b5afc1
gh-91860: Add typing.dataclass_transform (PEP 681) ( #91861 )
...
Copied from typing-extensions (python/typing#1054 , python/typing#1120 ).
Documentation is intentionally omitted, so we can focus on getting the
runtime part in before the feature freeze.
2022-04-25 20:30:25 -07:00
Jelle Zijlstra
93d280141c
gh-90633: Improve error and docs for typing.assert_never ( #91720 )
...
Closes #90633
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2022-04-25 06:40:18 -07:00
Matthew Rahtz
5e130a8da4
bpo-43224: Implement pickling of TypeVarTuples ( #32119 )
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-04-21 21:22:53 -07:00
Jelle Zijlstra
055760ed9e
gh-89263: Add typing.get_overloads (GH-31716)
...
Based on suggestions by Guido van Rossum, Spencer Brown, and Alex Waygood.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
2022-04-16 09:01:43 -07:00
Matthew Rahtz
f2bc12f0d5
bpo-43224: Add tests for TypeVarTuple substitution in Annotated (GH-31846)
2022-04-15 21:24:28 -07:00
Serhiy Storchaka
15537c51c1
bpo-43224: Forbid TypeVar substitution with Unpack (GH-32031)
2022-04-12 20:08:49 -07:00
Jelle Zijlstra
ac6c3de03c
gh-91243: Add typing.Required and NotRequired (PEP 655) (GH-32419)
...
I talked to @davidfstr and I offered to implement the runtime part of PEP 655
to make sure we can get it in before the feature freeze. We're going to defer
the documentation to a separate PR, because it can wait until after the feature
freeze.
The runtime implementation conveniently already exists in typing-extensions,
so I largely copied that.
Co-authored-by: David Foster <david@dafoster.net>
2022-04-12 12:31:02 -07:00
Adrian Garcia Badaracco
5f2abae61e
bpo-44807: Allow Protocol classes to define __init__ (GH-31628)
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-04-11 07:51:25 -07:00
Jelle Zijlstra
cfb849a326
bpo-47088: Add typing.LiteralString (PEP 675) (GH-32064)
...
Co-authored-by: Nick Pope <nick@nickpope.me.uk>
2022-04-05 07:21:03 -07:00
Shantanu
5a4973e29f
bpo-46998: Allow subclassing Any at runtime (GH-31841)
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-04-04 19:35:29 -07:00
Jelle Zijlstra
3a2b89580d
bpo-43224: Add TypeVarTuple.__name__ (GH-31954)
...
I noticed that TypeVar and ParamSpec put their name in a __name__
attribute, but TypeVarTuple doesn't. Let's be consistent.
2022-03-18 10:56:36 -07:00
Serhiy Storchaka
15df8f8d89
bpo-46981: Remove typing._TypingEmpty (GH-31836)
...
* get_args(Tuple[()]) now returns () instead of ((),).
* Tuple[Unpack[Ts]][()] now returns the result equal to Tuple[()].
2022-03-17 09:52:24 +02:00
Jelle Zijlstra
96568e995d
bpo-46480: add typing.assert_type (GH-30843)
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: David Foster <david@dafoster.net>
2022-03-16 20:02:26 -07:00
Jelle Zijlstra
75174371e6
bpo-46644: Fix test_typing test broken by GH-31151 due to a merge race (GH-31833)
2022-03-11 18:17:45 -08:00
Gregory Beauregard
870b22b9c4
bpo-46644: Remove callable() requirement from typing._type_check (GH-31151)
...
We also remove all the tests that check for integer literals.
2022-03-11 17:12:17 -08:00
Serhiy Storchaka
5b1b9eacb9
bpo-43224: Implement substitution of unpacked TypeVarTuple (GH-31800)
2022-03-11 21:43:58 +02:00
Serhiy Storchaka
b6a5d8590c
bpo-44796: Unify TypeVar and ParamSpec substitution (GH-31143)
...
Add methods __typing_subst__() in TypeVar and ParamSpec.
Simplify code by using more object-oriented approach, especially
the C code for types.GenericAlias and the Python code for
collections.abc.Callable.
2022-03-11 10:47:26 +02:00
Matt Bogosian
32bf359792
bpo-46581: Propagate private vars via _GenericAlias.copy_with (GH-31061)
...
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>
2022-03-10 16:42:15 +02:00
Matthew Rahtz
7a793a388b
bpo-43224: Implement PEP 646 changes to typing.py (GH-31021)
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-03-07 20:02:55 -08:00
James Hilton-Balfe
f391f9bf28
bpo-46170: Improve the error message when subclassing NewType (GH-30268)
...
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2022-03-07 19:50:46 -08:00
Niklas Rosenstein
b465b60604
bpo-41370: Evaluate strings as forward refs in PEP 585 generics (GH-30900)
...
This removes discrepancy between list["int"] and List["int"].
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2022-03-07 10:02:59 -08:00
Serhiy Storchaka
6927632492
Remove trailing spaces (GH-31695)
2022-03-05 17:47:00 +02:00
Gregory Beauregard
75d2d945b4
bpo-46643: Fix stringized P.args/P.kwargs with get_type_hints (GH-31238)
2022-03-02 17:14:52 -08:00
Nikita Sobolev
20a1c8ee4b
bpo-46195: Do not add `Optional` in `get_type_hints` (GH-30304)
...
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-03-01 21:29:46 -08:00
Jelle Zijlstra
0a8a8e7454
bpo-46066: Check DeprecationWarning in test_typing (GH-31428)
2022-02-19 17:44:51 -08:00
Nikita Sobolev
32e3e0bea6
bpo-46685: improve test coverage of `Self` and `Never` in `typing` (GH-31222)
2022-02-18 17:56:30 -08:00
Nikita Sobolev
25c0b9d243
bpo-46603: improve coverage of `typing._strip_annotations` (GH-31063)
2022-02-18 17:54:01 -08:00
Nikita Sobolev
395029b0bd
bpo-46571: improve `typing.no_type_check` to skip foreign objects (GH-31042)
...
There are several changes:
1. We now don't explicitly check for any base / sub types, because new name check covers it
2. I've also checked that `no_type_check` do not modify foreign functions. It was the same as with `type`s
3. I've also covered `except TypeError` in `no_type_check` with a simple test case, it was not covered at all
4. I also felt like adding `lambda` test is a good idea: because `lambda` is a bit of both in class bodies: a function and an assignment
<!-- issue-number: [bpo-46571](https://bugs.python.org/issue46571 ) -->
https://bugs.python.org/issue46571
<!-- /issue-number -->
2022-02-18 17:53:29 -08:00
aha79
6e7b813195
bpo-46333: Honor `module` parameter in ForwardRef (GH-30536)
...
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>
2022-02-16 19:28:18 -08:00
97littleleaf11
de6043e596
bpo-46066: Deprecate kwargs syntax for TypedDict definitions (GH-31126)
...
Closes python/typing#981
https://bugs.python.org/issue46066
2022-02-16 19:26:07 -08:00
aha79
b70690bb37
bpo-46333: include `module` in `ForwardRef.__repr__` ( #31283 )
...
The module parameter carries semantic information about the forward ref.
Show to the user that forward refs with same argument but different
module are different.
Co-authored-by: Andreas Hangauer <andreas.hangauer@siemens.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2022-02-12 07:35:57 -08:00
Nikita Sobolev
d2d1d49eac
bpo-46685: cover `TypeError` of `ForwardRef(1)` in `test_typing` (GH-31223)
2022-02-09 23:23:07 +09:00
Jelle Zijlstra
243436f377
bpo-46475: Add typing.Never and typing.assert_never (GH-30842)
2022-02-08 10:50:26 -08:00
Gregory Beauregard
c8b62bbe46
bpo-46676: Make ParamSpec args and kwargs equal to themselves (GH-31203)
2022-02-08 09:46:58 +02:00
James Hilton-Balfe
7ba1cc8049
bpo-46534: Implement PEP 673 Self in typing.py (GH-30924)
...
Co-authored-by: Pradeep Kumar Srinivasan <gohanpra@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-02-07 12:47:48 -08:00
Nikita Sobolev
067c03bf40
bpo-46611: add coverage to instance and class checks in `typing.py` (GH-31078)
2022-02-06 17:35:48 -08:00
Gregory Beauregard
77b025be4a
bpo-46655: allow stringized TypeAlias with get_type_hints (GH-31156)
2022-02-06 15:16:22 -08:00
Serhiy Storchaka
3da5526136
Add more tests for variable substitution in generics (GH-31170)
2022-02-06 21:52:39 +02:00
Jelle Zijlstra
abcc3d75f6
bpo-46414: Add typing.reveal_type ( #30646 )
...
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-02-01 18:48:55 -08:00
Nikita Sobolev
4c0612ad00
bpo-46482: add a test for `typing.Annotation.__new__` (GH-30821)
2022-02-01 17:58:41 +08:00
Gregory Beauregard
5445e173e7
bpo-46553: allow bare typing.ClassVar annotations ( #30983 )
...
These are used in the wild and covered by dataclasses unit tests.
Several static type checkers support this pattern.
2022-01-28 08:58:39 -08:00
Serhiy Storchaka
ecfacc362d
bpo-44791: Fix substitution of ParamSpec in Concatenate with different 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.
2022-01-27 14:34:55 +02:00
Gregory Beauregard
ced50051bb
bpo-46539: Pass status of special typeforms to forward references (GH-30926)
...
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.
2022-01-26 19:11:51 -08:00
Nikita Sobolev
d0c690b5f8
bpo-46529: increase coverage of `typing.Union.__repr__` method (GH-30911)
2022-01-26 18:13:02 +08:00
Gregory Beauregard
e1abffca45
bpo-46491: Allow Annotated on outside of Final/ClassVar (GH-30864)
...
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
2022-01-24 22:37:15 -08:00
Nikita Sobolev
65b88d5e01
bpo-46445: Cover multiple inheritance of `TypedDict` in `test_typing` (GH-30719)
2022-01-21 13:38:23 -08:00
Nikita Sobolev
263c0dd160
bpo-46437: remove useless `hasattr` from `test_typing` ( #30704 )
2022-01-19 13:24:27 -08:00
Nikita Sobolev
0a49148e87
bpo-46413: properly test `__{r}or__` code paths in `_SpecialGenericAlias` (GH-30640)
...
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2022-01-19 23:32:25 +08:00
Nikita Sobolev
2792d6d18e
bpo-46416: Allow direct invocation of `Lib/test/test_typing.py` (GH-30641)
...
Use `__name__`
2022-01-19 22:13:38 +08:00
Nikita Sobolev
32398294fb
bpo-46424: [typing] cover `Annotation[arg]` invalid usage in tests (GH-30663)
2022-01-18 22:43:51 +08:00
Nikita Sobolev
09087b8519
bpo-46386: improve `test_typing:test_immutability_by_copy_and_pickle` (GH-30613)
2022-01-16 16:32:11 +09:00
Nikita Sobolev
8c49d057bf
bpo-46359: Modernize `test_typing` by removing checks for EOL Python versions (GH-30563)
...
Also removes unused tests meant for older versions of Python.
2022-01-13 21:09:40 +08:00
Nikita Sobolev
1de60155d5
bpo-46345: Add a test case for implicit `Optional` class attribute (GH-30535)
2022-01-12 15:35:44 -08:00
Jelle Zijlstra
0bbf30e2b9
bpo-46342: make @typing.final introspectable (GH-30530)
...
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2022-01-12 11:38:25 -08:00
Nikita Sobolev
e2a9c8ef09
bpo-46348: modernize `test_typing` (GH-30547)
2022-01-12 08:48:10 -08:00
Ken Jin
d6e1374716
bpo-45755: [typing] Reveal class attributes of generic in generic aliases in `dir()` (GH-29962)
2021-12-16 22:29:59 +08:00
Serhiy Storchaka
634984d7db
bpo-45679: Fix caching of multi-value typing.Literal (GH-29334)
...
Literal[True, 2] is no longer equal to Literal[1, 2].
2021-10-31 10:22:16 +02:00
Nikita Sobolev
0c4c2e6213
Move several typing tests to a proper class, refs GH-28563 (GH-29126)
2021-10-21 22:16:50 +02:00
Dong-hee Na
15ad52fbf6
bpo-45489: Update ForwardRef to support | operator. (GH-28991)
2021-10-17 00:12:58 +09:00
Nikita Sobolev
f56268a2cd
bpo-45280: Add test for empty `NamedTuple` in `test_typing` (GH-28559)
...
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
2021-09-26 18:32:18 +02:00
Nikita Sobolev
784905dbef
bpo-45166: fixes `get_type_hints` failure on `Final` (GH-28279)
...
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2021-09-25 10:56:22 +02:00
Yurii Karabas
c11956a8bd
bpo-45121: Fix RecursionError when calling Protocol.__init__ from a subclass' __init__ (GH-28206)
2021-09-08 18:25:09 +08:00
Ken Jin
23384a1749
bpo-44524: Don't modify MRO when inheriting from typing.Annotated (GH-27841)
2021-08-25 21:13:59 +03:00
Dong-hee Na
24b63c695a
bpo-24234: Implement bytes.__bytes__ (GH-27901)
2021-08-23 19:01:51 +09:00
Mark Dickinson
6082bb5add
bpo-24234: implement complex.__complex__ (GH-27887)
...
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
2021-08-23 09:15:49 +01:00
Serhiy Storchaka
4ceec49559
bpo-44524: Do not set _name of _SpecialForm without need (GH-27861)
...
Because setting non-empty _name affects behavior of other code.
In most cases __name__ can be derived from __origin__.__name__.
2021-08-21 09:47:59 +03:00
Yurii Karabas
a3a4d20d67
bpo-44524: Fix cryptic TypeError message when trying to subclass special forms in `typing` (GH-27710)
...
This was a Python 3.9 regression.
2021-08-18 21:08:32 +02:00
Bas van Beek
8bdf12e99a
bpo-44524: Fix an issue wherein `_GenericAlias._name` was not properly set for specialforms (GH-27614)
...
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-08-06 15:36:35 +02:00
Serhiy Storchaka
3875a69547
bpo-44801: Check arguments in substitution of ParamSpec in Callable (GH-27585)
2021-08-04 20:07:01 +02:00
Serhiy Storchaka
043cd60abe
bpo-44806: Fix __init__ in subclasses of protocols (GH-27545)
...
Non-protocol subclasses of protocol ignore now the __init__ method
inherited from protocol base classes.
2021-08-02 18:23:22 +02:00
Serhiy Storchaka
f92b9133ef
bpo-44793: Fix checking the number of arguments when subscribe a generic 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.
2021-08-02 09:17:46 +03:00
Serhiy Storchaka
be4cb9089a
bpo-44794: Merge tests for typing.Callable and collection.abc.Callable (GH-27507)
2021-07-31 20:05:45 +03:00
Yurii Karabas
7b975f81e4
bpo-44761: Change default value of NewType __module__ attr (GH-27406)
2021-07-30 14:56:12 +02:00
Yurii Karabas
8182c8329c
bpo-44662: Add ability to annotate types.Union ( #27214 )
...
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2021-07-29 21:44:48 +02:00
Hasan
2b8ad9e6c5
bpo-44732: Rename types.Union to types.UnionType ( #27342 )
...
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2021-07-26 18:00:21 +02:00
Yurii Karabas
a22b05da87
bpo-44353: Improve tests covering typing.NewType pickling (GH-27302)
2021-07-24 11:53:40 +02:00
Serhiy Storchaka
e89ef0ad2a
bpo-44353: Expand NewType tests for complex __qualname__. ( #27311 )
...
Make NewType pickleable by name.
2021-07-24 09:40:08 +02:00
Sebastian Rittau
4512848ab9
Fix a deprecation warning in typing tests ( #27312 )
...
The test was accessing typing.{io,re}.__all__, which triggered the
warning. This check isn't necessary anymore, since the objects from
typing.{io,re}.__all__ are in typing.__all__ as well, since Python 3.10.
2021-07-23 11:53:29 -07:00
Yurii Karabas
8f42106b5c
bpo-44353: Fix memory leak introduced by GH-27262 (GH-27305)
2021-07-23 16:28:05 +02:00
Yurii Karabas
96c4cbd96c
bpo-44353: Implement typing.NewType __call__ method in C ( #27262 )
...
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Denis Laxalde <denis@laxalde.org>
2021-07-22 23:06:54 +02:00
Yurii Karabas
4868b94c60
bpo-44353: Add test to cover __or__ of two NewType ( #27259 )
2021-07-20 16:48:05 +02:00
Yurii Karabas
965dd76e90
bpo-44353: Refactor typing.NewType into callable class (GH-27250)
2021-07-20 15:20:38 +02:00
Yurii Karabas
bce1418541
bpo-44524: Add missed __name__ and __qualname__ to typing module objects ( #27237 )
...
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2021-07-19 19:22:12 +02:00
Germán Méndez Bravo
889036f7ef
bpo-41249: Fix postponed annotations for TypedDict (GH-27017)
...
This fixes TypedDict to work with get_type_hints and postponed evaluation of annotations across modules.
This is done by adding the module name to ForwardRef at the time the object is created and using that to resolve the globals during the evaluation.
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2021-07-16 20:49:30 -07:00
Yurii Karabas
bf89ff96e6
bpo-44490: Improve typing module compatibility with types.Union (GH-27048)
2021-07-16 20:33:40 -07:00
will-ca
7569c0fe91
bpo-44468: Never skip base classes in `typing.get_type_hints()`, even with invalid `.__module__`. (GH-26862)
2021-06-26 16:31:32 -07:00
Ikko Ashimine
35b773accb
Fix typo in test_typing.py (GH-26853)
...
maximium -> maximum
2021-06-22 15:42:28 -07:00
Ken Jin
c5d700f0e2
Reset DeprecationWarning filters in test_typing io and re ( #26811 )
2021-06-21 11:17:55 -07:00
Sebastian Rittau
09eb817115
bpo-38291: DeprecationWarning when importing typing.{io,re} ( #26719 )
2021-06-19 10:31:18 -07:00
Ken Jin
b2f3f8e3d8
bpo-44098: Drop ParamSpec from most ``__parameters__`` in typing generics (GH-26013)
...
Added two new attributes to ``_GenericAlias``:
* ``_typevar_types``, a single type or tuple of types indicating what types are treated as a ``TypeVar``. Used for ``isinstance`` checks.
* ``_paramspec_tvars ``, a boolean flag which guards special behavior for dealing with ``ParamSpec``. Setting it to ``True`` means this class deals with ``ParamSpec``.
Automerge-Triggered-By: GH:gvanrossum
2021-05-12 22:24:35 -07:00
Yurii Karabas
c40486a32d
bpo-38908: Fix issue when non runtime_protocol failed to raise TypeError ( #26067 )
2021-05-12 08:47:49 -07:00
Ken Jin
05ab4b60ab
bpo-43766: Implement PEP 647 (User-Defined Type Guards) in typing.py ( #25282 )
2021-04-27 07:31:04 -07:00