Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
Add initial support for TypeVarLike default parameters (PEP 696)#8821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+67
−26
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9bed980
Add initial support for TypeVarLike default parameters (PEP 696)
cdce8p 29dffc9
Fix tests
cdce8p 8c8708a
Revert conditional exports
cdce8p d587881
Merge branch 'master' into TypeVarLike-defaults
cdce8p 06e0bf7
Apply suggestions from code review
JelleZijlstra 53209fc
Add Any and override
JelleZijlstra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,12 +2,13 @@ import _typeshed | ||
| import abc | ||
| import collections | ||
| import sys | ||
| import typing | ||
| from _collections_abc import dict_items, dict_keys, dict_values | ||
| from _typeshed import IdentityFunction | ||
| from _typeshed import IdentityFunction, Incomplete | ||
| from collections.abc import Iterable | ||
| from typing import ( # noqa: Y022,Y027,Y039 | ||
| TYPE_CHECKING as TYPE_CHECKING, | ||
| Any, | ||
| Any as Any, | ||
| AsyncContextManager as AsyncContextManager, | ||
| AsyncGenerator as AsyncGenerator, | ||
| AsyncIterable as AsyncIterable, | ||
| @@ -27,13 +28,13 @@ from typing import ( # noqa: Y022,Y027,Y039 | ||
| Sequence, | ||
| Text as Text, | ||
| Type as Type, | ||
| TypeVar, | ||
| _Alias, | ||
| overload as overload, | ||
| type_check_only, | ||
| ) | ||
| __all__ = [ | ||
| "Any", | ||
| "ClassVar", | ||
| "Concatenate", | ||
| "Final", | ||
| @@ -43,6 +44,7 @@ __all__ = [ | ||
| "ParamSpecKwargs", | ||
| "Self", | ||
| "Type", | ||
| "TypeVar", | ||
| "TypeVarTuple", | ||
| "Unpack", | ||
| "Awaitable", | ||
| @@ -70,6 +72,7 @@ __all__ = [ | ||
| "Literal", | ||
| "NewType", | ||
| "overload", | ||
| "override", | ||
| "Protocol", | ||
| "reveal_type", | ||
| "runtime", | ||
| @@ -89,9 +92,9 @@ __all__ = [ | ||
| "get_type_hints", | ||
| ] | ||
| _T = TypeVar("_T") | ||
| _F = TypeVar("_F", bound=Callable[..., Any]) | ||
| _TC = TypeVar("_TC", bound=Type[object]) | ||
| _T = typing.TypeVar("_T") | ||
| _F = typing.TypeVar("_F", bound=Callable[..., Any]) | ||
| _TC = typing.TypeVar("_TC", bound=Type[object]) | ||
| # unfortunately we have to duplicate this class definition from typing.pyi or we break pytype | ||
| class _SpecialForm: | ||
| @@ -167,7 +170,6 @@ class SupportsIndex(Protocol, metaclass=abc.ABCMeta): | ||
| if sys.version_info >= (3, 10): | ||
| from typing import ( | ||
| Concatenate as Concatenate, | ||
| ParamSpec as ParamSpec, | ||
| ParamSpecArgs as ParamSpecArgs, | ||
| ParamSpecKwargs as ParamSpecKwargs, | ||
| TypeAlias as TypeAlias, | ||
| @@ -183,18 +185,6 @@ else: | ||
| __origin__: ParamSpec | ||
| def __init__(self, origin: ParamSpec) -> None: ... | ||
| class ParamSpec: | ||
| __name__: str | ||
| __bound__: type[Any] | None | ||
| __covariant__: bool | ||
| __contravariant__: bool | ||
| def __init__( | ||
| self, name: str, *, bound: None | type[Any] | str = ..., contravariant: bool = ..., covariant: bool = ... | ||
| ) -> None: ... | ||
| @property | ||
| def args(self) -> ParamSpecArgs: ... | ||
| @property | ||
| def kwargs(self) -> ParamSpecKwargs: ... | ||
| Concatenate: _SpecialForm | ||
| TypeAlias: _SpecialForm | ||
| TypeGuard: _SpecialForm | ||
| @@ -210,7 +200,6 @@ if sys.version_info >= (3, 11): | ||
| NotRequired as NotRequired, | ||
| Required as Required, | ||
| Self as Self, | ||
| TypeVarTuple as TypeVarTuple, | ||
| Unpack as Unpack, | ||
| assert_never as assert_never, | ||
| assert_type as assert_type, | ||
| @@ -233,12 +222,6 @@ else: | ||
| LiteralString: _SpecialForm | ||
| Unpack: _SpecialForm | ||
| @final | ||
| class TypeVarTuple: | ||
| __name__: str | ||
| def __init__(self, name: str) -> None: ... | ||
| def __iter__(self) -> Any: ... # Unpack[Self] | ||
| def dataclass_transform( | ||
| *, | ||
| eq_default: bool = ..., | ||
| @@ -268,3 +251,61 @@ else: | ||
| def _asdict(self) -> collections.OrderedDict[str, Any]: ... | ||
| def _replace(self: _typeshed.Self, **kwargs: Any) -> _typeshed.Self: ... | ||
| # New things in 3.xx | ||
| # The `default` parameter was added to TypeVar, ParamSpec, and TypeVarTuple (PEP 696) | ||
| # The `infer_variance` parameter was added to TypeVar (PEP 695) | ||
| # typing_extensions.override (PEP 698) | ||
| @final | ||
| class TypeVar: | ||
| __name__: str | ||
| __bound__: Any | None | ||
| __constraints__: tuple[Any, ...] | ||
| __covariant__: bool | ||
| __contravariant__: bool | ||
| __default__: Any | None | ||
| def __init__( | ||
| self, | ||
| name: str, | ||
| *constraints: Any, | ||
| bound: Any | None = ..., | ||
| covariant: bool = ..., | ||
| contravariant: bool = ..., | ||
| default: Any | None = ..., | ||
JelleZijlstra marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| infer_variance: bool = ..., | ||
| ) -> None: ... | ||
| if sys.version_info >= (3, 10): | ||
| def __or__(self, right: Any) -> _SpecialForm: ... | ||
| def __ror__(self, left: Any) -> _SpecialForm: ... | ||
| if sys.version_info >= (3, 11): | ||
| def __typing_subst__(self, arg: Incomplete) -> Incomplete: ... | ||
| @final | ||
| class ParamSpec: | ||
| __name__: str | ||
| __bound__: type[Any] | None | ||
| __covariant__: bool | ||
| __contravariant__: bool | ||
| __default__: type[Any] | None | ||
| def __init__( | ||
| self, | ||
| name: str, | ||
| *, | ||
| bound: None | type[Any] | str = ..., | ||
| contravariant: bool = ..., | ||
| covariant: bool = ..., | ||
| default: type[Any] | str | None = ..., | ||
| ) -> None: ... | ||
| @property | ||
| def args(self) -> ParamSpecArgs: ... | ||
| @property | ||
| def kwargs(self) -> ParamSpecKwargs: ... | ||
| @final | ||
| class TypeVarTuple: | ||
| __name__: str | ||
| __default__: Any | None | ||
| def __init__(self, name: str, *, default: Any | None = ...) -> None: ... | ||
| def __iter__(self) -> Any: ... # Unpack[Self] | ||
| def override(__arg: _F) -> _F: ... | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.