cut
stringclasses
1 value
version
stringclasses
10 values
idiom_id
stringclasses
53 values
pep
stringclasses
53 values
introduced_in
stringclasses
11 values
form
stringclasses
2 values
file
stringclasses
887 values
code
stringclasses
916 values
source
stringclasses
1 value
origin
stringlengths
15
17
origin_revision
stringclasses
10 values
license
stringclasses
1 value
train
3.11
literal-types
586
3.8
modern
literal-types/modern_12.py
class Test: def __init__(self, param: int) -> None: self.myfield = param def mymethod(self, val: int) -> str: ... a: Literal["myfield"] = "myfield" b: Literal["mymethod"] = "mymethod" c: Literal["blah"] = "blah" t = Test() reveal_type(getattr(t, a)) # Revealed type is 'int' reveal_type(getattr(...
pydocs
pep-0586.rst:403
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
literal-types
586
3.8
modern
literal-types/modern_13.py
_PathType = Union[str, bytes, int] @overload def open(path: _PathType, mode: Literal["r", "w", "a", "x", "r+", "w+", "a+", "x+"], ) -> IO[Text]: ... @overload def open(path: _PathType, mode: Literal["rb", "wb", "ab", "xb", "r+b", "w+b", "a+b", "x+b"], ) -> IO[bytes]: ... # Fallback...
pydocs
pep-0586.rst:431
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
literal-types
586
3.8
modern
literal-types/modern_14.py
A = TypeVar('A', bound=int) B = TypeVar('B', bound=int) C = TypeVar('C', bound=int) # A simplified definition for Matrix[row, column] class Matrix(Generic[A, B]): def __add__(self, other: Matrix[A, B]) -> Matrix[A, B]: ... def __matmul__(self, other: Matrix[B, C]) -> Matrix[A, C]: ... def transpose(self) -...
pydocs
pep-0586.rst:468
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
literal-types
586
3.8
modern
literal-types/modern_15.py
T = TypeVar('T', Literal["a"], Literal["b"], Literal["c"]) S = TypeVar('S', bound=Literal["foo"])
pydocs
pep-0586.rst:487
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
literal-types
586
3.8
modern
literal-types/modern_16.py
@overload def is_int_like(x: Union[int, List[int]]) -> Literal[True]: ... @overload def is_int_like(x: object) -> bool: ... def is_int_like(x): ... vector: List[int] = [1, 2, 3] if is_int_like(vector): vector.append(3) else: vector.append("bad") # This branch is inferred to be unreachable scalar: Union[int,...
pydocs
pep-0586.rst:569
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
literal-types
586
3.8
modern
literal-types/modern_17.py
def expects_three(x: Literal[3]) -> None: ... expects_three(foo) # Type checks, since 'foo' is Final and equal to 3
pydocs
pep-0586.rst:601
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
literal-types
586
3.8
modern
literal-types/modern_18.py
def foobar(arg1: Literal[1], arg2: Literal[True]) -> None: pass
pydocs
pep-0586.rst:667
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_01.py
from typing import TypedDict class Movie(TypedDict): name: str year: int
pydocs
pep-0589.rst:38
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_02.py
class EmptyDict(TypedDict): pass
pydocs
pep-0589.rst:160
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_03.py
class Strings(TypedDict): items: List[str] print(isinstance({'items': [1]}, Strings)) # Should be False print(isinstance({'items': ['x']}, Strings)) # Should be True
pydocs
pep-0589.rst:232
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_04.py
class BookBasedMovie(TypedDict): name: str year: int based_on: str
pydocs
pep-0589.rst:256
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_05.py
class X(TypedDict): x: int class Y(TypedDict): y: str class XYZ(X, Y): z: bool
pydocs
pep-0589.rst:263
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_06.py
class X(TypedDict): x: str class Y(X): x: int # Type check error: cannot overwrite TypedDict field "x"
pydocs
pep-0589.rst:283
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_07.py
class X(TypedDict): x: int class Y(TypedDict): x: str class XYZ(X, Y): # Type check error: cannot overwrite TypedDict field "x" while merging xyz: bool
pydocs
pep-0589.rst:297
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_08.py
class Movie(TypedDict, total=False): name: str year: int
pydocs
pep-0589.rst:314
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_09.py
Movie = TypedDict('Movie', {'name': str, 'year': int})
pydocs
pep-0589.rst:343
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_10.py
Movie = TypedDict('Movie', {'name': str, 'year': int}, total=False)
pydocs
pep-0589.rst:347
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_11.py
class A(TypedDict): x: Optional[int] class B(TypedDict): x: int def f(a: A) -> None: a['x'] = None b: B = {'x': 0} f(b) # Type check error: 'B' not compatible with 'A' b['x'] + 1 # Runtime error: None + 1
pydocs
pep-0589.rst:392
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_12.py
class A(TypedDict, total=False): x: int class B(TypedDict): x: int def f(a: A) -> None: del a['x'] b: B = {'x': 0} f(b) # Type check error: 'B' not compatible with 'A' b['x'] + 1 # Runtime KeyError: 'x'
pydocs
pep-0589.rst:409
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_13.py
class A(TypedDict): x: int class B(A): y: str def f(d: Dict[str, int]) -> None: d['y'] = 0 def g(a: A) -> None: f(a) # Type check error: 'A' incompatible with Dict[str, int] b: B = {'x': 0, 'y': 'foo'} g(b) b['y'] + 'bar' # Runtime error: int + str
pydocs
pep-0589.rst:454
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
typed-dict
589
3.8
modern
typed-dict/modern_14.py
class A(TypedDict): x: int class B(TypedDict): x: int y: str def sum_values(m: Mapping[str, int]) -> int: n = 0 for v in m.values(): n += v # Runtime error return n def f(a: A) -> None: sum_values(a) # Error: 'A' incompatible with Mapping[str, int] b: B = {'x': 0, 'y': 'foo'} f...
pydocs
pep-0589.rst:476
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_01.py
from typing import final @final class Base: ... class Derived(Base): # Error: Cannot inherit from final class "Base" ...
pydocs
pep-0591.rst:84
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_02.py
from typing import final class Base: @final def foo(self) -> None: ... class Derived(Base): def foo(self) -> None: # Error: Cannot override final attribute "foo" # (previously declared in base class "Base") ...
pydocs
pep-0591.rst:95
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_03.py
from typing import Any, overload class Base: @overload def method(self) -> None: ... @overload def method(self, arg: int) -> int: ... @final def method(self, x=None): ...
pydocs
pep-0591.rst:111
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_04.py
ID: Final[float] = 1
pydocs
pep-0591.rst:137
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_05.py
ID: Final = 1
pydocs
pep-0591.rst:141
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_06.py
from typing import Final RATE: Final = 3000 class Base: DEFAULT_ID: Final = 0 RATE = 300 # Error: can't assign to final attribute Base.DEFAULT_ID = 1 # Error: can't override a final attribute
pydocs
pep-0591.rst:171
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_07.py
from typing import Final class Window: BORDER_WIDTH: Final = 2.5 ... class ListView(Window): BORDER_WIDTH = 3 # Error: can't override a final attribute
pydocs
pep-0591.rst:188
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_08.py
class ImmutablePoint: x: Final[int] y: Final[int] # Error: final attribute without an initializer def __init__(self) -> None: self.x = 1 # Good
pydocs
pep-0591.rst:200
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_09.py
x: List[Final[int]] = [] # Error! def fun(x: Final[List[int]]) -> None: # Error! ...
pydocs
pep-0591.rst:215
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_10.py
x: Final = ['a', 'b'] x.append('c') # OK y: Final[Sequence[str]] = ['a', 'b'] y.append('x') # Error: "Sequence[str]" has no attribute "append" z: Final = ('a', 'b') # Also works
pydocs
pep-0591.rst:225
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
final-qualifier
591
3.8
modern
final-qualifier/modern_11.py
from typing import NamedTuple, Final X: Final = "x" Y: Final = "y" N = NamedTuple("N", [(X, int), (Y, int)])
pydocs
pep-0591.rst:237
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
annotated
593
3.9
modern
annotated/modern_01.py
UnsignedShort = Annotated[int, struct2.ctype('H')] SignedChar = Annotated[int, struct2.ctype('b')] class Student(struct2.Packed): # mypy typechecks 'name' field as 'str' name: Annotated[str, struct2.ctype("<10s")] serialnum: UnsignedShort school: SignedChar # 'unpack' only uses the metadata within the...
pydocs
pep-0593.rst:69
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
annotated
593
3.9
modern
annotated/modern_02.py
Currency = Annotated[ TypedDict('Currency', {'dollars': float, 'pounds': float}, total=False), TaggedUnion, ]
pydocs
pep-0593.rst:102
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
annotated
593
3.9
modern
annotated/modern_03.py
Annotated[int, ValueRange(3, 10), ctype("char")]
pydocs
pep-0593.rst:130
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
annotated
593
3.9
modern
annotated/modern_04.py
Annotated[int, ValueRange(3, 10), ctype("char")] != Annotated[ int, ctype("char"), ValueRange(3, 10) ]
pydocs
pep-0593.rst:138
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
annotated
593
3.9
modern
annotated/modern_05.py
Annotated[Annotated[int, ValueRange(3, 10)], ctype("char")] == Annotated[ int, ValueRange(3, 10), ctype("char") ]
pydocs
pep-0593.rst:145
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
annotated
593
3.9
modern
annotated/modern_06.py
Annotated[int, ValueRange(3, 10)] != Annotated[ int, ValueRange(3, 10), ValueRange(3, 10) ]
pydocs
pep-0593.rst:151
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
annotated
593
3.9
modern
annotated/modern_07.py
T1 = Annotated[int, ValueRange(-10, 5)] T2 = Annotated[T1, ValueRange(-20, 3)]
pydocs
pep-0593.rst:192
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
annotated
593
3.9
modern
annotated/modern_08.py
T2 = Annotated[int, ValueRange(-10, 5), ValueRange(-20, 3)]
pydocs
pep-0593.rst:197
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
annotated
593
3.9
modern
annotated/modern_09.py
@struct2.packed class Student(NamedTuple): name: Annotated[str, struct.ctype("<10s")] get_type_hints(Student) == {'name': str} get_type_hints(Student, include_extras=False) == {'name': str} get_type_hints(Student, include_extras=True) == { 'name': Annotated[str, struct.ctype("<10s")] }
pydocs
pep-0593.rst:208
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
annotated
593
3.9
modern
annotated/modern_10.py
T = TypeVar('T') Const = Annotated[T, my_annotations.CONST] class C: def const_method(self: Const[List[int]]) -> int: ...
pydocs
pep-0593.rst:225
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
union-syntax
604
3.10
modern
union-syntax/modern_01.py
isinstance(5, int | str) issubclass(bool, int | float)
pydocs
pep-0604.rst:52
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
union-syntax
604
3.10
modern
union-syntax/modern_02.py
isinstance(None, int | None) isinstance(42, None | int)
pydocs
pep-0604.rst:58
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
union-syntax
604
3.10
modern
union-syntax/modern_03.py
# Instead of # def f(list: List[Union[int, str]], param: Optional[int]) -> Union[float, str] def f(list: List[int | str], param: int | None) -> float | str: pass f([1, "abc"], None) # Instead of typing.List[typing.Union[str, int]] typing.List[str | int] list[str | int] # Instead of typing.Dict[str, typing.Union[...
pydocs
pep-0604.rst:70
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
union-syntax
604
3.10
modern
union-syntax/modern_04.py
int | str == typing.Union[int, str] typing.Union[int, int] == int int | int == int
pydocs
pep-0604.rst:89
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
union-syntax
604
3.10
modern
union-syntax/modern_05.py
(int | str) == (str | int) (int | str | float) == typing.Union[str, float, int]
pydocs
pep-0604.rst:98
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
union-syntax
604
3.10
modern
union-syntax/modern_06.py
None | t == typing.Optional[t]
pydocs
pep-0604.rst:106
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
union-syntax
604
3.10
modern
union-syntax/modern_07.py
str(int | list[str]) # int | list[str] str(int | int) # int
pydocs
pep-0604.rst:112
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
union-syntax
604
3.10
modern
union-syntax/modern_08.py
# valid isinstance("", int | str) # invalid isinstance(2, list[int]) # TypeError: isinstance() argument 2 cannot be a parameterized generic isinstance(1, int | list[int]) # valid issubclass(bool, int | float) # invalid issubclass(bool, bool | list[int])
pydocs
pep-0604.rst:125
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
union-syntax
604
3.10
modern
union-syntax/modern_09.py
class M(type): def __or__(self, other): return "Hello" class C(metaclass=M): pass C | int int | C Union[C, int]
pydocs
pep-0604.rst:147
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
union-syntax
604
3.10
modern
union-syntax/modern_10.py
from __future__ import annotations def foo() -> int | str: pass eval(foo.__annotations__['return'])
pydocs
pep-0604.rst:194
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
legacy
param-spec/legacy_01.py
from typing import Awaitable, Callable, TypeVar R = TypeVar("R") def add_logging(f: Callable[..., R]) -> Callable[..., Awaitable[R]]: async def inner(*args: object, **kwargs: object) -> R: await log_to_database() return f(*args, **kwargs) return inner @add_logging def takes_int_str(x: int, y: str) -> int...
pydocs
pep-0612.rst:36
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_01.py
from typing import Awaitable, Callable, ParamSpec, TypeVar P = ParamSpec("P") R = TypeVar("R") def add_logging(f: Callable[P, R]) -> Callable[P, Awaitable[R]]: async def inner(*args: P.args, **kwargs: P.kwargs) -> R: await log_to_database() return f(*args, **kwargs) return inner @add_logging def takes_in...
pydocs
pep-0612.rst:86
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
legacy
param-spec/legacy_02.py
class Request: ... def with_request(f: Callable[..., R]) -> Callable[..., R]: def inner(*args: object, **kwargs: object) -> R: return f(Request(), *args, **kwargs) return inner @with_request def takes_int_str(request: Request, x: int, y: str) -> int: # use request return x + 7 takes_int_str(1, "A") tak...
pydocs
pep-0612.rst:110
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_02.py
from typing import Concatenate def with_request(f: Callable[Concatenate[Request, P], R]) -> Callable[P, R]: def inner(*args: P.args, **kwargs: P.kwargs) -> R: return f(Request(), *args, **kwargs) return inner @with_request def takes_int_str(request: Request, x: int, y: str) -> int: # use request return x ...
pydocs
pep-0612.rst:132
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_03.py
from typing import ParamSpec P = ParamSpec("P") # Accepted P = ParamSpec("WrongName") # Rejected because P =/= WrongName
pydocs
pep-0612.rst:162
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_04.py
def foo(x: P) -> P: ... # Rejected def foo(x: Concatenate[int, P]) -> int: ... # Rejected def foo(x: typing.List[P]) -> None: ... # Rejected def foo(x: Callable[[int, str], P]) -> None: ... # Rejected
pydocs
pep-0612.rst:201
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_05.py
T = TypeVar("T") P_2 = ParamSpec("P_2") class X(Generic[T, P]): f: Callable[P, int] x: T def f(x: X[int, P_2]) -> str: ... # Accepted def f(x: X[int, Concatenate[int, P_2]]) -> str: ... # Accepted def f(x: X[int, [int, bool]]) -> str: ... # Accepted def f(x: X[int, ...]) -> str: ......
pydocs
pep-0612.rst:217
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_06.py
P = ParamSpec("P") def foo(x: Callable[P, int], y: Callable[P, int]) -> Callable[P, bool]: ... def x_y(x: int, y: str) -> int: ... def y_x(y: int, x: str) -> int: ... foo(x_y, x_y) # Should return (x: int, y: str) -> bool foo(x_y, y_x) # Could return (__a: int, __b: str) -> bool # This works becaus...
pydocs
pep-0612.rst:278
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_07.py
def bar(x: int, *args: bool) -> int: ... def add(x: Callable[P, int]) -> Callable[Concatenate[str, P], bool]: ... add(bar) # Should return (__a: str, x: int, *args: bool) -> bool def remove(x: Callable[Concatenate[int, P], int]) -> Callable[P, bool]: ... remove(bar) # Should return (*args: bool) -> bool d...
pydocs
pep-0612.rst:323
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_08.py
def expects_int_first(x: Callable[Concatenate[int, P], int]) -> None: ... @expects_int_first # Rejected def one(x: str) -> int: ... @expects_int_first # Rejected def two(*, x: int) -> int: ... @expects_int_first # Rejected def three(**kwargs: int) -> int: ... @expects_int_first # Accepted def four(*args: int) -> in...
pydocs
pep-0612.rst:346
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_09.py
def puts_p_into_scope(f: Callable[P, int]) -> None: def inner(*args: P.args, **kwargs: P.kwargs) -> None: # Accepted pass def mixed_up(*args: P.kwargs, **kwargs: P.args) -> None: # Rejected pass def misplaced(x: P.args) -> None: # Rejected pass def out_of_scope(*arg...
pydocs
pep-0612.rst:389
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_10.py
def puts_p_into_scope(f: Callable[P, int]) -> None: stored_args: P.args # Rejected stored_kwargs: P.kwargs # Rejected def just_args(*args: P.args) -> None: # Rejected pass def just_kwargs(**kwargs: P.kwargs) -> None: # Rejected pass
pydocs
pep-0612.rst:413
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_11.py
def decorator(f: Callable[P, int]) -> Callable[P, None]: def foo(*args: P.args, **kwargs: P.kwargs) -> None: f(*args, **kwargs) # Accepted, should resolve to int f(*kwargs, **args) # Rejected f(1, *args, **kwargs) # Rejected return foo # Accepted
pydocs
pep-0612.rst:453
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_12.py
def add(f: Callable[P, int]) -> Callable[Concatenate[str, P], None]: def foo(s: str, *args: P.args, **kwargs: P.kwargs) -> None: # Accepted pass def bar(*args: P.args, s: str, **kwargs: P.kwargs) -> None: # Rejected pass return foo # Accepted def re...
pydocs
pep-0612.rst:478
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_13.py
def outer(f: Callable[P, None]) -> Callable[P, None]: def foo(x: int, *args: P.args, **kwargs: P.kwargs) -> None: f(*args, **kwargs) def bar(*args: P.args, **kwargs: P.kwargs) -> None: foo(1, *args, **kwargs) # Accepted foo(x=1, *args, **kwargs) # Rejected return bar
pydocs
pep-0612.rst:506
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_14.py
def twice(f: Callable[P, int], *args: P.args, **kwargs: P.kwargs) -> int: return f(*args, **kwargs) + f(*args, **kwargs)
pydocs
pep-0612.rst:544
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_15.py
def add_n(f: Callable[P, R]) -> Callable[Concatenate[("n", int), P], R]: def inner(*args: P.args, n: int, **kwargs: P.kwargs) -> R: # use n return f(*args, **kwargs) return inner
pydocs
pep-0612.rst:715
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
param-spec
612
3.10
modern
param-spec/modern_16.py
def innocent_wrapper(f: Callable[P, R]) -> Callable[P, R]: def inner(*args: P.args, **kwargs: P.kwargs) -> R: added = add_n(f) return added(*args, n=1, **kwargs) return inner @innocent_wrapper def problem(n: int) -> None: pass
pydocs
pep-0612.rst:729
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
legacy
type-alias/legacy_01.py
MyType = "ClassName" def foo() -> MyType: ...
pydocs
pep-0613.rst:52
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
modern
type-alias/modern_01.py
MyType: TypeAlias = "ClassName" def foo() -> MyType: ...
pydocs
pep-0613.rst:63
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
legacy
type-alias/legacy_02.py
MyType1 = InvalidType MyType2 = MyGeneric(int) # i.e., intention was MyGeneric[int]
pydocs
pep-0613.rst:76
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
modern
type-alias/modern_02.py
MyType1: TypeAlias = InvalidType MyType2: TypeAlias = MyGeneric(int)
pydocs
pep-0613.rst:88
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
modern
type-alias/modern_03.py
class Foo: x = ClassName y: TypeAlias = ClassName z: Type[ClassName] = ClassName
pydocs
pep-0613.rst:102
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
legacy
type-alias/legacy_03.py
x = ClassName def foo() -> None: x = ClassName
pydocs
pep-0613.rst:113
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
modern
type-alias/modern_04.py
x: TypeAlias = ClassName def foo() -> None: x = ClassName def bar() -> None: x: TypeAlias = ClassName
pydocs
pep-0613.rst:126
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
legacy
type-alias/legacy_04.py
x = 1 # untyped global expression x: int = 1 # typed global expression x = int # type alias x: Type[int] = int # typed global expression
pydocs
pep-0613.rst:151
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
modern
type-alias/modern_05.py
x = 1 # untyped global expression x: int = 1 # typed global expression x = int # untyped global expression (see note below) x: Type[int] = int # typed global expression x: TypeAlias = int # type alias x: TypeAlias = "MyClass" # type alias
pydocs
pep-0613.rst:162
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
modern
type-alias/modern_06.py
MyType: TypeAlias[int]
pydocs
pep-0613.rst:199
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
type-alias
613
3.10
modern
type-alias/modern_07.py
MyType = TypeAlias[int]
pydocs
pep-0613.rst:205
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
legacy
variadic-generics/legacy_01.py
Axis1 = TypeVar('Axis1') Axis2 = TypeVar('Axis2') class Array1(Generic[Axis1]): ... class Array2(Generic[Axis1, Axis2]): ...
pydocs
pep-0646.rst:93
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_01.py
from typing import TypeVar, TypeVarTuple DType = TypeVar('DType') Shape = TypeVarTuple('Shape') class Array(Generic[DType, *Shape]): def __abs__(self) -> Array[DType, *Shape]: ... def __add__(self, other: Array[DType, *Shape]) -> Array[DType, *Shape]: ...
pydocs
pep-0646.rst:115
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_02.py
from typing import TypeVarTuple Ts = TypeVarTuple('Ts')
pydocs
pep-0646.rst:179
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_03.py
Shape = TypeVarTuple('Shape') class Array(Generic[*Shape]): ... Height = NewType('Height', int) Width = NewType('Width', int) x: Array[Height, Width] = Array()
pydocs
pep-0646.rst:191
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_04.py
class Array(Generic[*Shape]): def __init__(self, shape: Tuple[*Shape]): self._shape: Tuple[*Shape] = shape def get_shape(self) -> Tuple[*Shape]: return self._shape shape = (Height(480), Width(640)) x: Array[Height, Width] = Array(shape) y = abs(x) # Inferred type is Array[Height, Width] z = ...
pydocs
pep-0646.rst:227
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_05.py
# Unpacking using the star operator in new versions of Python class Array(Generic[*Shape]): ... # Unpacking using ``Unpack`` in older versions of Python class Array(Generic[Unpack[Shape]]): ...
pydocs
pep-0646.rst:268
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_06.py
def foo(arg1: Tuple[*Ts], arg2: Tuple[*Ts]): ... a = (0,) b = ('0',) foo(a, b) # Can Ts be bound to Tuple[int | str]?
pydocs
pep-0646.rst:295
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_07.py
def pointwise_multiply( x: Array[*Shape], y: Array[*Shape] ) -> Array[*Shape]: ... x: Array[Height] y: Array[Width] z: Array[Height, Width] pointwise_multiply(x, x) # Valid pointwise_multiply(x, y) # Error pointwise_multiply(x, z) # Error
pydocs
pep-0646.rst:308
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_08.py
class Array(Generic[*Ts1, *Ts2]): ... # Error
pydocs
pep-0646.rst:327
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_09.py
Shape = TypeVarTuple('Shape') Batch = NewType('Batch', int) Channels = NewType('Channels', int) def add_batch_axis(x: Array[*Shape]) -> Array[Batch, *Shape]: ... def del_batch_axis(x: Array[Batch, *Shape]) -> Array[*Shape]: ... def add_batch_channels( x: Array[*Shape] ) -> Array[Batch, *Shape, Channels]: ... a: Arr...
pydocs
pep-0646.rst:342
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_10.py
T = TypeVar('T') Ts = TypeVarTuple('Ts') def prefix_tuple( x: T, y: Tuple[*Ts] ) -> Tuple[T, *Ts]: ... z = prefix_tuple(x=0, y=(True, 'a')) # Inferred type of z is Tuple[int, bool, str]
pydocs
pep-0646.rst:362
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_11.py
def process_batch_channels( x: Array[Batch, *Tuple[Any, ...], Channels] ) -> None: ... x: Array[Batch, Height, Width, Channels] process_batch_channels(x) # OK y: Array[Batch, Channels] process_batch_channels(y) # OK z: Array[Batch] process_batch_channels(z) # Error: Expected Channels.
pydocs
pep-0646.rst:407
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_12.py
y: Array[*Tuple[Any, ...]] = read_from_file() def expect_variadic_array( x: Array[Batch, *Shape] ) -> None: ... expect_variadic_array(y) # OK def expect_precise_array( x: Array[Batch, Height, Width, Channels] ) -> None: ... expect_precise_array(y) # OK
pydocs
pep-0646.rst:429
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_13.py
x: Tuple[int, *Ts, str, *Ts2] # Error y: Tuple[int, *Tuple[int, ...], str, *Tuple[str, ...]] # Error
pydocs
pep-0646.rst:465
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_14.py
Ts = TypeVarTuple('Ts') def args_to_tuple(*args: *Ts) -> Tuple[*Ts]: ... args_to_tuple(1, 'a') # Inferred type is Tuple[int, str]
pydocs
pep-0646.rst:482
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_15.py
# os.execle takes arguments 'path, arg0, arg1, ..., env' def execle(path: str, *args: *Tuple[*Ts, Env]) -> None: ...
pydocs
pep-0646.rst:498
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_16.py
def execle(path: str, *args: *Ts, env: Env) -> None: ...
pydocs
pep-0646.rst:505
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_17.py
def foo(*args: *Tuple[int, ...]) -> None: ... # equivalent to: def foo(*args: int) -> None: ...
pydocs
pep-0646.rst:516
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0
train
3.11
variadic-generics
646
3.11
modern
variadic-generics/modern_18.py
def foo(*args: *Tuple[int, *Tuple[str, ...], str]) -> None: ...
pydocs
pep-0646.rst:527
1a931bf317c851a907067308cb1175deeb9415c6
CC0-1.0