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.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_49.py | def foo(x: AnyStr, y: AnyStr = ...) -> AnyStr: ...
| pydocs | pep-0484.txt:1355 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_50.py | def quux(__x: int, __y__: int = 0) -> None: ...
quux(3, __y__=1) # This call is fine.
quux(__x=3) # This call is an error.
| pydocs | pep-0484.txt:1374 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_51.py | def echo_round() -> Generator[int, float, str]:
res = yield
while res:
res = yield round(res)
return 'OK'
| pydocs | pep-0484.txt:1388 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_52.py | async def spam(ignored: int) -> str:
return 'spam'
async def foo() -> None:
bar = await spam(42) # type: str
| pydocs | pep-0484.txt:1398 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | legacy | type-hints/legacy_05.py | from typing import List, Coroutine
c = None # type: Coroutine[List[str], str, int]
...
x = c.send('hi') # type: List[str]
async def bar() -> None:
x = await c # type: int
| pydocs | pep-0484.txt:1410 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_53.py | def op() -> typing.Awaitable[str]:
if cond:
return spam(42)
else:
return asyncio.Future(...)
| pydocs | pep-0484.txt:1421 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | legacy | type-hints/legacy_06.py | x = [] # type: List[Employee]
x, y, z = [], [], [] # type: List[int], List[int], List[str]
x, y, z = [], [], [] # type: (List[int], List[int], List[str])
a, b, *c = range(5) # type: float, float, List[float]
x = [1, 2] # type: List[int]
| pydocs | pep-0484.txt:1465 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | legacy | type-hints/legacy_07.py | with frobnicate() as foo: # type: int
# Here foo is an int
...
for x, y in points: # type: float, float
# Here x and y are floats
...
| pydocs | pep-0484.txt:1477 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | legacy | type-hints/legacy_08.py | from typing import IO
stream = None # type: IO[str]
| pydocs | pep-0484.txt:1497 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_54.py | from typing import List, cast
def find_first_str(a: List[object]) -> str:
index = next(i for i, x in enumerate(a) if isinstance(x, str))
# We only get here if there's at least one string in a
return cast(str, a[index])
| pydocs | pep-0484.txt:1538 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_55.py | class Derived(Base):
def __init__(self, _x: Base) -> None:
...
| pydocs | pep-0484.txt:1578 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_56.py | UserId = NewType('UserId', int)
def name_by_id(user_id: UserId) -> str:
...
UserId('user') # Fails type check
name_by_id(42) # Fails type check
name_by_id(UserId(42)) # OK
num = UserId(5) + 1 # type: int
| pydocs | pep-0484.txt:1587 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_57.py | class PacketId:
def __init__(self, major: int, minor: int) -> None:
self._major = major
self._minor = minor
TcpPacketId = NewType('TcpPacketId', PacketId)
packet = PacketId(100, 100)
tcp_packet = TcpPacketId(packet) # OK
tcp_packet = TcpPacketId(127, 0) # Fails in type checker and at runtime
| pydocs | pep-0484.txt:1606 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_58.py | def __getattr__(name) -> Any: ...
| pydocs | pep-0484.txt:1685 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_59.py | from typing import overload
class bytes:
...
@overload
def __getitem__(self, i: int) -> int: ...
@overload
def __getitem__(self, s: slice) -> bytes: ...
| pydocs | pep-0484.txt:1699 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_60.py | from typing import Union
class bytes:
...
def __getitem__(self, a: Union[int, slice]) -> Union[int, bytes]: ...
| pydocs | pep-0484.txt:1712 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_61.py | @overload
def map(func: None, iter1: Iterable[T1]) -> Iterable[T1]: ...
@overload
def map(func: None,
iter1: Iterable[T1],
iter2: Iterable[T2]) -> Iterable[Tuple[T1, T2]]: ...
| pydocs | pep-0484.txt:1737 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_62.py | from typing import TypeVar
AnyStr = TypeVar('AnyStr', str, bytes)
def concat1(x: AnyStr, y: AnyStr) -> AnyStr: ...
@overload
def concat2(x: str, y: str) -> str: ...
@overload
def concat2(x: bytes, y: bytes) -> bytes: ...
| pydocs | pep-0484.txt:1786 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | legacy | type-hints/legacy_09.py | def add(a, b): # type: (int, int) -> int
return a + b
| pydocs | pep-0484.txt:2165 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | legacy | type-hints/legacy_10.py | def f():
'''Docstring'''
# type: () -> None # Error!
def g():
'''Docstring'''
# # type: () -> None # This is OK
| pydocs | pep-0484.txt:2171 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_63.py | class Node:
"""Binary tree node."""
def __init__(self, left: Node, right: Node):
self.left = left
self.right = right
| pydocs | pep-0484.txt:2314 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | type-hints | 484 | 3.5 | modern | type-hints/modern_64.py | from __future__ import annotations
class ImSet:
def add(self, a: ImSet) -> List[ImSet]: ...
assert ImSet.add.__annotations__ == {'a': 'ImSet', 'return': 'List[ImSet]'}
| pydocs | pep-0484.txt:2340 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | numeric-underscores | 515 | 3.6 | modern | numeric-underscores/modern_01.py | # grouping decimal numbers by thousands
amount = 10_000_000.0
# grouping hexadecimal addresses by words
addr = 0xCAFE_F00D
# grouping bits into nibbles in a binary literal
flags = 0b_0011_1111_0100_1110
# same, for string conversions
flags = int('0b_1111_0000', 2)
| pydocs | pep-0515.txt:27 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | legacy | variable-annotations/legacy_01.py | # 'primes' is a list of integers
primes = [] # type: List[int]
# 'captain' is a string (Note: initial value is a problem)
captain = ... # type: str
class Starship:
# 'stats' is a class variable
stats = {} # type: Dict[str, int]
| pydocs | pep-0526.txt:43 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_01.py | primes: List[int] = []
captain: str # Note: no initial value!
class Starship:
stats: ClassVar[Dict[str, int]] = {}
| pydocs | pep-0526.txt:57 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | legacy | variable-annotations/legacy_02.py | if some_value:
my_var = function() # type: Logger
else:
my_var = another_function() # Why isn't there a type here?
| pydocs | pep-0526.txt:84 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | legacy | variable-annotations/legacy_03.py | path = None # type: Optional[str] # Path to module source
| pydocs | pep-0526.txt:100 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_02.py | my_var: int
my_var = 5 # Passes type check.
other_var: int = 'a' # Flagged as error by type checker,
# but OK at runtime.
| pydocs | pep-0526.txt:139 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_03.py | var = value # type: annotation
var: annotation; var = value
var: annotation = value
| pydocs | pep-0526.txt:147 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_04.py | some_number: int # variable without initial value
some_list: List[int] = [] # variable with initial value
| pydocs | pep-0526.txt:163 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_05.py | sane_world: bool
if 2+2 == 4:
sane_world = True
else:
sane_world = False
| pydocs | pep-0526.txt:169 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_06.py | # Tuple packing with variable annotation syntax
t: Tuple[int, ...] = (1, 2, 3)
# Tuple unpacking with variable annotation syntax
header: str
kind: int
body: Optional[List[str]]
header, kind, body = message
| pydocs | pep-0526.txt:178 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_07.py | a: int
print(a) # raises NameError
| pydocs | pep-0526.txt:189 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_08.py | def f():
a: int
print(a) # raises UnboundLocalError
# Commenting out the a: int makes it a NameError.
| pydocs | pep-0526.txt:195 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_09.py | a: int
a: str # Static type checker may or may not warn about this.
| pydocs | pep-0526.txt:210 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_10.py | class BasicStarship:
captain: str = 'Picard' # instance variable with default
damage: int # instance variable without default
stats: ClassVar[Dict[str, int]] = {} # class variable
| pydocs | pep-0526.txt:223 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_11.py | class Starship:
captain: str = 'Picard'
damage: int
stats: ClassVar[Dict[str, int]] = {}
def __init__(self, damage: int, captain: str = None):
self.damage = damage
if captain:
self.captain = captain # Else keep the default
def hit(self):
Starship.stats['hits'] ... | pydocs | pep-0526.txt:264 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_12.py | from typing import Generic, TypeVar
T = TypeVar('T')
class Box(Generic[T]):
def __init__(self, content):
self.content: T = content
| pydocs | pep-0526.txt:284 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_13.py | class Cls:
pass
c = Cls()
c.x: int = 0 # Annotates c.x with int.
c.y: int # Annotates c.y with int.
d = {}
d['a']: int = 0 # Annotates d['a'] with int.
d['b']: int # Annotates d['b'] with int.
| pydocs | pep-0526.txt:298 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_14.py | (x): int # Annotates x with int, (x) treated as expression by compiler.
(y): int = 0 # Same situation here.
| pydocs | pep-0526.txt:312 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_15.py | a: int
for a in my_iter:
...
f: MyFile
with myfunc() as f:
...
| pydocs | pep-0526.txt:336 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_16.py | # file lib.pyi
ADDRESS: unicode = ...
class Error:
cause: Union[str, unicode]
| pydocs | pep-0526.txt:353 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_17.py | code: int
class Point:
coords: Tuple[int, int]
label: str = '<unknown>'
| pydocs | pep-0526.txt:371 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_18.py | code:int # No space after colon
code : int # Space before colon
class Test:
result: int=0 # No spaces around equality sign
| pydocs | pep-0526.txt:379 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_19.py | def f():
x: NonexistentName # No error.
| pydocs | pep-0526.txt:420 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_20.py | x: NonexistentName # Error!
class X:
var: NonexistentName # Error!
| pydocs | pep-0526.txt:426 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_21.py | from typing import Dict
class Player:
...
players: Dict[str, Player]
__points: int
print(__annotations__)
# prints: {'players': typing.Dict[str, __main__.Player],
# '_Player__points': <class 'int'>}
| pydocs | pep-0526.txt:436 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_22.py | class C:
__annotations__ = 42
x: int = 5 # raises TypeError
| pydocs | pep-0526.txt:453 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_23.py | from typing import Dict, ClassVar, get_type_hints
class Starship:
hitpoints: int = 50
stats: ClassVar[Dict[str, int]] = {}
shield: int = 100
captain: str
def __init__(self, captain: str) -> None:
...
assert get_type_hints(Starship) == {'hitpoints': int,
'... | pydocs | pep-0526.txt:467 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_24.py | alice: 'well done' = 'A+'
bob: 'what a shame' = 'F-'
| pydocs | pep-0526.txt:496 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | variable-annotations | 526 | 3.6 | modern | variable-annotations/modern_25.py | def foo(self):
slef.name: str
| pydocs | pep-0526.txt:656 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | legacy | fstring/legacy_01.py | msg = 'disk failure'
'error: %s' % msg
| pydocs | pep-0498.txt:62 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | legacy | fstring/legacy_02.py | msg = ('disk failure', 32)
'error: %s' % msg
| pydocs | pep-0498.txt:68 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | legacy | fstring/legacy_03.py | 'error: %s' % (msg,)
| pydocs | pep-0498.txt:76 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | legacy | fstring/legacy_04.py | value = 4 * 20
'The value is {value}.'.format(value=value)
| pydocs | pep-0498.txt:90 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | legacy | fstring/legacy_05.py | 'The value is {}.'.format(value)
| pydocs | pep-0498.txt:98 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_02.py | f'The value is {value}.'
| pydocs | pep-0498.txt:103 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_03.py | value = 1234
f'input={value:#06x}'
| pydocs | pep-0498.txt:118 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_05.py | f'{"quoted string"}'
| pydocs | pep-0498.txt:254 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_06.py | f'{{ {4*10} }}'
f'{{{4*10}}}'
| pydocs | pep-0498.txt:263 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_07.py | fr'x={4*10}\n'
| pydocs | pep-0498.txt:271 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_08.py | f"abc {a['x']} def"
| pydocs | pep-0498.txt:281 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_09.py | f'''abc {a['x']} def'''
| pydocs | pep-0498.txt:285 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_10.py | f'abc{expr1:spec1}{expr2!r:spec2}def{expr3}ghi'
| pydocs | pep-0498.txt:297 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_11.py | def foo():
return 20
f'result={foo()}'
| pydocs | pep-0498.txt:317 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_21.py | f'a={d["a"]}'
| pydocs | pep-0498.txt:564 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_22.py | a = 'b'
f'a={d[a]}'
| pydocs | pep-0498.txt:570 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | legacy | fstring/legacy_09.py | '{i[";]}'.format(i={'";':4})
| pydocs | pep-0498.txt:580 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_23.py | header = 'Subject'
fr'{header}:\s+'
| pydocs | pep-0498.txt:600 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_24.py | a = 'some string'
f'{a!r}'
| pydocs | pep-0498.txt:635 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_25.py | f'{repr(a)}'
| pydocs | pep-0498.txt:641 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | fstring | 498 | 3.6 | modern | fstring/modern_26.py | f'{(lambda x: x*2)(3)}'
| pydocs | pep-0498.txt:664 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
train | 3.7 | 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 | 7ef0449603189a7d7f18026972afe733d99b996d | CC0-1.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.