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.
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):
@runtime_checkable
-class SupportsAbs(Protocol[T_co]):
+class SupportsAbs[T](Protocol):
"""An ABC with one abstract method __abs__ that is covariant in its return type."""
__slots__ = ()
@abstractmethod
- def __abs__(self) -> T_co:
+ def __abs__(self) -> T:
pass
@runtime_checkable
-class SupportsRound(Protocol[T_co]):
+class SupportsRound[T](Protocol):
"""An ABC with one abstract method __round__ that is covariant in its return type."""
__slots__ = ()
@abstractmethod
- def __round__(self, ndigits: int = 0) -> T_co:
+ def __round__(self, ndigits: int = 0) -> T:
pass
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()``,
return obj
+class _IdentityCallable(Protocol):
+ def __call__[T](self, arg: T, /) -> T:
+ ...
+
+
def dataclass_transform(
*,
eq_default: bool = True,
frozen_default: bool = False,
field_specifiers: tuple[type[Any] | Callable[..., Any], ...] = (),
**kwargs: Any,
-) -> Callable[[T], T]:
+) -> _IdentityCallable:
"""Decorator that marks a function, class, or metaclass as providing
dataclass-like behavior.
return decorator
+type _Func = Callable[..., Any]
+
-def override(method: F, /) -> F:
+def override[F: _Func](method: F, /) -> F:
"""Indicate that a method is intended to override a method in a base class.
Usage: