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.9
protocol
544
3.8
modern
protocol/modern_29.py
class P(Protocol): x: float def f(arg: P) -> None: arg.x = 0.42 class C: x: int c = C() f(c) # Would typecheck if covariant subtyping # of mutable attributes were allowed. c.x >> 1 # But this fails at runtime
pydocs
pep-0544.txt:1313
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
protocol
544
3.8
modern
protocol/modern_30.py
T = TypeVar('T') class P(Protocol[T]): # Protocol is declared as invariant. def meth(self) -> T: ... class C: def meth(self) -> float: ... class D(C): def meth(self) -> int: ...
pydocs
pep-0544.txt:1341
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
protocol
544
3.8
modern
protocol/modern_31.py
class OldIterable(Sized, Protocol[T]): def __getitem__(self, item: int) -> T: ... CompatIterable = Union[Iterable[T], OldIterable[T]] class A: def __iter__(self) -> Iterator[str]: ... class B: def __len__(self) -> int: ... def __getitem__(self, item: int) -> str: ... def iterate(it: CompatIterable[st...
pydocs
pep-0544.txt:1387
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
positional-only-params
570
3.8
modern
positional-only-params/modern_01.py
def name(positional_only_parameters, /, positional_or_keyword_parameters, *, keyword_only_parameters): ...
pydocs
pep-0570.rst:443
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
positional-only-params
570
3.8
modern
positional-only-params/modern_02.py
def name(p1, p2, /, p_or_kw, *, kw): ... def name(p1, p2=None, /, p_or_kw=None, *, kw): ... def name(p1, p2=None, /, *, kw): ... def name(p1, p2=None, /): ... def name(p1, p2, /, p_or_kw): ... def name(p1, p2, /): ...
pydocs
pep-0570.rst:461
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
positional-only-params
570
3.8
modern
positional-only-params/modern_03.py
def foo(name, /, **kwds): return 'name' in kwds
pydocs
pep-0570.rst:539
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
positional-only-params
570
3.8
modern
positional-only-params/modern_04.py
def standard_arg(arg): print(arg) def pos_only_arg(arg, /): print(arg) def kwd_only_arg(*, arg): print(arg) def combined_example(pos_only, /, standard, *, kwd_only): print(pos_only, standard, kwd_only)
pydocs
pep-0570.rst:635
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
positional-only-params
570
3.8
modern
positional-only-params/modern_05.py
def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2): ...
pydocs
pep-0570.rst:705
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
builtin-generics
585
3.9
modern
builtin-generics/modern_01.py
from __future__ import annotations def find(haystack: dict[str, list[int]]) -> int: ...
pydocs
pep-0585.rst:66
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
builtin-generics
585
3.9
modern
builtin-generics/modern_02.py
list[str] tuple[int, ...] ChainMap[str, list[str]]
pydocs
pep-0585.rst:142
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
builtin-generics
585
3.9
modern
builtin-generics/modern_03.py
l = list[str]() list is list[str] list == list[str] list[str] == list[str] list[str] == list[int] isinstance([1, 2, 3], list[str]) issubclass(list, list[str]) isinstance(list[str], types.GenericAlias)
pydocs
pep-0585.rst:167
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
builtin-generics
585
3.9
modern
builtin-generics/modern_04.py
l: list[str] = []
pydocs
pep-0585.rst:193
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
builtin-generics
585
3.9
modern
builtin-generics/modern_05.py
l = list[str]()
pydocs
pep-0585.rst:197
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
builtin-generics
585
3.9
modern
builtin-generics/modern_06.py
list[str] tuple[int, ...] collections.ChainMap[str, list[str]]
pydocs
pep-0585.rst:243
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
builtin-generics
585
3.9
legacy
builtin-generics/legacy_01.py
from typing import List, Tuple, ChainMap List[str] Tuple[int, ...] ChainMap[str, List[str]]
pydocs
pep-0585.rst:254
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
builtin-generics
585
3.9
modern
builtin-generics/modern_07.py
isinstance([1, 2, 3], list[str])
pydocs
pep-0585.rst:322
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_01.py
from typing import Literal def accepts_only_four(x: Literal[4]) -> None: pass accepts_only_four(4) # OK accepts_only_four(19) # Rejected
pydocs
pep-0586.rst:23
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_02.py
# Note: this is a simplification of the true type signature. _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", "...
pydocs
pep-0586.rst:125
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_03.py
Literal[26] Literal[0x1A] # Exactly equivalent to Literal[26] Literal[-4] Literal["hello world"] Literal[b"hello world"] Literal[u"hello world"] Literal[True] Literal[Color.RED] # Assuming Color is some enum Literal[None]
pydocs
pep-0586.rst:165
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_04.py
ReadOnlyMode = Literal["r", "r+"] WriteAndTruncateMode = Literal["w", "w+", "wt", "w+t"] WriteNoTruncateMode = Literal["r+", "r+t"] AppendMode = Literal["a", "a+", "at", "a+t"] AllModes = Literal[ReadOnlyMode, WriteAndTruncateMode, WriteNoTruncateMode, AppendMode]
pydocs
pep-0586.rst:182
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_05.py
Literal[Literal[Literal[1, 2, 3], "foo"], 5, None]
pydocs
pep-0586.rst:196
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_06.py
Literal[1, 2, 3, "foo", 5, None]
pydocs
pep-0586.rst:200
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_07.py
Optional[Literal[1, 2, 3, "foo", 5]]
pydocs
pep-0586.rst:204
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_08.py
def my_function(x: Literal[1 + 2]) -> int: return x * 3 x: Literal = 3 y: Literal[my_function] = my_function
pydocs
pep-0586.rst:271
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_09.py
def expects_str(x: str) -> None: ... var: Literal["foo"] = "foo" # Legal: Literal["foo"] is a subtype of str expects_str(var)
pydocs
pep-0586.rst:360
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_10.py
def expects_literal(x: Literal["foo"]) -> None: ... def runner(my_str: str) -> None: # ILLEGAL: str is not a subclass of Literal["foo"] expects_literal(my_str)
pydocs
pep-0586.rst:369
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
literal-types
586
3.8
modern
literal-types/modern_11.py
a: Literal[0] = 0 b: Literal[5] = 5 some_tuple: Tuple[int, str, List[bool]] = (3, "abc", [True, False]) reveal_type(some_tuple[a]) # Revealed type is 'int' some_tuple[b] # Error: 5 is not a valid index into the tuple
pydocs
pep-0586.rst:393
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:402
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:430
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:467
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:486
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:567
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:599
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:665
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:37
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
typed-dict
589
3.8
modern
typed-dict/modern_02.py
class EmptyDict(TypedDict): pass
pydocs
pep-0589.rst:159
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:231
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:255
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:262
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:282
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:296
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
typed-dict
589
3.8
modern
typed-dict/modern_08.py
class Movie(TypedDict, total=False): name: str year: int
pydocs
pep-0589.rst:313
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
typed-dict
589
3.8
modern
typed-dict/modern_09.py
Movie = TypedDict('Movie', {'name': str, 'year': int})
pydocs
pep-0589.rst:342
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
typed-dict
589
3.8
modern
typed-dict/modern_10.py
Movie = TypedDict('Movie', {'name': str, 'year': int}, total=False)
pydocs
pep-0589.rst:346
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:391
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:408
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:453
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:475
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:83
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:94
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:110
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
final-qualifier
591
3.8
modern
final-qualifier/modern_04.py
ID: Final[float] = 1
pydocs
pep-0591.rst:136
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
final-qualifier
591
3.8
modern
final-qualifier/modern_05.py
ID: Final = 1
pydocs
pep-0591.rst:140
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:170
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:187
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:199
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:214
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:224
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:236
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:67
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
annotated
593
3.9
modern
annotated/modern_02.py
Currency = Annotated[ TypedDict('Currency', {'dollars': float, 'pounds': float}, total=False), TaggedUnion, ]
pydocs
pep-0593.rst:100
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
annotated
593
3.9
modern
annotated/modern_03.py
Annotated[int, ValueRange(3, 10), ctype("char")]
pydocs
pep-0593.rst:129
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:137
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:144
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:150
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:191
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
annotated
593
3.9
modern
annotated/modern_08.py
T2 = Annotated[int, ValueRange(-10, 5), ValueRange(-20, 3)]
pydocs
pep-0593.rst:196
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
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:207
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_01.py
import datetime name = 'Fred' age = 50 anniversary = datetime.date(1991, 10, 12) f'My name is {name}, my age next year is {age+1}, my anniversary is {anniversary:%A, %B %d, %Y}.' f'He said his name is {name!r}.'
pydocs
pep-0498.txt:36
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
legacy
fstring/legacy_01.py
msg = 'disk failure' 'error: %s' % msg
pydocs
pep-0498.txt:62
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
legacy
fstring/legacy_02.py
msg = ('disk failure', 32) 'error: %s' % msg
pydocs
pep-0498.txt:68
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
legacy
fstring/legacy_03.py
'error: %s' % (msg,)
pydocs
pep-0498.txt:76
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
legacy
fstring/legacy_04.py
value = 4 * 20 'The value is {value}.'.format(value=value)
pydocs
pep-0498.txt:90
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
legacy
fstring/legacy_05.py
'The value is {}.'.format(value)
pydocs
pep-0498.txt:98
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_02.py
f'The value is {value}.'
pydocs
pep-0498.txt:103
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_03.py
value = 1234 f'input={value:#06x}'
pydocs
pep-0498.txt:118
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_04.py
date = datetime.date(1991, 10, 12) f'{date} was on a {date:%A}'
pydocs
pep-0498.txt:125
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
legacy
fstring/legacy_06.py
def outer(x): def inner(): return 'x={x}'.format_map(locals()) return inner outer(42)()
pydocs
pep-0498.txt:137
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
legacy
fstring/legacy_07.py
def outer(x): def inner(): x return 'x={x}'.format_map(locals()) return inner outer(42)()
pydocs
pep-0498.txt:152
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_05.py
f'{"quoted string"}'
pydocs
pep-0498.txt:254
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_06.py
f'{{ {4*10} }}' f'{{{4*10}}}'
pydocs
pep-0498.txt:263
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_07.py
fr'x={4*10}\n'
pydocs
pep-0498.txt:271
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_08.py
f"abc {a['x']} def"
pydocs
pep-0498.txt:281
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_09.py
f'''abc {a['x']} def'''
pydocs
pep-0498.txt:285
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_10.py
f'abc{expr1:spec1}{expr2!r:spec2}def{expr3}ghi'
pydocs
pep-0498.txt:297
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_11.py
def foo(): return 20 f'result={foo()}'
pydocs
pep-0498.txt:317
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_12.py
x = 0 f'''{x +1}''' d = {0: 'zero'} f'''{d[0 ]}'''
pydocs
pep-0498.txt:334
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_13.py
width = 10 precision = 4 value = decimal.Decimal('12.34567') f'result: {value:{width}.{precision}}'
pydocs
pep-0498.txt:350
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_14.py
x = 10 y = 'hi' 'a' 'b' f'{x}' '{c}' f'str<{y:^4}>' 'd' 'e'
pydocs
pep-0498.txt:368
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_15.py
d = {0:10, 1:20} for i in range(3): print(f'{i}:{d[i]}')
pydocs
pep-0498.txt:413
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_16.py
for x in (32, 100, 'fifty'): print(f'x = {x:+3}')
pydocs
pep-0498.txt:425
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_17.py
def fn(l, incr): result = l[0] l[0] += incr return result lst = [0] f'{fn(lst,2)} {fn(lst,3)}' f'{fn(lst,2)} {fn(lst,3)}' lst
pydocs
pep-0498.txt:447
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_18.py
f'Column={col_idx+1}' f'number of items: {len(items)}'
pydocs
pep-0498.txt:521
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_19.py
col_number = col_idx+1 f'Column={col_number}' n_items = len(items) f'number of items: {n_items}'
pydocs
pep-0498.txt:526
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_20.py
f'mapping is { {a:b for (a, b) in ((1, 2), (3, 4))} }'
pydocs
pep-0498.txt:535
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
legacy
fstring/legacy_08.py
d = {'a': 10, 'b': 20} 'a={d[a]}'.format(d=d)
pydocs
pep-0498.txt:554
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_21.py
f'a={d["a"]}'
pydocs
pep-0498.txt:564
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_22.py
a = 'b' f'a={d[a]}'
pydocs
pep-0498.txt:570
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
legacy
fstring/legacy_09.py
'{i[";]}'.format(i={'";':4})
pydocs
pep-0498.txt:580
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0
train
3.9
fstring
498
3.6
modern
fstring/modern_23.py
header = 'Subject' fr'{header}:\s+'
pydocs
pep-0498.txt:600
a95341328c8ee8d84692e5dad85bef668d86c9d5
CC0-1.0