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 | doctest | DocTestCase.debug | >>> case = DocTestCase(test) | null | |
cpython | 3.10 | doctest | DocTestCase.debug | >>> try:
... case.debug()
... except UnexpectedException as f:
... failure = f | null | |
cpython | 3.10 | doctest | DocTestCase.debug | >>> failure.test is test | True | null |
cpython | 3.10 | doctest | DocTestCase.debug | >>> failure.example.want | '42\n' | null |
cpython | 3.10 | doctest | DocTestCase.debug | >>> exc_info = failure.exc_info | null | |
cpython | 3.10 | doctest | DocTestCase.debug | >>> raise exc_info[1] # Already has the traceback | Traceback (most recent call last):
...
KeyError | null |
cpython | 3.10 | doctest | DocTestCase.debug | >>> test = DocTestParser().get_doctest('''
... >>> x = 1
... >>> x
... 2
... ''', {}, 'foo', 'foo.py', 0) | null | |
cpython | 3.10 | doctest | DocTestCase.debug | >>> case = DocTestCase(test) | null | |
cpython | 3.10 | doctest | DocTestCase.debug | >>> try:
... case.debug()
... except DocTestFailure as f:
... failure = f | null | |
cpython | 3.10 | doctest | DocTestCase.debug | >>> failure.test is test | True | null |
cpython | 3.10 | doctest | DocTestCase.debug | >>> failure.example.want | '2\n'
and the actual output: | null |
cpython | 3.10 | doctest | DocTestCase.debug | >>> failure.got | '1\n' | null |
cpython | 3.10 | doctest | DocFileCase.script_from_examples | >>> text = '''
... Here are examples of simple math.
...
... Python has super accurate integer addition
...
... >>> 2 + 2
... 5
...
... And very friendly error messages:
...
... >>> 1/0
... To Infinity
... And
... Beyond
...
... You can use logic if you want:
...
... >>> if 0:
... ... blah
... ... blah
... ...
...
... Ho hum
... ''' | null | |
cpython | 3.10 | doctest | DocFileCase.script_from_examples | >>> print(script_from_examples(text)) | # Here are examples of simple math.
#
# Python has super accurate integer addition
#
2 + 2
# Expected:
## 5
#
# And very friendly error messages:
#
1/0
# Expected:
## To Infinity
## And
## Beyond
#
# You can use logic if you want:
#
if 0:
blah
blah
#
# Ho hum
<BLANKLINE> | null |
cpython | 3.10 | doctest | _TestClass | >>> _TestClass(13).get() + _TestClass(-12).get() | 1 | null |
cpython | 3.10 | doctest | _TestClass | >>> hex(_TestClass(13).square().get()) | '0xa9' | null |
cpython | 3.10 | doctest | _TestClass.__init__ | >>> t = _TestClass(123) | null | |
cpython | 3.10 | doctest | _TestClass.__init__ | >>> print(t.get()) | 123 | null |
cpython | 3.10 | doctest | _TestClass.square | >>> _TestClass(13).square().get() | 169 | null |
cpython | 3.10 | doctest | _TestClass.get | >>> x = _TestClass(-42) | null | |
cpython | 3.10 | doctest | _TestClass.get | >>> print(x.get()) | -42 | null |
cpython | 3.10 | doctest | _TestClass.get | >>> x = 1; y = 2 | null | |
cpython | 3.10 | doctest | _TestClass.get | >>> x + y, x * y | (3, 2) | null |
cpython | 3.10 | doctest | _TestClass.get | >>> 4 == 4 | 1 | null |
cpython | 3.10 | doctest | _TestClass.get | >>> 4 == 4 | True | null |
cpython | 3.10 | doctest | _TestClass.get | >>> 4 > 4 | 0 | null |
cpython | 3.10 | doctest | _TestClass.get | >>> 4 > 4 | False | null |
cpython | 3.10 | doctest | _TestClass.get | >>> print('foo\n\nbar\n') | foo
<BLANKLINE>
bar
<BLANKLINE> | null |
cpython | 3.10 | doctest | _TestClass.get | >>> print(list(range(1000))) #doctest: +ELLIPSIS | [0, 1, 2, ..., 999] | null |
cpython | 3.10 | doctest | _TestClass.get | >>> print(list(range(30))) #doctest: +NORMALIZE_WHITESPACE | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29] | null |
cpython | 3.10 | poplib | POP3.capa | >>> c=poplib.POP3('localhost') | null | |
cpython | 3.10 | poplib | POP3.capa | >>> c.capa() | {'IMPLEMENTATION': ['Cyrus', 'POP3', 'server', 'v2.2.12'],
'TOP': [], 'LOGIN-DELAY': ['0'], 'AUTH-RESP-CODE': [],
'EXPIRE': ['NEVER'], 'USER': [], 'STLS': [], 'PIPELINING': [],
'UIDL': [], 'RESP-CODES': []} | null |
cpython | 3.10 | poplib | POP3.capa | >>> | null | |
cpython | 3.10 | difflib | SequenceMatcher | >>> s = SequenceMatcher(lambda x: x == " ",
... "private Thread currentThread;",
... "private volatile Thread currentThread;") | null | |
cpython | 3.10 | difflib | SequenceMatcher | >>> | .ratio() returns a float in [0, 1], measuring the "similarity" of the
sequences. As a rule of thumb, a .ratio() value over 0.6 means the
sequences are close matches: | null |
cpython | 3.10 | difflib | SequenceMatcher | >>> print(round(s.ratio(), 3)) | 0.866 | null |
cpython | 3.10 | difflib | SequenceMatcher | >>> | null | |
cpython | 3.10 | difflib | SequenceMatcher | >>> for block in s.get_matching_blocks():
... print("a[%d] and b[%d] match for %d elements" % block) | a[0] and b[0] match for 8 elements
a[8] and b[17] match for 21 elements
a[29] and b[38] match for 0 elements | null |
cpython | 3.10 | difflib | SequenceMatcher | >>> for opcode in s.get_opcodes():
... print("%6s a[%d:%d] b[%d:%d]" % opcode) | equal a[0:8] b[0:8]
insert a[8:8] b[8:17]
equal a[8:29] b[17:38] | null |
cpython | 3.10 | difflib | SequenceMatcher.set_seqs | >>> s = SequenceMatcher() | null | |
cpython | 3.10 | difflib | SequenceMatcher.set_seqs | >>> s.set_seqs("abcd", "bcde") | null | |
cpython | 3.10 | difflib | SequenceMatcher.set_seqs | >>> s.ratio() | 0.75 | null |
cpython | 3.10 | difflib | SequenceMatcher.set_seq1 | >>> s = SequenceMatcher(None, "abcd", "bcde") | null | |
cpython | 3.10 | difflib | SequenceMatcher.set_seq1 | >>> s.ratio() | 0.75 | null |
cpython | 3.10 | difflib | SequenceMatcher.set_seq1 | >>> s.set_seq1("bcde") | null | |
cpython | 3.10 | difflib | SequenceMatcher.set_seq1 | >>> s.ratio() | 1.0 | null |
cpython | 3.10 | difflib | SequenceMatcher.set_seq1 | >>> | null | |
cpython | 3.10 | difflib | SequenceMatcher.set_seq2 | >>> s = SequenceMatcher(None, "abcd", "bcde") | null | |
cpython | 3.10 | difflib | SequenceMatcher.set_seq2 | >>> s.ratio() | 0.75 | null |
cpython | 3.10 | difflib | SequenceMatcher.set_seq2 | >>> s.set_seq2("abcd") | null | |
cpython | 3.10 | difflib | SequenceMatcher.set_seq2 | >>> s.ratio() | 1.0 | null |
cpython | 3.10 | difflib | SequenceMatcher.set_seq2 | >>> | null | |
cpython | 3.10 | difflib | SequenceMatcher.find_longest_match | >>> s = SequenceMatcher(None, " abcd", "abcd abcd") | null | |
cpython | 3.10 | difflib | SequenceMatcher.find_longest_match | >>> s.find_longest_match(0, 5, 0, 9) | null | |
cpython | 3.10 | difflib | SequenceMatcher.find_longest_match | >>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd") | null | |
cpython | 3.10 | difflib | SequenceMatcher.find_longest_match | >>> s.find_longest_match(0, 5, 0, 9) | null | |
cpython | 3.10 | difflib | SequenceMatcher.find_longest_match | >>> s = SequenceMatcher(None, "ab", "c") | null | |
cpython | 3.10 | difflib | SequenceMatcher.find_longest_match | >>> s.find_longest_match(0, 2, 0, 1) | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_matching_blocks | >>> s = SequenceMatcher(None, "abxcd", "abcd") | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_matching_blocks | >>> list(s.get_matching_blocks()) | [Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)] | null |
cpython | 3.10 | difflib | SequenceMatcher.get_opcodes | >>> a = "qabxcd" | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_opcodes | >>> b = "abycdf" | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_opcodes | >>> s = SequenceMatcher(None, a, b) | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_opcodes | >>> for tag, i1, i2, j1, j2 in s.get_opcodes():
... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2]))) | delete a[0:1] (q) b[0:0] ()
equal a[1:3] (ab) b[0:2] (ab)
replace a[3:4] (x) b[2:3] (y)
equal a[4:6] (cd) b[3:5] (cd)
insert a[6:6] () b[5:6] (f) | null |
cpython | 3.10 | difflib | SequenceMatcher.get_grouped_opcodes | >>> from pprint import pprint | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_grouped_opcodes | >>> a = list(map(str, range(1,40))) | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_grouped_opcodes | >>> b = a[:] | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_grouped_opcodes | >>> b[8:8] = ['i'] # Make an insertion | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_grouped_opcodes | >>> b[20] += 'x' # Make a replacement | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_grouped_opcodes | >>> b[23:28] = [] # Make a deletion | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_grouped_opcodes | >>> b[30] += 'y' # Make another replacement | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_grouped_opcodes | >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes())) | [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
[('equal', 16, 19, 17, 20),
('replace', 19, 20, 20, 21),
('equal', 20, 22, 21, 23),
('delete', 22, 27, 23, 23),
('equal', 27, 30, 23, 26)],
[('equal', 31, 34, 27, 30),
('replace', 34, 35, 30, 31),
('equal', 35, 38, 31, 34)]] | null |
cpython | 3.10 | difflib | SequenceMatcher.ratio | >>> s = SequenceMatcher(None, "abcd", "bcde") | null | |
cpython | 3.10 | difflib | SequenceMatcher.ratio | >>> s.ratio() | 0.75 | null |
cpython | 3.10 | difflib | SequenceMatcher.ratio | >>> s.quick_ratio() | 0.75 | null |
cpython | 3.10 | difflib | SequenceMatcher.ratio | >>> s.real_quick_ratio() | 1.0 | null |
cpython | 3.10 | difflib | SequenceMatcher.get_close_matches | >>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"]) | ['apple', 'ape'] | null |
cpython | 3.10 | difflib | SequenceMatcher.get_close_matches | >>> import keyword as _keyword | null | |
cpython | 3.10 | difflib | SequenceMatcher.get_close_matches | >>> get_close_matches("wheel", _keyword.kwlist) | ['while'] | null |
cpython | 3.10 | difflib | SequenceMatcher.get_close_matches | >>> get_close_matches("Apple", _keyword.kwlist) | [] | null |
cpython | 3.10 | difflib | SequenceMatcher.get_close_matches | >>> get_close_matches("accept", _keyword.kwlist) | ['except'] | null |
cpython | 3.10 | difflib | Differ | >>> text1 = ''' 1. Beautiful is better than ugly.
... 2. Explicit is better than implicit.
... 3. Simple is better than complex.
... 4. Complex is better than complicated.
... '''.splitlines(keepends=True) | null | |
cpython | 3.10 | difflib | Differ | >>> len(text1) | 4 | null |
cpython | 3.10 | difflib | Differ | >>> text1[0][-1] | '\n' | null |
cpython | 3.10 | difflib | Differ | >>> text2 = ''' 1. Beautiful is better than ugly.
... 3. Simple is better than complex.
... 4. Complicated is better than complex.
... 5. Flat is better than nested.
... '''.splitlines(keepends=True) | null | |
cpython | 3.10 | difflib | Differ | >>> d = Differ() | null | |
cpython | 3.10 | difflib | Differ | >>> result = list(d.compare(text1, text2)) | 'result' is a list of strings, so let's pretty-print it: | null |
cpython | 3.10 | difflib | Differ | >>> from pprint import pprint as _pprint | null | |
cpython | 3.10 | difflib | Differ | >>> _pprint(result) | [' 1. Beautiful is better than ugly.\n',
'- 2. Explicit is better than implicit.\n',
'- 3. Simple is better than complex.\n',
'+ 3. Simple is better than complex.\n',
'? ++\n',
'- 4. Complex is better than complicated.\n',
'? ^ ---- ^\n',
'+ 4. Complicated is better than complex.\n',
'? ++++ ^ ^\n',
'+ 5. Flat is better than nested.\n'] | null |
cpython | 3.10 | difflib | Differ | >>> print(''.join(result), end="") | 1. Beautiful is better than ugly.
- 2. Explicit is better than implicit.
- 3. Simple is better than complex.
+ 3. Simple is better than complex.
? ++
- 4. Complex is better than complicated.
? ^ ---- ^
+ 4. Complicated is better than complex.
? ++++ ^ ^
+ 5. Flat is better than nested. | null |
cpython | 3.10 | difflib | Differ.compare | >>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True),
... 'ore\ntree\nemu\n'.splitlines(True))),
... end="") | - one
? ^
+ ore
? ^
- two
- three
? -
+ tree
+ emu | null |
cpython | 3.10 | difflib | Differ._fancy_replace | >>> d = Differ() | null | |
cpython | 3.10 | difflib | Differ._fancy_replace | >>> results = d._fancy_replace(['abcDefghiJkl\n'], 0, 1,
... ['abcdefGhijkl\n'], 0, 1) | null | |
cpython | 3.10 | difflib | Differ._fancy_replace | >>> print(''.join(results), end="") | - abcDefghiJkl
? ^ ^ ^
+ abcdefGhijkl
? ^ ^ ^ | null |
cpython | 3.10 | difflib | Differ._qformat | >>> d = Differ() | null | |
cpython | 3.10 | difflib | Differ._qformat | >>> results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n',
... ' ^ ^ ^ ', ' ^ ^ ^ ') | null | |
cpython | 3.10 | difflib | Differ._qformat | >>> for line in results: print(repr(line))
... | '- \tabcDefghiJkl\n'
'? \t ^ ^ ^\n'
'+ \tabcdefGhijkl\n'
'? \t ^ ^ ^\n' | null |
cpython | 3.10 | difflib | Differ.IS_LINE_JUNK | >>> IS_LINE_JUNK('\n') | True | null |
cpython | 3.10 | difflib | Differ.IS_LINE_JUNK | >>> IS_LINE_JUNK(' # \n') | True | null |
cpython | 3.10 | difflib | Differ.IS_LINE_JUNK | >>> IS_LINE_JUNK('hello\n') | False | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.