source
stringclasses
1 value
version
stringclasses
1 value
module
stringclasses
43 values
function
stringclasses
307 values
input
stringlengths
3
496
expected
stringlengths
0
40.5k
signature
stringclasses
0 values
cpython
cfcd524
_pydatetime
date.__repr__
>>> repr(d)
'datetime.date(2010, 1, 1)'
null
cpython
cfcd524
_pydatetime
timezone.__repr__
>>> tz = timezone.utc
null
cpython
cfcd524
_pydatetime
timezone.__repr__
>>> repr(tz)
'datetime.timezone.utc'
null
cpython
cfcd524
_pydatetime
timezone.__repr__
>>> tz = timezone(timedelta(hours=-5), 'EST')
null
cpython
cfcd524
_pydatetime
timezone.__repr__
>>> repr(tz)
"datetime.timezone(datetime.timedelta(-1, 68400), 'EST')"
null
cpython
cfcd524
asyncio.timeouts
Timeout.timeout
>>> async with asyncio.timeout(10): # 10 seconds timeout ... await long_running_task()
delay - value in seconds or None to disable timeout logic long_running_task() is interrupted by raising asyncio.CancelledError, the top-most affected timeout() context manager converts CancelledError into TimeoutError.
null
cpython
cfcd524
asyncio.timeouts
Timeout.timeout_at
>>> async with asyncio.timeout_at(loop.time() + 10): ... await long_running_task()
when - a deadline when timeout occurs or None to disable timeout logic long_running_task() is interrupted by raising asyncio.CancelledError, the top-most affected timeout() context manager converts CancelledError into TimeoutError.
null
cpython
cfcd524
pdb
__module__
>>> import pdb
null
cpython
cfcd524
pdb
__module__
>>> pdb.run('<a statement>')
The debugger's prompt is '(Pdb) '. This will stop in the first function call in <a statement>. Alternatively, if a statement terminated with an unhandled exception, you can use pdb's post-mortem facility to inspect the contents of the traceback:
null
cpython
cfcd524
pdb
__module__
>>> <a statement>
<exception traceback>
null
cpython
cfcd524
pdb
__module__
>>> import pdb
null
cpython
cfcd524
pdb
__module__
>>> pdb.pm()
The commands recognized by the debugger are listed in the next section. Most can be abbreviated as indicated; e.g., h(elp) means that 'help' can be typed as 'h' or 'help' (but not as 'he' or 'hel', nor as 'H' or 'Help' or 'HELP'). Optional arguments are enclosed in square brackets. Alternatives in the command syntax are separated by a vertical bar (|). A blank line repeats the previous command literally, except for 'list', where it lists the next 11 lines. Commands that the debugger doesn't recognize are assumed to be Python statements and are executed in the context of the program being debugged. Python statements can also be prefixed with an exclamation point ('!'). This is a powerful way to inspect the program being debugged; it is even possible to change variables or call functions. When an exception occurs in such a statement, the exception name is printed but the debugger's state is not changed. The debugger supports aliases, which can save typing. And aliases can have parameters (see the alias help entry) which allows one a certain level of adaptability to the context under examination. Multiple commands may be entered on a single line, separated by the pair ';;'. No intelligence is applied to separating the commands; the input is split at the first ';;', even if it is in the middle of a quoted string. If a file ".pdbrc" exists in your home directory or in the current directory, it is read in and executed as if it had been typed at the debugger prompt. This is particularly useful for aliases. If both files exist, the one in the home directory is read first and aliases defined there can be overridden by the local file. This behavior can be disabled by passing the "readrc=False" argument to the Pdb constructor. Aside from aliases, the debugger is not directly programmable; but it is implemented as a class from which you can derive your own debugger class, which you can make as fancy as you like. Debugger commands =================
null
cpython
cfcd524
_pyrepl.utils
ColorSpan.disp_str
>>> utils.disp_str("a = 9")
(['a', ' ', '=', ' ', '9'], [1, 1, 1, 1, 1])
null
cpython
cfcd524
_pyrepl.utils
ColorSpan.disp_str
>>> line = "while 1:"
null
cpython
cfcd524
_pyrepl.utils
ColorSpan.disp_str
>>> colors = list(utils.gen_colors(line))
null
cpython
cfcd524
_pyrepl.utils
ColorSpan.disp_str
>>> utils.disp_str(line, colors=colors)
(['\x1b[1;34mw', 'h', 'i', 'l', 'e\x1b[0m', ' ', '1', ':'], [1, 1, 1, 1, 1, 1, 1, 1])
null
cpython
cfcd524
unittest.mock
NonCallableMock.configure_mock
>>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
null
cpython
cfcd524
unittest.mock
NonCallableMock.configure_mock
>>> mock.configure_mock(**attrs)
null
cpython
cfcd524
unittest.mock
AsyncMock
>>> mock = AsyncMock()
null
cpython
cfcd524
unittest.mock
AsyncMock
>>> inspect.iscoroutinefunction(mock)
True
null
cpython
cfcd524
unittest.mock
AsyncMock
>>> inspect.isawaitable(mock())
True The result of ``mock()`` is an async function which will have the outcome of ``side_effect`` or ``return_value``: - if ``side_effect`` is a function, the async function will return the result of that function, - if ``side_effect`` is an exception, the async function will raise the exception, - if ``side_effect`` is an iterable, the async function will return the next value of the iterable, however, if the sequence of result is exhausted, ``StopIteration`` is raised immediately, - if ``side_effect`` is not defined, the async function will return the value defined by ``return_value``, hence, by default, the async function returns a new :class:`AsyncMock` object. If the outcome of ``side_effect`` or ``return_value`` is an async function, the mock async function obtained when the mock object is called will be this async function itself (and not an async function returning an async function). The test author can also specify a wrapped object with ``wraps``. In this case, the :class:`Mock` object behavior is the same as with an :class:`.Mock` object: the wrapped object may have methods defined as async function functions. Based on Martin Richard's asynctest project.
null
cpython
cfcd524
ipaddress
NetmaskValueError.summarize_address_range
>>> list(summarize_address_range(IPv4Address('192.0.2.0'), ... IPv4Address('192.0.2.130'))) ... #doctest: +NORMALIZE_WHITESPACE
[IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'), IPv4Network('192.0.2.130/32')] Args: first: the first IPv4Address or IPv6Address in the range. last: the last IPv4Address or IPv6Address in the range. Returns: An iterator of the summarized IPv(4|6) network objects. Raise: TypeError: If the first and last objects are not IP addresses. If the first and last objects are not the same version. ValueError: If the last object is not greater than the first. If the version of the first address is not 4 or 6.
null
cpython
cfcd524
ipaddress
_IPAddressBase.reverse_pointer
>>> ipaddress.ip_address("127.0.0.1").reverse_pointer
'1.0.0.127.in-addr.arpa'
null
cpython
cfcd524
ipaddress
_IPAddressBase.reverse_pointer
>>> ipaddress.ip_address("2001:db8::1").reverse_pointer
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
null
cpython
cfcd524
_pydecimal
FloatOperation.localcontext
>>> setcontext(DefaultContext)
null
cpython
cfcd524
_pydecimal
FloatOperation.localcontext
>>> print(getcontext().prec)
28
null
cpython
cfcd524
_pydecimal
FloatOperation.localcontext
>>> with localcontext(): ... ctx = getcontext() ... ctx.prec += 2 ... print(ctx.prec) ...
30
null
cpython
cfcd524
_pydecimal
FloatOperation.localcontext
>>> with localcontext(ExtendedContext): ... print(getcontext().prec) ...
9
null
cpython
cfcd524
_pydecimal
FloatOperation.localcontext
>>> print(getcontext().prec)
28
null
cpython
cfcd524
_pydecimal
Decimal.__new__
>>> Decimal('3.14') # string input
Decimal('3.14')
null
cpython
cfcd524
_pydecimal
Decimal.__new__
>>> Decimal((0, (3, 1, 4), -2)) # tuple (sign, digit_tuple, exponent)
Decimal('3.14')
null
cpython
cfcd524
_pydecimal
Decimal.__new__
>>> Decimal(314) # int
Decimal('314')
null
cpython
cfcd524
_pydecimal
Decimal.__new__
>>> Decimal(Decimal(314)) # another decimal instance
Decimal('314')
null
cpython
cfcd524
_pydecimal
Decimal.__new__
>>> Decimal(' 3.14 \\n') # leading and trailing whitespace okay
Decimal('3.14')
null
cpython
cfcd524
_pydecimal
Decimal.from_number
>>> Decimal.from_number(314) # int
Decimal('314')
null
cpython
cfcd524
_pydecimal
Decimal.from_number
>>> Decimal.from_number(0.1) # float
Decimal('0.1000000000000000055511151231257827021181583404541015625')
null
cpython
cfcd524
_pydecimal
Decimal.from_number
>>> Decimal.from_number(Decimal('3.14')) # another decimal instance
Decimal('3.14')
null
cpython
cfcd524
_pydecimal
Decimal.from_float
>>> Decimal.from_float(0.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')
null
cpython
cfcd524
_pydecimal
Decimal.from_float
>>> Decimal.from_float(float('nan'))
Decimal('NaN')
null
cpython
cfcd524
_pydecimal
Decimal.from_float
>>> Decimal.from_float(float('inf'))
Decimal('Infinity')
null
cpython
cfcd524
_pydecimal
Decimal.from_float
>>> Decimal.from_float(-float('inf'))
Decimal('-Infinity')
null
cpython
cfcd524
_pydecimal
Decimal.from_float
>>> Decimal.from_float(-0.0)
Decimal('-0')
null
cpython
cfcd524
_pydecimal
Decimal.as_integer_ratio
>>> Decimal('3.14').as_integer_ratio()
(157, 50)
null
cpython
cfcd524
_pydecimal
Decimal.as_integer_ratio
>>> Decimal('-123e5').as_integer_ratio()
(-12300000, 1)
null
cpython
cfcd524
_pydecimal
Decimal.as_integer_ratio
>>> Decimal('0.00').as_integer_ratio()
(0, 1)
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('123.456'))
123
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('-456.789'))
-457
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('-3.0'))
-3
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('2.5'))
2
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('3.5'))
4
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('Inf'))
Traceback (most recent call last): ... OverflowError: cannot round an infinity
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('NaN'))
Traceback (most recent call last): ... ValueError: cannot round a NaN If a second argument n is supplied, self is rounded to n decimal places using the rounding mode for the current context. For an integer n, round(self, -n) is exactly equivalent to self.quantize(Decimal('1En')).
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('123.456'), 0)
Decimal('123')
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('123.456'), 2)
Decimal('123.46')
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('123.456'), -2)
Decimal('1E+2')
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('-Infinity'), 37)
Decimal('NaN')
null
cpython
cfcd524
_pydecimal
Decimal.__round__
>>> round(Decimal('sNaN123'), 0)
Decimal('NaN123')
null
cpython
cfcd524
_pydecimal
Context.create_decimal_from_float
>>> context = Context(prec=5, rounding=ROUND_DOWN)
null
cpython
cfcd524
_pydecimal
Context.create_decimal_from_float
>>> context.create_decimal_from_float(3.1415926535897932)
Decimal('3.1415')
null
cpython
cfcd524
_pydecimal
Context.create_decimal_from_float
>>> context = Context(prec=5, traps=[Inexact])
null
cpython
cfcd524
_pydecimal
Context.create_decimal_from_float
>>> context.create_decimal_from_float(3.1415926535897932)
Traceback (most recent call last): ... decimal.Inexact: None
null
cpython
cfcd524
_pydecimal
Context.abs
>>> ExtendedContext.abs(Decimal('2.1'))
Decimal('2.1')
null
cpython
cfcd524
_pydecimal
Context.abs
>>> ExtendedContext.abs(Decimal('-100'))
Decimal('100')
null
cpython
cfcd524
_pydecimal
Context.abs
>>> ExtendedContext.abs(Decimal('101.5'))
Decimal('101.5')
null
cpython
cfcd524
_pydecimal
Context.abs
>>> ExtendedContext.abs(Decimal('-101.5'))
Decimal('101.5')
null
cpython
cfcd524
_pydecimal
Context.abs
>>> ExtendedContext.abs(-1)
Decimal('1')
null
cpython
cfcd524
_pydecimal
Context.add
>>> ExtendedContext.add(Decimal('12'), Decimal('7.00'))
Decimal('19.00')
null
cpython
cfcd524
_pydecimal
Context.add
>>> ExtendedContext.add(Decimal('1E+2'), Decimal('1.01E+4'))
Decimal('1.02E+4')
null
cpython
cfcd524
_pydecimal
Context.add
>>> ExtendedContext.add(1, Decimal(2))
Decimal('3')
null
cpython
cfcd524
_pydecimal
Context.add
>>> ExtendedContext.add(Decimal(8), 5)
Decimal('13')
null
cpython
cfcd524
_pydecimal
Context.add
>>> ExtendedContext.add(5, 5)
Decimal('10')
null
cpython
cfcd524
_pydecimal
Context.canonical
>>> ExtendedContext.canonical(Decimal('2.50'))
Decimal('2.50')
null
cpython
cfcd524
_pydecimal
Context.compare
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('3'))
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.1'))
Decimal('0')
null
cpython
cfcd524
_pydecimal
Context.compare
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.10'))
Decimal('0')
null
cpython
cfcd524
_pydecimal
Context.compare
>>> ExtendedContext.compare(Decimal('3'), Decimal('2.1'))
Decimal('1')
null
cpython
cfcd524
_pydecimal
Context.compare
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('-3'))
Decimal('1')
null
cpython
cfcd524
_pydecimal
Context.compare
>>> ExtendedContext.compare(Decimal('-3'), Decimal('2.1'))
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare
>>> ExtendedContext.compare(1, 2)
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare
>>> ExtendedContext.compare(Decimal(1), 2)
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare
>>> ExtendedContext.compare(1, Decimal(2))
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> c = ExtendedContext
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> c.compare_signal(Decimal('2.1'), Decimal('3'))
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> c.compare_signal(Decimal('2.1'), Decimal('2.1'))
Decimal('0')
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> c.flags[InvalidOperation] = 0
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> print(c.flags[InvalidOperation])
0
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> c.compare_signal(Decimal('NaN'), Decimal('2.1'))
Decimal('NaN')
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> print(c.flags[InvalidOperation])
1
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> c.flags[InvalidOperation] = 0
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> print(c.flags[InvalidOperation])
0
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> c.compare_signal(Decimal('sNaN'), Decimal('2.1'))
Decimal('NaN')
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> print(c.flags[InvalidOperation])
1
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> c.compare_signal(-1, 2)
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> c.compare_signal(Decimal(-1), 2)
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare_signal
>>> c.compare_signal(-1, Decimal(2))
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare_total
>>> ExtendedContext.compare_total(Decimal('12.73'), Decimal('127.9'))
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare_total
>>> ExtendedContext.compare_total(Decimal('-127'), Decimal('12'))
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare_total
>>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.3'))
Decimal('-1')
null
cpython
cfcd524
_pydecimal
Context.compare_total
>>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.30'))
Decimal('0')
null
cpython
cfcd524
_pydecimal
Context.compare_total
>>> ExtendedContext.compare_total(Decimal('12.3'), Decimal('12.300'))
Decimal('1')
null