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.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
typed-dict
589
3.8
modern
typed-dict/modern_02.py
class EmptyDict(TypedDict): pass
pydocs
pep-0589.rst:159
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
typed-dict
589
3.8
modern
typed-dict/modern_09.py
Movie = TypedDict('Movie', {'name': str, 'year': int})
pydocs
pep-0589.rst:342
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
final-qualifier
591
3.8
modern
final-qualifier/modern_04.py
ID: Final[float] = 1
pydocs
pep-0591.rst:136
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
final-qualifier
591
3.8
modern
final-qualifier/modern_05.py
ID: Final = 1
pydocs
pep-0591.rst:140
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
legacy
fstring/legacy_01.py
msg = 'disk failure' 'error: %s' % msg
pydocs
pep-0498.txt:62
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
legacy
fstring/legacy_02.py
msg = ('disk failure', 32) 'error: %s' % msg
pydocs
pep-0498.txt:68
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
legacy
fstring/legacy_03.py
'error: %s' % (msg,)
pydocs
pep-0498.txt:76
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
legacy
fstring/legacy_04.py
value = 4 * 20 'The value is {value}.'.format(value=value)
pydocs
pep-0498.txt:90
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
legacy
fstring/legacy_05.py
'The value is {}.'.format(value)
pydocs
pep-0498.txt:98
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_02.py
f'The value is {value}.'
pydocs
pep-0498.txt:103
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_03.py
value = 1234 f'input={value:#06x}'
pydocs
pep-0498.txt:118
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_05.py
f'{"quoted string"}'
pydocs
pep-0498.txt:254
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_06.py
f'{{ {4*10} }}' f'{{{4*10}}}'
pydocs
pep-0498.txt:263
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_07.py
fr'x={4*10}\n'
pydocs
pep-0498.txt:271
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_08.py
f"abc {a['x']} def"
pydocs
pep-0498.txt:281
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_09.py
f'''abc {a['x']} def'''
pydocs
pep-0498.txt:285
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_10.py
f'abc{expr1:spec1}{expr2!r:spec2}def{expr3}ghi'
pydocs
pep-0498.txt:297
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_11.py
def foo(): return 20 f'result={foo()}'
pydocs
pep-0498.txt:317
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
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
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_21.py
f'a={d["a"]}'
pydocs
pep-0498.txt:564
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_22.py
a = 'b' f'a={d[a]}'
pydocs
pep-0498.txt:570
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
legacy
fstring/legacy_09.py
'{i[";]}'.format(i={'";':4})
pydocs
pep-0498.txt:580
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_23.py
header = 'Subject' fr'{header}:\s+'
pydocs
pep-0498.txt:600
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_24.py
a = 'some string' f'{a!r}'
pydocs
pep-0498.txt:635
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_25.py
f'{repr(a)}'
pydocs
pep-0498.txt:641
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_26.py
f'{(lambda x: x*2)(3)}'
pydocs
pep-0498.txt:664
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_27.py
extra = '{},waiters:{}'.format(extra, len(self._waiters)) extra = f'{extra},waiters:{len(self._waiters)}'
pydocs
pep-0498.txt:686
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_28.py
message.append(" [line {0:2d}]".format(lineno)) message.append(f" [line {lineno:2d}]")
pydocs
pep-0498.txt:691
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_29.py
methoddef_name = "{}_METHODDEF".format(c_basename.upper()) methoddef_name = f"{c_basename.upper()}_METHODDEF"
pydocs
pep-0498.txt:696
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
fstring
498
3.6
modern
fstring/modern_30.py
print("Usage: {0} [{1}]".format(sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr) print(f"Usage: {sys.argv[0]} [{'|'.join('--'+opt for opt in valid_opts)}]", file=sys.stderr)
pydocs
pep-0498.txt:701
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_01.py
match = re.match(data) group = match.group(1) if match else None
pydocs
pep-0572.rst:87
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_02.py
group = re.match(data).group(1) if re.match(data) else None
pydocs
pep-0572.rst:92
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_03.py
match1 = pattern1.match(data) match2 = pattern2.match(data) if match1: result = match1.group(1) elif match2: result = match2.group(2) else: result = None
pydocs
pep-0572.rst:97
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_04.py
match1 = pattern1.match(data) if match1: result = match1.group(1) else: match2 = pattern2.match(data) if match2: result = match2.group(2) else: result = None
pydocs
pep-0572.rst:110
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_01.py
# Handle a matched regex if (match := pattern.search(data)) is not None: ... # Do something with match # A loop that can't be trivially rewritten using 2-arg iter() while chunk := file.read(8192): process(chunk) # Reuse a value that's expensive to compute [y := f(x), y**2, y**3] # Share a subexpression be...
pydocs
pep-0572.rst:133
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_02.py
f'{(x:=10)}' # Valid, uses assignment expression x = 10 f'{x:=10}' # Valid, passes '=10' to formatter
pydocs
pep-0572.rst:222
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_03.py
if any((comment := line).startswith('#') for line in lines): print("First comment:", comment) else: print("There are no comments") if all((nonblank := line).strip() == '' for line in lines): print("All lines are blank") else: print("First non-blank line:", nonblank)
pydocs
pep-0572.rst:257
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_04.py
# Compute partial sums in a list comprehension total = 0 partial_sums = [total := total + v for v in values] print("Total:", total)
pydocs
pep-0572.rst:270
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_05.py
[[(j := j) for i in range(5)] for j in range(5)] # INVALID [i := 0 for i, j in stuff] # INVALID [i+1 for i in (i := stuff)] # INVALID
pydocs
pep-0572.rst:287
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_06.py
[False and (i := 0) for i, j in stuff] # INVALID [i for i, j in stuff if True or (j := 1)] # INVALID
pydocs
pep-0572.rst:299
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_07.py
[i+1 for i in (j := stuff)] # INVALID [i+1 for i in range(2) for j in (k := stuff)] # INVALID [i+1 for i in [j for j in (k := stuff)]] # INVALID [i+1 for i in (lambda: (j := stuff))()] # INVALID
pydocs
pep-0572.rst:316
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_08.py
class Example: [(j := i) for i in range(5)] # INVALID
pydocs
pep-0572.rst:327
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_09.py
# Valid if any(len(longline := line) >= 100 for line in lines): print("Extremely long line:", longline)
pydocs
pep-0572.rst:386
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_10.py
x = 1, 2 # Sets x to (1, 2) (x := 1, 2) # Sets x to 1
pydocs
pep-0572.rst:433
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_05.py
env_base = os.environ.get("PYTHONUSERBASE", None) if env_base: return env_base
pydocs
pep-0572.rst:491
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_11.py
if env_base := os.environ.get("PYTHONUSERBASE", None): return env_base
pydocs
pep-0572.rst:497
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_06.py
if self._is_special: ans = self._check_nans(context=context) if ans: return ans
pydocs
pep-0572.rst:507
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_12.py
if self._is_special and (ans := self._check_nans(context=context)): return ans
pydocs
pep-0572.rst:514
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_07.py
reductor = dispatch_table.get(cls) if reductor: rv = reductor(x) else: reductor = getattr(x, "__reduce_ex__", None) if reductor: rv = reductor(4) else: reductor = getattr(x, "__reduce__", None) if reductor: rv = reductor() else: raise Error( ...
pydocs
pep-0572.rst:525
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_13.py
if reductor := dispatch_table.get(cls): rv = reductor(x) elif reductor := getattr(x, "__reduce_ex__", None): rv = reductor(4) elif reductor := getattr(x, "__reduce__", None): rv = reductor() else: raise Error("un(deep)copyable object of type %s" % cls)
pydocs
pep-0572.rst:542
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_08.py
s = _format_time(self._hour, self._minute, self._second, self._microsecond, timespec) tz = self._tzstr() if tz: s += tz return s
pydocs
pep-0572.rst:559
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_14.py
s = _format_time(self._hour, self._minute, self._second, self._microsecond, timespec) if tz := self._tzstr(): s += tz return s
pydocs
pep-0572.rst:569
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_09.py
while True: line = fp.readline() if not line: break m = define_rx.match(line) if m: n, v = m.group(1, 2) try: v = int(v) except ValueError: pass vars[n] = v else: m = undef_rx.match(line) if m: vars[m.group(1...
pydocs
pep-0572.rst:585
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_15.py
while line := fp.readline(): if m := define_rx.match(line): n, v = m.group(1, 2) try: v = int(v) except ValueError: pass vars[n] = v elif m := undef_rx.match(line): vars[m.group(1)] = 0
pydocs
pep-0572.rst:604
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_16.py
results = [(x, y, x/y) for x in input_data if (y := f(x)) > 0]
pydocs
pep-0572.rst:622
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_17.py
stuff = [[y := f(x), x/y] for x in range(5)]
pydocs
pep-0572.rst:627
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_18.py
# Loop-and-a-half while (command := input("> ")) != "quit": print("You entered:", command) # Capturing regular expression match objects # See, for instance, Lib/pydoc.py, which uses a multiline spelling # of this effect if match := re.search(pat, text): print("Found:", match.group(0)) # The same syntax chains ...
pydocs
pep-0572.rst:639
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_19.py
if pid := os.fork(): ... # Parent code else: ... # Child code
pydocs
pep-0572.rst:669
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_20.py
pos = -1 while pos := buffer.find(search_term, pos + 1) >= 0: ...
pydocs
pep-0572.rst:862
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_21.py
(point := (x, y)) (point := x, y)
pydocs
pep-0572.rst:882
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_22.py
foo(x := 1, y) foo(x := (1, y))
pydocs
pep-0572.rst:892
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_23.py
# Top level in if if match := pattern.match(line): return match.group(1) # Short call len(lines := f.readlines())
pydocs
pep-0572.rst:907
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_10.py
mylast = mylast[1] yield mylast[0]
pydocs
pep-0572.rst:996
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
modern
walrus/modern_24.py
yield (mylast := mylast[1])[0]
pydocs
pep-0572.rst:1001
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0
train
3.8
walrus
572
3.8
legacy
walrus/legacy_11.py
while True: old = total total += term if old == total: return total term *= mx2 / (i*(i+1)) i += 2
pydocs
pep-0572.rst:1009
3c69ec5e81bc7dc5a6a2a90b6ffb6a2d7b626c96
CC0-1.0