-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
typing: Use PEP 695 syntax in typing.py #104553
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
Changes from 1 commit
e1ff413
16b0978
655d6ac
754dda0
302f071
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2471,8 +2471,9 @@ class Other(Leaf): # Error reported by type checker | |
| return f | ||
|
|
||
|
|
||
| # Some unconstrained type variables. These are used by the container types. | ||
| # (These are not for export.) | ||
| # Some unconstrained type variables. These were initially used by the container types. | ||
| # They were never meant for export and are now unused, but we keep them around to | ||
| # avoid breaking compatibility with users who import them. | ||
| T = TypeVar('T') # Any type. | ||
| KT = TypeVar('KT') # Key type. | ||
| VT = TypeVar('VT') # Value type. | ||
|
|
@@ -2577,8 +2578,6 @@ def new_user(user_class: Type[U]) -> U: | |
| At this point the type checker knows that joe has type BasicUser. | ||
| """ | ||
|
|
||
| # Internal type variable for callables. Not for export. | ||
| F = TypeVar("F", bound=Callable[..., Any]) | ||
|
|
||
| @runtime_checkable | ||
| class SupportsInt(Protocol): | ||
|
|
@@ -2631,7 +2630,7 @@ def __index__(self) -> int: | |
|
|
||
|
|
||
| @runtime_checkable | ||
| class SupportsAbs(Protocol[T_co]): | ||
| class SupportsAbs[T_co](Protocol): | ||
|
JelleZijlstra marked this conversation as resolved.
Outdated
|
||
| """An ABC with one abstract method __abs__ that is covariant in its return type.""" | ||
| __slots__ = () | ||
|
|
||
|
|
@@ -2641,7 +2640,7 @@ def __abs__(self) -> T_co: | |
|
|
||
|
|
||
| @runtime_checkable | ||
| class SupportsRound(Protocol[T_co]): | ||
| class SupportsRound[T_co](Protocol): | ||
| """An ABC with one abstract method __round__ that is covariant in its return type.""" | ||
| __slots__ = () | ||
|
|
||
|
|
@@ -3183,7 +3182,7 @@ class re(metaclass=_DeprecatedType): | |
| sys.modules[re.__name__] = re | ||
|
|
||
|
|
||
| def reveal_type(obj: T, /) -> T: | ||
| def reveal_type[T](obj: T, /) -> T: | ||
| """Reveal the inferred type of a variable. | ||
|
|
||
| When a static type checker encounters a call to ``reveal_type()``, | ||
|
|
@@ -3203,7 +3202,7 @@ def reveal_type(obj: T, /) -> T: | |
| return obj | ||
|
|
||
|
|
||
| def dataclass_transform( | ||
| def dataclass_transform[T]( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels slightly strange to me, as (to me) it implies that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC we did think about this and decided that this is indeed how such cases should be spelled (since
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we shouldn't do this since it confuses scoping and much of the point of PEP 695 is to clarify scoping. We can use a callback protocol to spell this. I'd brought this up somewhere before PEP 695 was accepted, but didn't get much of a response. Presumably since it's not the most common thing and I think e.g. pyre might not even support
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to a callback protocol |
||
| *, | ||
| eq_default: bool = True, | ||
| order_default: bool = False, | ||
|
|
@@ -3288,8 +3287,7 @@ def decorator(cls_or_fn): | |
| return decorator | ||
|
|
||
|
|
||
|
|
||
| def override(method: F, /) -> F: | ||
| def override[F: Callable[..., Any]](method: F, /) -> F: | ||
|
AlexWaygood marked this conversation as resolved.
Outdated
|
||
| """Indicate that a method is intended to override a method in a base class. | ||
|
|
||
| Usage: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one was added as part of implementing
overrideearlier in 3.12, so there's no need to keep it around for compatibility.