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
887 values
source
stringclasses
1 value
origin
stringclasses
887 values
origin_revision
stringclasses
1 value
license
stringclasses
1 value
train
3.12
type-param-syntax
695
3.12
modern
type-param-syntax/modern_23.py
T = 0 # T refers to the global variable print(T) # Prints 0 class Outer[T]: T = 1 # T refers to the local variable scoped to class 'Outer' print(T) # Prints 1 class Inner1: T = 2 # T refers to the local type variable within 'Inner1' print(T) # Prints 2 def inner_...
pydocs
pep-0695.rst:548
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
type-param-syntax
695
3.12
modern
type-param-syntax/modern_24.py
class ClassA[T]((x := Sequence[T])): ... # Syntax error: assignment expression not allowed def func1[T](val: (x := int)): ... # Syntax error: assignment expression not allowed def func2[T]() -> (x := Sequence[T]): ... # Syntax error: assignment expression not allowed type Alias1[T] = (x := list[T]) # Syntax erro...
pydocs
pep-0695.rst:597
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
type-param-syntax
695
3.12
modern
type-param-syntax/modern_25.py
class ClassA[T1, T2, T3](list[T1]): def method1(self, a: T2) -> None: ... def method2(self) -> T3: ...
pydocs
pep-0695.rst:664
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
type-param-syntax
695
3.12
legacy
type-param-syntax/legacy_04.py
T1 = TypeVar("T1", infer_variance=True) # Inferred variance T2 = TypeVar("T2") # Invariant T3 = TypeVar("T3", covariant=True) # Covariant # A type checker should infer the variance for T1 but use the # specified variance for T2 and T3. class ClassA(Generic[T1, T2, T3]): ...
pydocs
pep-0695.rst:719
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
type-param-syntax
695
3.12
modern
type-param-syntax/modern_26.py
K = TypeVar("K") class ClassA[V](dict[K, V]): ... # Type checker error class ClassB[K, V](dict[K, V]): ... # OK class ClassC[V]: # The use of K and V for "method1" is OK because it uses the # "traditional" generic function mechanism where type parameters # are implicit. In this case V comes from an out...
pydocs
pep-0695.rst:744
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
type-param-syntax
695
3.12
modern
type-param-syntax/modern_27.py
X = int class Foo[T: X, U: X]: t, u = T, U print(Foo.t.__bound__) # prints "int" X = str print(Foo.u.__bound__) # prints "str"
pydocs
pep-0695.rst:866
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
type-param-syntax
695
3.12
modern
type-param-syntax/modern_28.py
type Alias = int
pydocs
pep-0695.rst:946
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
type-param-syntax
695
3.12
modern
type-param-syntax/modern_29.py
type Alias[T: int] = list[T]
pydocs
pep-0695.rst:957
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
type-param-syntax
695
3.12
modern
type-param-syntax/modern_30.py
def f[T](x: T) -> T: return x
pydocs
pep-0695.rst:974
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
type-param-syntax
695
3.12
modern
type-param-syntax/modern_31.py
class C[T](Base): def __init__(self, x: T): self.x = x
pydocs
pep-0695.rst:1028
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
type-param-syntax
695
3.12
modern
type-param-syntax/modern_32.py
class C: class Nested: ... def generic_method[T](self, x: T, y: Nested) -> T: ...
pydocs
pep-0695.rst:1048
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
override-decorator
698
3.12
modern
override-decorator/modern_01.py
from typing import override class Parent: def foo(self) -> int: return 1 def bar(self, x: str) -> str: return x class Child(Parent): @override def foo(self) -> int: return 2 @override def baz(self) -> int: # Type check error: no matching signature in ancestor ...
pydocs
pep-0698.rst:186
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring-grammar
701
3.12
modern
fstring-grammar/modern_01.py
f'Magic wand: { bag['wand'] }'
pydocs
pep-0701.rst:44
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring-grammar
701
3.12
modern
fstring-grammar/modern_02.py
f'''A complex trick: { bag['bag'] # recursive bags! }'''
pydocs
pep-0701.rst:56
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring-grammar
701
3.12
modern
fstring-grammar/modern_03.py
f"These are the things: {", ".join(things)}" f"{source.removesuffix(".py")}.c: $(srcdir)/{source}" f"{f"{f"infinite"}"}" + " " + f"{f"nesting!!!"}"
pydocs
pep-0701.rst:144
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring-grammar
701
3.12
modern
fstring-grammar/modern_04.py
a = ["hello", "world"] f"{'\n'.join(a)}"
pydocs
pep-0701.rst:157
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring-grammar
701
3.12
modern
fstring-grammar/modern_05.py
f"{f"{f"{f"{f"{f"{1+1}"}"}"}"}"}"
pydocs
pep-0701.rst:192
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring-grammar
701
3.12
modern
fstring-grammar/modern_06.py
x = 1 f"___{ x }___" f"___{( x )}___"
pydocs
pep-0701.rst:422
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring-grammar
701
3.12
modern
fstring-grammar/modern_07.py
def py2c(source): return f"{source.removesuffix(".py")}.c"
pydocs
pep-0701.rst:491
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:33
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
legacy
fstring/legacy_01.py
msg = 'disk failure' 'error: %s' % msg
pydocs
pep-0498.rst:59
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
legacy
fstring/legacy_02.py
msg = ('disk failure', 32) 'error: %s' % msg
pydocs
pep-0498.rst:65
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
legacy
fstring/legacy_03.py
'error: %s' % (msg,)
pydocs
pep-0498.rst:73
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
legacy
fstring/legacy_04.py
value = 4 * 20 'The value is {value}.'.format(value=value)
pydocs
pep-0498.rst:87
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
legacy
fstring/legacy_05.py
'The value is {}.'.format(value)
pydocs
pep-0498.rst:95
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_02.py
f'The value is {value}.'
pydocs
pep-0498.rst:100
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_03.py
value = 1234 f'input={value:#06x}'
pydocs
pep-0498.rst:115
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:122
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:134
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:149
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_05.py
f'{"quoted string"}'
pydocs
pep-0498.rst:251
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_06.py
f'{{ {4*10} }}' f'{{{4*10}}}'
pydocs
pep-0498.rst:260
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_07.py
fr'x={4*10}\n'
pydocs
pep-0498.rst:268
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_08.py
f"abc {a['x']} def"
pydocs
pep-0498.rst:278
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_09.py
f'''abc {a['x']} def'''
pydocs
pep-0498.rst:282
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_10.py
f'abc{expr1:spec1}{expr2!r:spec2}def{expr3}ghi'
pydocs
pep-0498.rst:294
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_11.py
def foo(): return 20 f'result={foo()}'
pydocs
pep-0498.rst:314
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_12.py
x = 0 f'''{x +1}''' d = {0: 'zero'} f'''{d[0 ]}'''
pydocs
pep-0498.rst:331
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:347
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:365
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:410
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_16.py
for x in (32, 100, 'fifty'): print(f'x = {x:+3}')
pydocs
pep-0498.rst:422
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:444
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_18.py
f'Column={col_idx+1}' f'number of items: {len(items)}'
pydocs
pep-0498.rst:518
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:523
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:532
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
legacy
fstring/legacy_08.py
d = {'a': 10, 'b': 20} 'a={d[a]}'.format(d=d)
pydocs
pep-0498.rst:551
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_21.py
f'a={d["a"]}'
pydocs
pep-0498.rst:561
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_22.py
a = 'b' f'a={d[a]}'
pydocs
pep-0498.rst:567
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
legacy
fstring/legacy_09.py
'{i[";]}'.format(i={'";':4})
pydocs
pep-0498.rst:577
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_23.py
header = 'Subject' fr'{header}:\s+'
pydocs
pep-0498.rst:597
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_24.py
a = 'some string' f'{a!r}'
pydocs
pep-0498.rst:632
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_25.py
f'{repr(a)}'
pydocs
pep-0498.rst:638
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
fstring
498
3.6
modern
fstring/modern_26.py
f'{(lambda x: x*2)(3)}'
pydocs
pep-0498.rst:661
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:683
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:688
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:693
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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.rst:698
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:86
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:91
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:96
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:109
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:132
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:221
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:256
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:269
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:286
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:298
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:315
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_08.py
class Example: [(j := i) for i in range(5)] # INVALID
pydocs
pep-0572.rst:326
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:385
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:432
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:490
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_11.py
if env_base := os.environ.get("PYTHONUSERBASE", None): return env_base
pydocs
pep-0572.rst:496
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:506
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:513
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:524
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:541
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:558
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:568
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:584
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:603
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:621
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_17.py
stuff = [[y := f(x), x/y] for x in range(5)]
pydocs
pep-0572.rst:626
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:638
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_19.py
if pid := os.fork(): ... # Parent code else: ... # Child code
pydocs
pep-0572.rst:668
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_20.py
pos = -1 while pos := buffer.find(search_term, pos + 1) >= 0: ...
pydocs
pep-0572.rst:861
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_21.py
(point := (x, y)) (point := x, y)
pydocs
pep-0572.rst:881
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_22.py
foo(x := 1, y) foo(x := (1, y))
pydocs
pep-0572.rst:891
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:906
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
legacy
walrus/legacy_10.py
mylast = mylast[1] yield mylast[0]
pydocs
pep-0572.rst:995
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_24.py
yield (mylast := mylast[1])[0]
pydocs
pep-0572.rst:1000
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
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:1008
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_25.py
while total != (total := total + term): term *= mx2 / (i*(i+1)) i += 2 return total
pydocs
pep-0572.rst:1018
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
legacy
walrus/legacy_12.py
result = solution(xs, n) if result: ... # use result
pydocs
pep-0572.rst:1036
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_26.py
if result := solution(xs, n): ... # use result
pydocs
pep-0572.rst:1043
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
legacy
walrus/legacy_13.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("un(sha...
pydocs
pep-0572.rst:1056
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_27.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(shallow)copyable object of type %s" % cls)
pydocs
pep-0572.rst:1073
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
legacy
walrus/legacy_14.py
diff = x - x_base if diff: g = gcd(diff, n) if g > 1: return g
pydocs
pep-0572.rst:1090
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.12
walrus
572
3.8
modern
walrus/modern_28.py
if (diff := x - x_base) and (g := gcd(diff, n)) > 1: return g
pydocs
pep-0572.rst:1098
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0