source
stringclasses
2 values
version
stringclasses
2 values
module
stringclasses
53 values
function
stringclasses
318 values
input
stringlengths
3
496
expected
stringlengths
0
876
signature
stringclasses
41 values
cpython
3.10
_pydecimal
Context.to_integral_value
>>> ExtendedContext.to_integral_value(Decimal('10E+5'))
Decimal('1.0E+6')
null
cpython
3.10
_pydecimal
Context.to_integral_value
>>> ExtendedContext.to_integral_value(Decimal('7.89E+77'))
Decimal('7.89E+77')
null
cpython
3.10
_pydecimal
Context.to_integral_value
>>> ExtendedContext.to_integral_value(Decimal('-Inf'))
Decimal('-Infinity')
null
cpython
3.10
_pydecimal
_WorkRep._decimal_lshift_exact
>>> _decimal_lshift_exact(3, 4)
30000
null
cpython
3.10
_pydecimal
_WorkRep._decimal_lshift_exact
>>> _decimal_lshift_exact(300, -999999999) # returns None
null
cpython
3.10
shutil
_GiveupOnFastCopy._basename
>>> os.path.basename('/bar/foo')
'foo'
null
cpython
3.10
shutil
_GiveupOnFastCopy._basename
>>> os.path.basename('/bar/foo/')
''
null
cpython
3.10
shutil
_GiveupOnFastCopy._basename
>>> _basename('/bar/foo/')
'foo'
null
cpython
3.10
json
__module__
>>> import json
null
cpython
3.10
json
__module__
>>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
'["foo", {"bar": ["baz", null, 1.0, 2]}]'
null
cpython
3.10
json
__module__
>>> print(json.dumps("\"foo\bar"))
"\"foo\bar"
null
cpython
3.10
json
__module__
>>> print(json.dumps('\u1234'))
"\u1234"
null
cpython
3.10
json
__module__
>>> print(json.dumps('\\'))
"\\"
null
cpython
3.10
json
__module__
>>> print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True))
{"a": 0, "b": 0, "c": 0}
null
cpython
3.10
json
__module__
>>> from io import StringIO
null
cpython
3.10
json
__module__
>>> io = StringIO()
null
cpython
3.10
json
__module__
>>> json.dump(['streaming API'], io)
null
cpython
3.10
json
__module__
>>> io.getvalue()
'["streaming API"]' Compact encoding::
null
cpython
3.10
json
__module__
>>> import json
null
cpython
3.10
json
__module__
>>> mydict = {'4': 5, '6': 7}
null
cpython
3.10
json
__module__
>>> json.dumps([1,2,3,mydict], separators=(',', ':'))
'[1,2,3,{"4":5,"6":7}]' Pretty printing::
null
cpython
3.10
json
__module__
>>> import json
null
cpython
3.10
json
__module__
>>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4))
{ "4": 5, "6": 7 } Decoding JSON::
null
cpython
3.10
json
__module__
>>> import json
null
cpython
3.10
json
__module__
>>> obj = ['foo', {'bar': ['baz', None, 1.0, 2]}]
null
cpython
3.10
json
__module__
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]') == obj
True
null
cpython
3.10
json
__module__
>>> json.loads('"\\"foo\\bar"') == '"foo\x08ar'
True
null
cpython
3.10
json
__module__
>>> from io import StringIO
null
cpython
3.10
json
__module__
>>> io = StringIO('["streaming API"]')
null
cpython
3.10
json
__module__
>>> json.load(io)[0] == 'streaming API'
True
null
cpython
3.10
json
__module__
>>> import json
null
cpython
3.10
json
__module__
>>> def as_complex(dct): ... if '__complex__' in dct: ... return complex(dct['real'], dct['imag']) ... return dct ...
null
cpython
3.10
json
__module__
>>> json.loads('{"__complex__": true, "real": 1, "imag": 2}', ... object_hook=as_complex)
(1+2j)
null
cpython
3.10
json
__module__
>>> from decimal import Decimal
null
cpython
3.10
json
__module__
>>> json.loads('1.1', parse_float=Decimal) == Decimal('1.1')
True
null
cpython
3.10
json
__module__
>>> import json
null
cpython
3.10
json
__module__
>>> def encode_complex(obj): ... if isinstance(obj, complex): ... return [obj.real, obj.imag] ... raise TypeError(f'Object of type {obj.__class__.__name__} ' ... f'is not JSON serializable') ...
null
cpython
3.10
json
__module__
>>> json.dumps(2 + 1j, default=encode_complex)
'[2.0, 1.0]'
null
cpython
3.10
json
__module__
>>> json.JSONEncoder(default=encode_complex).encode(2 + 1j)
'[2.0, 1.0]'
null
cpython
3.10
json
__module__
>>> ''.join(json.JSONEncoder(default=encode_complex).iterencode(2 + 1j))
'[2.0, 1.0]'
null
cpython
3.10
json.encoder
JSONEncoder.encode
>>> from json.encoder import JSONEncoder
null
cpython
3.10
json.encoder
JSONEncoder.encode
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
null
cpython
3.10
nntplib
__module__
>>> from nntplib import NNTP
null
cpython
3.10
nntplib
__module__
>>> s = NNTP('news')
null
cpython
3.10
nntplib
__module__
>>> resp, count, first, last, name = s.group('comp.lang.python')
null
cpython
3.10
nntplib
__module__
>>> print('Group', name, 'has', count, 'articles, range', first, 'to', last)
null
cpython
3.10
nntplib
__module__
>>> resp, subs = s.xhdr('subject', '{0}-{1}'.format(first, last))
null
cpython
3.10
nntplib
__module__
>>> resp = s.quit()
null
cpython
3.10
nntplib
__module__
>>>
null
cpython
3.10
nntplib
__module__
>>> f = open(filename, 'rb') # file containing article, including header
null
cpython
3.10
nntplib
__module__
>>> resp = s.post(f)
null
cpython
3.10
nntplib
__module__
>>>
null
cpython
3.10
_threading_local
__module__
>>> mydata = local()
null
cpython
3.10
_threading_local
__module__
>>> mydata.number = 42
null
cpython
3.10
_threading_local
__module__
>>> mydata.number
42
null
cpython
3.10
_threading_local
__module__
>>> mydata.__dict__
{'number': 42}
null
cpython
3.10
_threading_local
__module__
>>> mydata.__dict__.setdefault('widgets', [])
[]
null
cpython
3.10
_threading_local
__module__
>>> mydata.widgets
[]
null
cpython
3.10
_threading_local
__module__
>>> log = []
null
cpython
3.10
_threading_local
__module__
>>> def f(): ... items = sorted(mydata.__dict__.items()) ... log.append(items) ... mydata.number = 11 ... log.append(mydata.number)
null
cpython
3.10
_threading_local
__module__
>>> import threading
null
cpython
3.10
_threading_local
__module__
>>> thread = threading.Thread(target=f)
null
cpython
3.10
_threading_local
__module__
>>> thread.start()
null
cpython
3.10
_threading_local
__module__
>>> thread.join()
null
cpython
3.10
_threading_local
__module__
>>> log
[[], 11] we get different data. Furthermore, changes made in the other thread don't affect data seen in this thread:
null
cpython
3.10
_threading_local
__module__
>>> mydata.number
42
null
cpython
3.10
_threading_local
__module__
>>> class MyLocal(local): ... number = 2 ... def __init__(self, /, **kw): ... self.__dict__.update(kw) ... def squared(self): ... return self.number ** 2
null
cpython
3.10
_threading_local
__module__
>>> mydata = MyLocal(color='red')
null
cpython
3.10
_threading_local
__module__
>>> mydata.number
2 an initial color:
null
cpython
3.10
_threading_local
__module__
>>> mydata.color
'red'
null
cpython
3.10
_threading_local
__module__
>>> del mydata.color
null
cpython
3.10
_threading_local
__module__
>>> mydata.squared()
4
null
cpython
3.10
_threading_local
__module__
>>> log = []
null
cpython
3.10
_threading_local
__module__
>>> thread = threading.Thread(target=f)
null
cpython
3.10
_threading_local
__module__
>>> thread.start()
null
cpython
3.10
_threading_local
__module__
>>> thread.join()
null
cpython
3.10
_threading_local
__module__
>>> log
[[('color', 'red')], 11] without affecting this thread's data:
null
cpython
3.10
_threading_local
__module__
>>> mydata.number
2
null
cpython
3.10
_threading_local
__module__
>>> mydata.color
Traceback (most recent call last): ... AttributeError: 'MyLocal' object has no attribute 'color'
null
cpython
3.10
_threading_local
__module__
>>> class MyLocal(local): ... __slots__ = 'number'
null
cpython
3.10
_threading_local
__module__
>>> mydata = MyLocal()
null
cpython
3.10
_threading_local
__module__
>>> mydata.number = 42
null
cpython
3.10
_threading_local
__module__
>>> mydata.color = 'red'
null
cpython
3.10
_threading_local
__module__
>>> thread = threading.Thread(target=f)
null
cpython
3.10
_threading_local
__module__
>>> thread.start()
null
cpython
3.10
_threading_local
__module__
>>> thread.join()
affects what we see:
null
cpython
3.10
_threading_local
__module__
>>> mydata.number
11
null
cpython
3.10
_threading_local
__module__
>>> del mydata
null
cpython
3.10
textwrap
TextWrapper.shorten
>>> textwrap.shorten("Hello world!", width=12)
'Hello world!'
null
cpython
3.10
textwrap
TextWrapper.shorten
>>> textwrap.shorten("Hello world!", width=11)
'Hello [...]'
null
cpython
3.10
turtle
TurtleScreenBase._pointlist
>>> from turtle import *
null
cpython
3.10
turtle
TurtleScreenBase._pointlist
>>> getscreen()._pointlist(getturtle().turtle._item)
[(0.0, 9.9999999999999982), (0.0, -9.9999999999999982), (9.9999999999999982, 0.0)]
null
cpython
3.10
turtle
TurtleScreenBase._pointlist
>>>
null
cpython
3.10
turtle
TurtleScreenBase.mainloop
>>> screen.mainloop()
null
cpython
3.10
turtle
TurtleScreenBase.textinput
>>> screen.textinput("NIM", "Name of first player:")
null
cpython
3.10
turtle
TurtleScreenBase.numinput
>>> screen.numinput("Poker", "Your stakes:", 1000, minval=10, maxval=10000)
null
cpython
3.10
turtle
Shape.addcomponent
>>> poly = ((0,0),(10,-5),(0,10),(-10,-5))
null
cpython
3.10
turtle
Shape.addcomponent
>>> s = Shape("compound")
null
cpython
3.10
turtle
Shape.addcomponent
>>> s.addcomponent(poly, "red", "blue")
null
cpython
3.10
turtle
Shape.addcomponent
>>> # .. add more components and then use register_shape()
null