Commit Graph

254 Commits

Author SHA1 Message Date
Miss Islington (bot) 01ab43c08a
[3.11] gh-117110: Fix subclasses of typing.Any with custom constructors (GH-117111) (#117358)
gh-117110: Fix subclasses of typing.Any with custom constructors (GH-117111)
(cherry picked from commit 8eec7ed714)

Co-authored-by: 傅立业(Chris Fu) <17433201@qq.com>
2024-03-29 00:38:13 +00:00
Miss Islington (bot) f187da5b59
[3.11] gh-116325: Raise `SyntaxError` rather than `IndexError` on ForwardRef with empty string arg (GH-116341) (#116348)
gh-116325: Raise `SyntaxError` rather than `IndexError` on ForwardRef with empty string arg (GH-116341)
(cherry picked from commit a29998a06b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-03-05 10:15:54 +00:00
Nikita Sobolev 8bfbeeb0a1
[3.11] gh-112281: Allow `Union` with unhashable `Annotated` metadata (GH-112283) (#116288)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-03-03 20:20:01 +00:00
Jelle Zijlstra c01a4808d3
[3.11] gh-115570: Fix DeprecationWarnings in test_typing (#115571)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-02-16 19:37:42 +00:00
Miss Islington (bot) 7542210a95
[3.11] gh-115165: Fix `typing.Annotated` for immutable types (GH-115213) (#115228)
gh-115165: Fix `typing.Annotated` for immutable types (GH-115213)

The return value from an annotated callable can raise any exception from
__setattr__ for the `__orig_class__` property.
(cherry picked from commit 564385612c)

Co-authored-by: dave-shawley <daveshawley@gmail.com>
2024-02-09 22:43:24 +00:00
Alex Waygood d65dfc8238
[3.11] gh-113255: Clarify docs for `typing.reveal_type` (#113286) (#113326)
(cherry-picked from commit 11ee912327)

Co-authored-by: Kir <note351@hotmail.com>
2023-12-20 18:35:13 +00:00
Miss Islington (bot) db537702e4
[3.11] [3.12] gh-112618: Make Annotated cache typed (GH-112619) (GH-112628) (#112633)
[3.12] gh-112618: Make Annotated cache typed (GH-112619) (GH-112628)
(cherry picked from commit 2a378ca2ef)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-12-03 00:58:13 +00:00
Miss Islington (bot) f6edb83fe9
[3.11] gh-112509: Fix keys being present in both required_keys and optional_keys in TypedDict (GH-112512) (#112531)
(cherry picked from commit 4038869423)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-29 17:51:00 +00:00
Miss Islington (bot) e7aa40a341
[3.11] gh-112194: Convert more examples to doctests in `typing.py` (GH-112195) (#112209)
gh-112194: Convert more examples to doctests in `typing.py` (GH-112195)
(cherry picked from commit 949b2cc6ea)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-17 18:14:20 +00:00
Alex Waygood 6cb1308005
[3.11] Miscellaneous improvements to the typing docs (#105529) (#105568)
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 22:41:22 +01:00
Miss Islington (bot) af80db063f
[3.11] Further improve docs for `typing.Annotated` (GH-105498) (#105504)
* Further improve docs for `typing.Annotated` (GH-105498)
(cherry picked from commit d213c2990f)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-08 15:06:39 +00:00
Jelle Zijlstra 3a195f3468
[3.11] gh-105286: Further improvements to `typing.py` docstrings (GH-105363) (#105417)
[3.11] gh-105286: Further improvements to `typing.py` docstrings (GH-105363).
(cherry picked from commit 9a89f1bf1e)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-07 21:41:46 +00:00
Alex Waygood ccc971714e
[3.11] typing: Improve documentation of generic classes and aliases (#105369) (#105454) 2023-06-07 21:27:15 +00:00
Alex Waygood 18e9fd80d9
[3.11] gh-103171: Revert undocumented behaviour change for runtime-checkable protocols decorated with `@final` (#105445) 2023-06-07 21:18:21 +00:00
Alex Waygood 93d9e990fb
[3.11] gh-105286: Improve typing.py docstrings (#105287) (#105322)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-06-05 18:11:35 +02:00
Jelle Zijlstra d34e58a1d5
[3.11] gh-103921: Improve typing documentation (GH-104642) (#105007)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-27 16:30:41 -07:00
Miss Islington (bot) 13424746ce
[3.11] gh-104943: Remove mentions of old Python versions (GH-104945) (#104962)
(cherry picked from commit 46857d0b2a)

Co-authored-by: Tomas R <tomas.roun8@gmail.com>
2023-05-26 07:13:45 +00:00
Miss Islington (bot) 663b32199e
[3.11] gh-104328: Fix typo in ``typing.Generic`` multiple inheritance error message (GH-104335) (#104338)
gh-104328: Fix typo in ``typing.Generic`` multiple inheritance error message (GH-104335)
(cherry picked from commit 01c321ca34)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2023-05-09 19:42:57 +00:00
Miss Islington (bot) 3e7e50e656
[3.11] Improve assert_type phrasing (GH-104081) (#104084)
Improve assert_type phrasing (GH-104081)

I'd like to make the fact that this does nothing at runtime
really obvious, since I suspect this is unintuitive for users who are
unfamiliar with static type checking.

I thought of this because of
https://discuss.python.org/t/add-arg-check-type-to-types/26384
wherein I'm skeptical that the user really did want `assert_type`.
(cherry picked from commit 82ba6ce303)

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2023-05-02 08:44:16 +01:00
Miss Islington (bot) 0f6319fc8c
gh-97797: Mention `__metadata__` in docstrings of `typing.{_AnnotatedAlias, Annotated}` (GH-103405)
(cherry picked from commit dc604a8c58)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Kirill <80244920+Eclips4@users.noreply.github.com>
2023-04-10 08:21:45 -07:00
Miss Islington (bot) 1645a40b5e
gh-88965: typing: fix type substitution of a list of types after initial `ParamSpec` substitution (GH-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]
```

(cherry picked from commit adb0621652)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-23 09:54:07 -07:00
Miss Islington (bot) 29ff9daf82
gh-101015: Fix `typing.get_type_hints` with unpacked `*tuple` (PEP 646) (GH-101031)
(cherry picked from commit 807d6b576f)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-01-23 00:20:15 -08:00
Miss Islington (bot) 6afc389e1d
Correct typo in typing.py (GH-100423)
In the docstring of `ParamSpec`, the name of `P = ParamSpec('P')` was
mistakenly written as `'T'`.
(cherry picked from commit 68981578ec)

Co-authored-by: david-why <david_why@outlook.com>
2022-12-22 03:49:18 -08:00
Miss Islington (bot) 74920aa27d
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.
(cherry picked from commit 8f2fb7dfe7)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-11-29 06:46:53 -08:00
Miss Islington (bot) 20c258c692
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.
(cherry picked from commit 0e15c31c7e)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-11-01 01:01:28 -07:00
Shantanu c9eacc8d02
[3.11] gh-95987: Fix `repr` of `Any` type subclasses (GH-96412) (#96451)
(cherry picked from commit 4217393)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-10-05 15:02:06 -07:00
Miss Islington (bot) 16d8948c31
gh-96385: Correctly raise error on `[*T, *V]` substitution (GH-96386) (#96407)
(cherry picked from commit 75177358a6)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-08-30 11:58:54 +01:00
Miss Islington (bot) 7c185017a9
docs: typing.Self, fix typo (GH-94771)
* fix typo - double spelled word 'use'

* change methods names to the infinitive form
(cherry picked from commit 90a6e56e56)

Co-authored-by: Max Zhenzhera <59729293+maxzhenzhera@users.noreply.github.com>
2022-07-12 11:17:06 -07:00
Miss Islington (bot) b4e232c4b5
gh-94607: Fix subclassing generics (GH-94610)
Co-authored-by: Serhiy Storchaka <3659035+serhiy-storchaka@users.noreply.github.com>
(cherry picked from commit 6442a9dd21)

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2022-07-08 22:20:43 -07:00
Miss Islington (bot) 579e985e75
gh-89828: Do not relay the __class__ attribute in GenericAlias (GH-93754)
list[int].__class__ returned type, and isinstance(list[int], type)
returned True. It caused numerous problems in code that checks
isinstance(x, type).
(cherry picked from commit f9433fff47)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-06-18 07:41:25 -07:00
Miss Islington (bot) 8dc5df4e21
[3.11] gh-91162: Support splitting of unpacked arbitrary-length tuple over TypeVar and TypeVarTuple parameters (alt) (GH-93412) (GH-93746)
For example:

  A[T, *Ts][*tuple[int, ...]] -> A[int, *tuple[int, ...]]
  A[*Ts, T][*tuple[int, ...]] -> A[*tuple[int, ...], int]
(cherry picked from commit 3473817106)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-06-14 21:15:56 +03:00
Miss Islington (bot) 00f8fe9564
[3.11] gh-91162: Fix substitution of unpacked tuples in generic aliases (GH-92335) (#92484)
* gh-91162: Fix substitution of unpacked tuples in generic aliases (GH-92335)
(cherry picked from commit 9d25db9db1)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

* Regenerate ABI file

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2022-06-01 03:13:27 +01:00
Miss Islington (bot) 6a3a6ba7a2
gh-91860: documentation for typing.dataclass_transform (GH-92768)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
(cherry picked from commit f20a6a54fb)

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2022-05-20 08:01:44 -07:00
Miss Islington (bot) 8a2b3edcdc
Add `__slots__` to `typing._NotIterable` (GH-92570)
(cherry picked from commit eef47d5bc7)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2022-05-10 02:45:17 -07:00
Miss Islington (bot) 7540a432ce
gh-92261: Disallow iteration of Union (and other special forms) (GH-92262) (GH-92582)
(cherry picked from commit 4739997e14)

Co-authored-by: Matthew Rahtz <matthew.rahtz@gmail.com>
2022-05-10 08:39:31 +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 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
Serhiy Storchaka 81120b6754
bpo-44791: Accept ellipsis as the last argument of typing.Concatenate (#30969) 2022-04-29 15:01:40 -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