| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
| |
The issue raised by recursive evaluation is infinite recursion with
recursive types. In that case, only the first recursive ForwardRef is
evaluated.
|
|
|
| |
Automerge-Triggered-By: @gvanrossum
|
|
|
|
| |
(GH-20021)
|
| |
|
| |
|
| |
|
| |
|
|
|
| |
https://bugs.python.org/issue39942
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
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`.
|
| |
|
| |
|
| |
|
|
|
| |
(Adapted from https://github.com/python/typing/pull/700)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
(GH-17126)
https://bugs.python.org/issue37838
|
| |
|
| |
|
|
|
|
|
|
|
|
| |
(GH-16222)
This includes such names as "cls", "self", "typename", "_typename",
"fields" and "_fields".
Passing positional arguments by keyword is deprecated.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
| |
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
|
|
|
|
| |
Fixes https://bugs.python.org/issue38008
|
|
|
|
|
|
| |
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
|
|
|
| |
This test "works" if things are run in the right order, so it's better to use @skip than @expectedFailure here.
|
|
|
|
|
|
|
|
|
|
| |
(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.
|
|
|
| |
https://bugs.python.org/issue36983
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
The implementation is straightforward and essentially is just copied from `typing_extensions`.
|
|
|
|
| |
The implementation is straightforward and essentially is just copied from `typing_extensions`.
|
|
|
|
| |
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`.
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
The second attempt. Now deprecate `@coroutine` only, keep `yield from fut` as is.
https://bugs.python.org/issue36921
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
| |
This also fixes https://bugs.python.org/issue33420
|
|
|
|
| |
This removes a hack and replaces it with a proper
mapping {'list': 'List', 'dict': 'Dict', ...}.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
| |
This adds C versions of methods used by ABCMeta that
improve performance of various ABC operations.
|
|
|
|
| |
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.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
(#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.
|
|
|
|
| |
* Copy changes to typing from upstream repo
* Add NEWS entry
|
|
|
|
|
|
|
| |
This PR contains two updates to typing module:
- Support ContextManager on all versions (original PR by Jelle Zijlstra).
- Add generic AsyncContextManager.
|