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.10 | walrus | 572 | 3.8 | modern | walrus/modern_31.py | def f():
global TARGET
a = [TARGET := EXPR for VAR in ITERABLE]
| pydocs | pep-0572.rst:1211 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | walrus | 572 | 3.8 | modern | walrus/modern_32.py | def g():
TARGET = ...
def f():
nonlocal TARGET
a = [TARGET := EXPR for VAR in ITERABLE]
| pydocs | pep-0572.rst:1230 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | walrus | 572 | 3.8 | modern | walrus/modern_33.py | def f():
a = [[TARGET := i for i in range(3)] for j in range(2)]
# I.e., a = [[0, 1, 2], [0, 1, 2]]
print(TARGET) # prints 2
| pydocs | pep-0572.rst:1253 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | walrus | 572 | 3.8 | modern | walrus/modern_34.py | a = 42
def f():
# `a` is local to `f`, but remains unbound
# until the caller executes this genexp:
yield ((a := i) for i in range(3))
yield lambda: a + 100
print("done")
try:
print(f"`a` is bound to {a}")
assert False
except UnboundLocalError:
print("`a` is not yet b... | pydocs | pep-0572.rst:1284 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_01.py | match command.split():
case [action, obj]:
... # interpret action, obj
| pydocs | pep-0636.rst:66 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_02.py | match command.split():
case [action]:
... # interpret single-verb action
case [action, obj]:
... # interpret action, obj
| pydocs | pep-0636.rst:97 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_03.py | match command.split():
case ["quit"]:
print("Goodbye!")
quit_game()
case ["look"]:
current_room.describe()
case ["get", obj]:
character.get(obj, current_room)
case ["go", direction]:
current_room = current_room.neighbor(direction)
# The rest of your commands g... | pydocs | pep-0636.rst:119 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_04.py | match command.split():
case ["drop", *objects]:
for obj in objects:
character.drop(obj, current_room)
# The rest of your commands go here
| pydocs | pep-0636.rst:150 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_05.py | match command.split():
case ["go", ("north" | "south" | "east" | "west")]:
current_room = current_room.neighbor(...)
# how do I know which direction to go?
| pydocs | pep-0636.rst:248 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_06.py | match command.split():
case ["go", ("north" | "south" | "east" | "west") as direction]:
current_room = current_room.neighbor(direction)
| pydocs | pep-0636.rst:258 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_07.py | match command.split():
case ["go", direction] if direction in current_room.exits:
current_room = current_room.neighbor(direction)
case ["go", _]:
print("Sorry, you can't go that way")
| pydocs | pep-0636.rst:274 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_08.py | match event.get():
case Click((x, y)):
handle_click_at(x, y)
| pydocs | pep-0636.rst:347 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_09.py | match event.get():
case Click((x, y), button=Button.LEFT): # This is a left click
handle_click_at(x, y)
case Click():
pass # ignore other clicks
| pydocs | pep-0636.rst:376 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_10.py | for action in actions:
match action:
case {"text": message, "color": c}:
ui.set_text_color(c)
ui.display(message)
case {"sleep": duration}:
ui.wait(duration)
case {"sound": url, "format": "ogg"}:
ui.play(url)
case {"sound": _, "format":... | pydocs | pep-0636.rst:404 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_11.py | for action in actions:
match action:
case {"text": str(message), "color": str(c)}:
ui.set_text_color(c)
ui.display(message)
case {"sleep": float(duration)}:
ui.wait(duration)
case {"sound": str(url), "format": "ogg"}:
ui.play(url)
case ... | pydocs | pep-0636.rst:440 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_12.py | def http_error(status):
match status:
case 400:
return "Bad request"
case 404:
return "Not found"
case 418:
return "I'm a teapot"
case _:
return "Something's wrong with the Internet"
| pydocs | pep-0636.rst:466 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_13.py | # point is an (x, y) tuple
match point:
case (0, 0):
print("Origin")
case (0, y):
print(f"Y={y}")
case (x, 0):
print(f"X={x}")
case (x, y):
print(f"X={x}, Y={y}")
case _:
raise ValueError("Not a point")
| pydocs | pep-0636.rst:488 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_14.py | from dataclasses import dataclass
@dataclass
class Point:
x: int
y: int
def where_is(point):
match point:
case Point(x=0, y=0):
print("Origin")
case Point(x=0, y=y):
print(f"Y={y}")
case Point(x=x, y=0):
print(f"X={x}")
case Point():
... | pydocs | pep-0636.rst:512 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_15.py | match points:
case []:
print("No points")
case [Point(0, 0)]:
print("The origin")
case [Point(x, y)]:
print(f"Single point {x}, {y}")
case [Point(0, y1), Point(0, y2)]:
print(f"Two on the Y axis at {y1}, {y2}")
case _:
print("Something else")
| pydocs | pep-0636.rst:546 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_16.py | match point:
case Point(x, y) if x == y:
print(f"Y=X at {x}")
case Point(x, y):
print(f"Not on the diagonal")
| pydocs | pep-0636.rst:562 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | pattern-matching | 634 | 3.10 | modern | pattern-matching/modern_17.py | from enum import Enum
class Color(Enum):
RED = 0
GREEN = 1
BLUE = 2
match color:
case Color.RED:
print("I see red!")
case Color.GREEN:
print("Grass is green")
case Color.BLUE:
print("I'm feeling the blues :(")
| pydocs | pep-0636.rst:596 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_01.py | d1 = {'spam': 1}
d2 = {'eggs': 2}
merged = ChainMap(d2, d1)
merged['eggs'] = 999
d2
| pydocs | pep-0584.rst:83 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_02.py | d1 = {"spam": 1}
d2 = {3665: 2}
dict(d1, **d2)
| pydocs | pep-0584.rst:98 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_03.py | {'a': 1, 'a': 2}
{**d, **e}
d.update(e)
d[k] = v
{k: v for x in (d, e) for (k, v) in x.items()}
| pydocs | pep-0584.rst:124 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_01.py | d = {'spam': 1, 'eggs': 2, 'cheese': 3}
e = {'cheese': 'cheddar', 'aardvark': 'Ethel'}
d | e
e | d
| pydocs | pep-0584.rst:150 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_02.py | d |= e
d
| pydocs | pep-0584.rst:159 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_03.py | d | [('spam', 999)]
d |= [('spam', 999)]
d
| pydocs | pep-0584.rst:170 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_04.py | new = {}
for d in many_dicts:
new |= d
| pydocs | pep-0584.rst:270 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_05.py | flags |= WRITEABLE # Probably numeric bitwise-or.
DO_NOT_RUN = WEEKENDS | HOLIDAYS # Probably set union.
settings = DEFAULT_SETTINGS | user_settings | workspace_settings # Probably dict union.
| pydocs | pep-0584.rst:388 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_06.py | d2 | d1 # d1 merged with d2, keeping existing values in d1
| pydocs | pep-0584.rst:491 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_07.py | {'a': [1, 2]} | {'a': [3, 4]}
| pydocs | pep-0584.rst:501 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_04.py | aliases = dict(kernel_aliases)
aliases.update(shell_aliases)
| pydocs | pep-0584.rst:670 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_08.py | aliases = kernel_aliases | shell_aliases
| pydocs | pep-0584.rst:675 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_05.py | kernel_aliases = dict(base_aliases)
kernel_aliases.update({
'ip' : 'KernelApp.ip',
'hb' : 'KernelApp.hb_port',
'shell' : 'KernelApp.shell_port',
'iopub' : 'KernelApp.iopub_port',
'stdin' : 'KernelApp.stdin_port',
'parent': 'KernelApp.parent',
})
if sys.platform.startswith('win'):
kernel_alia... | pydocs | pep-0584.rst:684 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_09.py | kernel_aliases = base_aliases | {
'ip' : 'KernelApp.ip',
'hb' : 'KernelApp.hb_port',
'shell' : 'KernelApp.shell_port',
'iopub' : 'KernelApp.iopub_port',
'stdin' : 'KernelApp.stdin_port',
'parent': 'KernelApp.parent',
}
if sys.platform.startswith('win'):
kernel_aliases['interrupt'] = 'KernelA... | pydocs | pep-0584.rst:708 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_06.py | attrib = attrib.copy()
attrib.update(extra)
attrib = attrib.items()
| pydocs | pep-0584.rst:735 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_10.py | attrib = (attrib | extra).items()
| pydocs | pep-0584.rst:741 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_07.py | edges = {}
edges.update(dict(zip(self.triangle_nodes[border[:,0]][:,1],
self.triangle_nodes[border[:,0]][:,2])))
edges.update(dict(zip(self.triangle_nodes[border[:,1]][:,2],
self.triangle_nodes[border[:,1]][:,0])))
edges.update(dict(zip(self.triangle_nodes[border[:,2]][:,0],
self.... | pydocs | pep-0584.rst:750 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_11.py | edges = {}
edges |= zip(self.triangle_nodes[border[:,0]][:,1],
self.triangle_nodes[border[:,0]][:,2])
edges |= zip(self.triangle_nodes[border[:,1]][:,2],
self.triangle_nodes[border[:,1]][:,0])
edges |= zip(self.triangle_nodes[border[:,2]][:,0],
self.triangle_nodes[border[:,2]][:,1... | pydocs | pep-0584.rst:760 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_08.py | hm = default_handler_map.copy()
hm.update(self._handler_map)
return hm
| pydocs | pep-0584.rst:775 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_12.py | return default_handler_map | self._handler_map
| pydocs | pep-0584.rst:781 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_09.py | _optinfo = {}
_optinfo.update(getattr(obj, '_optinfo', {}))
_optinfo.update(getattr(obj, '_basedict', {}))
if not isinstance(obj, MaskedArray):
_optinfo.update(getattr(obj, '__dict__', {}))
| pydocs | pep-0584.rst:790 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_13.py | _optinfo = {}
_optinfo |= getattr(obj, '_optinfo', {})
_optinfo |= getattr(obj, '_basedict', {})
if not isinstance(obj, MaskedArray):
_optinfo |= getattr(obj, '__dict__', {})
| pydocs | pep-0584.rst:798 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_10.py | data = {'name': six.text_type(user), 'type': relationship}
data.update(kwargs)
| pydocs | pep-0584.rst:811 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_14.py | data = {'name': six.text_type(user), 'type': relationship} | kwargs
| pydocs | pep-0584.rst:816 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_11.py | kwargs.update(lexer.options)
lx = lexer.__class__(**kwargs)
| pydocs | pep-0584.rst:825 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_15.py | lx = lexer.__class__(**(kwargs | lexer.options))
| pydocs | pep-0584.rst:830 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_12.py | merged_setting = dict_class(to_key_val_list(session_setting))
merged_setting.update(to_key_val_list(request_setting))
| pydocs | pep-0584.rst:839 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_16.py | merged_setting = dict_class(to_key_val_list(session_setting)) | to_key_val_list(request_setting)
| pydocs | pep-0584.rst:844 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_13.py | self.attrs = self.known_attrs.copy()
self.attrs.update(attrs)
| pydocs | pep-0584.rst:853 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_17.py | self.attrs = self.known_attrs | attrs
| pydocs | pep-0584.rst:858 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_14.py | new_opt = code[0].options.copy()
new_opt.update(example.options)
example.options = new_opt
| pydocs | pep-0584.rst:867 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_18.py | example.options = code[0].options | example.options
| pydocs | pep-0584.rst:873 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_15.py | n_attrs = self.default_node_attrs.copy()
e_attrs = self.default_edge_attrs.copy()
g_attrs.update(graph_attrs)
n_attrs.update(node_attrs)
e_attrs.update(edge_attrs)
| pydocs | pep-0584.rst:882 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_19.py | g_attrs |= graph_attrs
n_attrs = self.default_node_attrs | node_attrs
e_attrs = self.default_edge_attrs | edge_attrs
| pydocs | pep-0584.rst:890 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_16.py | kwargs.update(self.formatter_args)
return self.formatter(**kwargs)
| pydocs | pep-0584.rst:901 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_20.py | return self.formatter(**(kwargs | self.formatter_args))
| pydocs | pep-0584.rst:906 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_17.py | d2 = DEFAULT_VALUE.copy()
d2.update(dict(("ext_"+ext, False) for ext in EXTENSIONS))
d2.update(d)
d = d2
| pydocs | pep-0584.rst:915 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_21.py | d = DEFAULT_VALUE | dict(("ext_"+ext, False) for ext in EXTENSIONS) | d
| pydocs | pep-0584.rst:922 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_18.py | clash = {}
clash.update(clash1)
clash.update(clash2)
return clash1, clash2, clash
| pydocs | pep-0584.rst:931 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_22.py | return clash1, clash2, clash1 | clash2
| pydocs | pep-0584.rst:938 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_19.py | dct = MaximaHelpers.__dict__.copy()
dct.update(name_dict)
obj = sympify(str, locals=dct)
| pydocs | pep-0584.rst:947 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_23.py | obj = sympify(str, locals=MaximaHelpers.__dict__|name_dict)
| pydocs | pep-0584.rst:953 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_20.py | self.known_functions = dict(known_functions)
userfuncs = settings.get('user_functions', {})
self.known_functions.update(userfuncs)
| pydocs | pep-0584.rst:962 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_24.py | self.known_functions = known_functions | settings.get('user_functions', {})
| pydocs | pep-0584.rst:968 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | legacy | dict-union/legacy_21.py | globs = globs.copy()
if extraglobs is not None:
globs.update(extraglobs)
| pydocs | pep-0584.rst:977 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | dict-union | 584 | 3.9 | modern | dict-union/modern_25.py | globs = globs | (extraglobs if extraglobs is not None else {})
| pydocs | pep-0584.rst:983 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | legacy | async-generators/legacy_01.py | class Ticker:
"""Yield numbers from 0 to `to` every `delay` seconds."""
def __init__(self, delay, to):
self.delay = delay
self.i = 0
self.to = to
def __aiter__(self):
return self
async def __anext__(self):
i = self.i
if i >= self.to:
raise S... | pydocs | pep-0525.txt:46 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | modern | async-generators/modern_01.py | async def ticker(delay, to):
"""Yield numbers from 0 to `to` every `delay` seconds."""
for i in range(to):
yield i
await asyncio.sleep(delay)
| pydocs | pep-0525.txt:69 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | modern | async-generators/modern_02.py | async def coro(): # a coroutine function
await smth()
async def asyncgen(): # an asynchronous generator function
await smth()
yield 42
| pydocs | pep-0525.txt:101 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | modern | async-generators/modern_03.py | async def genfunc():
yield 1
yield 2
gen = genfunc()
assert gen.__aiter__() is gen
assert await gen.__anext__() == 1
assert await gen.__anext__() == 2
await gen.__anext__() # This line will raise StopAsyncIteration.
| pydocs | pep-0525.txt:129 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | modern | async-generators/modern_04.py | async def square_series(con, to):
async with con.transaction():
cursor = con.cursor(
'SELECT generate_series(0, $1) AS i', to)
async for row in cursor:
yield row['i'] ** 2
async for i in square_series(con, 1000):
if i == 100:
break
| pydocs | pep-0525.txt:155 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | modern | async-generators/modern_05.py | async def gen():
try:
yield
finally:
await asyncio.sleep(1) # Can use 'await'.
yield # Cannot use 'yield',
# this line will trigger a
# RuntimeError.
| pydocs | pep-0525.txt:191 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | modern | async-generators/modern_06.py | async def gen():
await asyncio.sleep(0.1)
v = yield 42
print(v)
await asyncio.sleep(0.2)
g = gen()
await g.asend(None) # Will return 42 after sleeping
# for 0.1 seconds.
await g.asend('hello') # Will print 'hello' and
# raise StopAsyncIteration... | pydocs | pep-0525.txt:307 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | modern | async-generators/modern_07.py | N = 10 ** 7
async def agen():
for i in range(N):
yield i
class AIter:
def __init__(self):
self.i = 0
def __aiter__(self):
return self
async def __anext__(self):
i = self.i
if i >= N:
raise StopAsyncIteration
self.i += 1
return i
| pydocs | pep-0525.txt:492 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | modern | async-generators/modern_08.py | async def g1():
yield 1
yield 2
async def g2():
async for v in g1():
yield v
| pydocs | pep-0525.txt:553 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | modern | async-generators/modern_09.py | @async_context_manager
async def ctx():
await open()
try:
yield
finally:
await close()
async with ctx():
await ...
| pydocs | pep-0525.txt:570 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | async-generators | 525 | 3.6 | modern | async-generators/modern_10.py | async def ticker(delay, to):
for i in range(to):
yield i
await asyncio.sleep(delay)
async def run():
async for i in ticker(1, 10):
print(i)
import asyncio
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(run())
finally:
loop.close()
| pydocs | pep-0525.txt:599 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_01.py | # Declare a context variable 'var' with the default value 42.
var = ContextVar('var', default=42)
| pydocs | pep-0567.rst:150 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_02.py | ctx = contextvars.copy_context()
| pydocs | pep-0567.rst:234 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_03.py | var = ContextVar('var')
var.set('spam')
def main():
# 'var' was set to 'spam' before
# calling 'copy_context()' and 'ctx.run(main)', so:
# var.get() == ctx[var] == 'spam'
var.set('ham')
# Now, after setting 'var' to 'ham':
# var.get() == ctx[var] == 'ham'
ctx = copy_context()
# Any changes ... | pydocs | pep-0567.rst:244 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_04.py | ctx = contextvars.copy_context()
# Print all context variables and their values in 'ctx':
print(ctx.items())
# Print the value of 'some_variable' in context 'ctx':
print(ctx[some_variable])
| pydocs | pep-0567.rst:279 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_05.py | def call_soon(self, callback, *args, context=None):
if context is None:
context = contextvars.copy_context()
# ... some time later
context.run(callback, *args)
| pydocs | pep-0567.rst:312 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_06.py | class Task:
def __init__(self, coro):
...
# Get the current context snapshot.
self._context = contextvars.copy_context()
self._loop.call_soon(self._step, context=self._context)
def _step(self, exc=None):
...
# Every advance of the wrapped coroutine is done in
... | pydocs | pep-0567.rst:323 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_07.py | var = ContextVar('var')
ctx = copy_context()
ctx[var] = 'value'
print(ctx[var]) # Prints 'value'
print(var.get()) # Raises a LookupError
| pydocs | pep-0567.rst:711 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_08.py | ctx = copy_context()
def func():
ctx[var] = 'value'
# Contrary to the previous example, this would work
# because 'func()' is running within 'ctx'.
print(ctx[var])
print(var.get())
ctx.run(func)
| pydocs | pep-0567.rst:721 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_09.py | # Framework:
current_request: ContextVar[Request] = \
ContextVar('current_request')
# Later, while handling an HTTP request:
request: Request = current_request.get()
# Work with the 'request' object:
return request.method
| pydocs | pep-0567.rst:755 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_10.py | # Framework:
current_request: ContextVar[Optional[Request]] = \
ContextVar('current_request', initial_value=None)
# Later, while handling an HTTP request:
request: Optional[Request] = current_request.get()
# Check if the current request object was set:
if request is None:
raise RuntimeError
# Work with the ... | pydocs | pep-0567.rst:774 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | legacy | context-vars/legacy_01.py | class PrecisionStorage(threading.local):
# Subclass threading.local to specify a default value.
value = 0.0
precision = PrecisionStorage()
# To set a new precision:
precision.value = 0.5
# To read the current precision:
print(precision.value)
| pydocs | pep-0567.rst:816 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_11.py | precision = contextvars.ContextVar('precision', default=0.0)
# To set a new precision:
precision.set(0.5)
# To read the current precision:
print(precision.get())
| pydocs | pep-0567.rst:831 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | context-vars | 567 | 3.7 | modern | context-vars/modern_12.py | executor = ThreadPoolExecutor()
current_context = contextvars.copy_context()
executor.submit(current_context.run, some_function)
| pydocs | pep-0567.rst:846 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | breakpoint | 553 | 3.7 | legacy | breakpoint/legacy_01.py | foo()
import pdb; pdb.set_trace()
bar()
| pydocs | pep-0553.rst:28 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | breakpoint | 553 | 3.7 | modern | breakpoint/modern_01.py | foo()
breakpoint()
bar()
| pydocs | pep-0553.rst:71 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | breakpoint | 553 | 3.7 | modern | breakpoint/modern_02.py | os.environ['PYTHONBREAKPOINT'] = 'foo.bar.baz'
breakpoint() # Imports foo.bar and calls foo.bar.baz()
| pydocs | pep-0553.rst:142 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | str-affix-removal | 616 | 3.9 | legacy | str-affix-removal/legacy_01.py | if test_func_name.startswith("test_"):
print(test_func_name[5:])
else:
print(test_func_name)
| pydocs | pep-0616.rst:105 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | str-affix-removal | 616 | 3.9 | modern | str-affix-removal/modern_01.py | print(test_func_name.removeprefix("test_"))
| pydocs | pep-0616.rst:112 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | str-affix-removal | 616 | 3.9 | legacy | str-affix-removal/legacy_02.py | if funcname.startswith("context."):
self.funcname = funcname.replace("context.", "")
self.contextfunc = True
else:
self.funcname = funcname
self.contextfunc = False
| pydocs | pep-0616.rst:124 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | str-affix-removal | 616 | 3.9 | modern | str-affix-removal/modern_02.py | if funcname.startswith("context."):
self.funcname = funcname.removeprefix("context.")
self.contextfunc = True
else:
self.funcname = funcname
self.contextfunc = False
| pydocs | pep-0616.rst:133 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | str-affix-removal | 616 | 3.9 | modern | str-affix-removal/modern_03.py | self.contextfunc = funcname.startswith("context.")
self.funcname = funcname.removeprefix("context.")
| pydocs | pep-0616.rst:142 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
train | 3.10 | str-affix-removal | 616 | 3.9 | legacy | str-affix-removal/legacy_03.py | def strip_quotes(text):
if text.startswith('"'):
text = text[1:]
if text.endswith('"'):
text = text[:-1]
return text
| pydocs | pep-0616.rst:151 | 2c89d6ac2ccea9d8691f1b75d95c2d7294cc32ca | CC0-1.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.