GeezerVison is showing github.com — bpo-28315: Improve code examples in docs (GH-1372) · python/cpython@8856940
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Doc/extending/newtypes.rst +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -124,7 +124,7 @@ our objects and in some error messages, for example:: | 124 | 124 |
| 125 | 125 | >>> "" + noddy.new_noddy() | 126 | 126 | Traceback (most recent call last): | 127 | | - File "<stdin>", line 1, in ? | | 127 | + File "<stdin>", line 1, in <module> | 128 | 128 | TypeError: cannot add type "noddy.Noddy" to string | 129 | 129 |
| 130 | 130 | Note that the name is a dotted name that includes both the module name and the | |
Collapse file Copy file name to clipboardExpand all lines: Doc/howto/functional.rst +3-3Lines changed: 3 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -210,7 +210,7 @@ You can experiment with the iteration interface manually: | 210 | 210 | 3 | 211 | 211 | >>> next(it) | 212 | 212 | Traceback (most recent call last): | 213 | | - File "<stdin>", line 1, in ? | | 213 | + File "<stdin>", line 1, in <module> | 214 | 214 | StopIteration | 215 | 215 | >>> | 216 | 216 |
| @@ -474,7 +474,7 @@ Here's a sample usage of the ``generate_ints()`` generator: | 474 | 474 | 2 | 475 | 475 | >>> next(gen) | 476 | 476 | Traceback (most recent call last): | 477 | | - File "stdin", line 1, in ? | | 477 | + File "stdin", line 1, in <module> | 478 | 478 | File "stdin", line 2, in generate_ints | 479 | 479 | StopIteration | 480 | 480 |
| @@ -577,7 +577,7 @@ And here's an example of changing the counter: | 577 | 577 | 9 | 578 | 578 | >>> next(it) #doctest: +SKIP | 579 | 579 | Traceback (most recent call last): | 580 | | - File "t.py", line 15, in ? | | 580 | + File "t.py", line 15, in <module> | 581 | 581 | it.next() | 582 | 582 | StopIteration | 583 | 583 |
| |
Collapse file Copy file name to clipboardExpand all lines: Doc/library/ctypes.rst +15-15Lines changed: 15 additions & 15 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -97,7 +97,7 @@ Functions are accessed as attributes of dll objects:: | 97 | 97 | <_FuncPtr object at 0x...> | 98 | 98 | >>> print(windll.kernel32.MyOwnFunction) # doctest: +WINDOWS | 99 | 99 | Traceback (most recent call last): | 100 | | - File "<stdin>", line 1, in ? | | 100 | + File "<stdin>", line 1, in <module> | 101 | 101 | File "ctypes.py", line 239, in __getattr__ | 102 | 102 | func = _StdcallFuncPtr(name, self) | 103 | 103 | AttributeError: function 'MyOwnFunction' not found | @@ -135,7 +135,7 @@ functions can be accessed by indexing the dll object with the ordinal number:: | 135 | 135 | <_FuncPtr object at 0x...> | 136 | 136 | >>> cdll.kernel32[0] # doctest: +WINDOWS | 137 | 137 | Traceback (most recent call last): | 138 | | - File "<stdin>", line 1, in ? | | 138 | + File "<stdin>", line 1, in <module> | 139 | 139 | File "ctypes.py", line 310, in __getitem__ | 140 | 140 | func = _StdcallFuncPtr(name, self) | 141 | 141 | AttributeError: function ordinal 0 not found | @@ -168,11 +168,11 @@ although an error is raised the function *has* been called:: | 168 | 168 |
| 169 | 169 | >>> windll.kernel32.GetModuleHandleA() # doctest: +WINDOWS | 170 | 170 | Traceback (most recent call last): | 171 | | - File "<stdin>", line 1, in ? | | 171 | + File "<stdin>", line 1, in <module> | 172 | 172 | ValueError: Procedure probably called with not enough arguments (4 bytes missing) | 173 | 173 | >>> windll.kernel32.GetModuleHandleA(0, 0) # doctest: +WINDOWS | 174 | 174 | Traceback (most recent call last): | 175 | | - File "<stdin>", line 1, in ? | | 175 | + File "<stdin>", line 1, in <module> | 176 | 176 | ValueError: Procedure probably called with too many arguments (4 bytes in excess) | 177 | 177 | >>> | 178 | 178 |
| @@ -181,13 +181,13 @@ The same exception is raised when you call an ``stdcall`` function with the | 181 | 181 |
| 182 | 182 | >>> cdll.kernel32.GetModuleHandleA(None) # doctest: +WINDOWS | 183 | 183 | Traceback (most recent call last): | 184 | | - File "<stdin>", line 1, in ? | | 184 | + File "<stdin>", line 1, in <module> | 185 | 185 | ValueError: Procedure probably called with not enough arguments (4 bytes missing) | 186 | 186 | >>> | 187 | 187 |
| 188 | 188 | >>> windll.msvcrt.printf(b"spam") # doctest: +WINDOWS | 189 | 189 | Traceback (most recent call last): | 190 | | - File "<stdin>", line 1, in ? | | 190 | + File "<stdin>", line 1, in <module> | 191 | 191 | ValueError: Procedure probably called with too many arguments (4 bytes in excess) | 192 | 192 | >>> | 193 | 193 |
| @@ -200,7 +200,7 @@ argument values:: | 200 | 200 |
| 201 | 201 | >>> windll.kernel32.GetModuleHandleA(32) # doctest: +WINDOWS | 202 | 202 | Traceback (most recent call last): | 203 | | - File "<stdin>", line 1, in ? | | 203 | + File "<stdin>", line 1, in <module> | 204 | 204 | OSError: exception: access violation reading 0x00000020 | 205 | 205 | >>> | 206 | 206 |
| @@ -373,7 +373,7 @@ from within *IDLE* or *PythonWin*:: | 373 | 373 | 19 | 374 | 374 | >>> printf(b"%f bottles of beer\n", 42.5) | 375 | 375 | Traceback (most recent call last): | 376 | | - File "<stdin>", line 1, in ? | | 376 | + File "<stdin>", line 1, in <module> | 377 | 377 | ArgumentError: argument 2: exceptions.TypeError: Don't know how to convert parameter 2 | 378 | 378 | >>> | 379 | 379 |
| @@ -436,7 +436,7 @@ prototype for a C function), and tries to convert the arguments to valid types:: | 436 | 436 |
| 437 | 437 | >>> printf(b"%d %d %d", 1, 2, 3) | 438 | 438 | Traceback (most recent call last): | 439 | | - File "<stdin>", line 1, in ? | | 439 | + File "<stdin>", line 1, in <module> | 440 | 440 | ArgumentError: argument 2: exceptions.TypeError: wrong type | 441 | 441 | >>> printf(b"%s %d %f\n", b"X", 2, 3) | 442 | 442 | X 2 3.000000 | @@ -486,7 +486,7 @@ single character Python bytes object into a C char:: | 486 | 486 | 'def' | 487 | 487 | >>> strchr(b"abcdef", b"def") | 488 | 488 | Traceback (most recent call last): | 489 | | - File "<stdin>", line 1, in ? | | 489 | + File "<stdin>", line 1, in <module> | 490 | 490 | ArgumentError: argument 2: exceptions.TypeError: one character string expected | 491 | 491 | >>> print(strchr(b"abcdef", b"x")) | 492 | 492 | None | @@ -512,7 +512,7 @@ useful to check for error return values and automatically raise an exception:: | 512 | 512 | 486539264 | 513 | 513 | >>> GetModuleHandle("something silly") # doctest: +WINDOWS | 514 | 514 | Traceback (most recent call last): | 515 | | - File "<stdin>", line 1, in ? | | 515 | + File "<stdin>", line 1, in <module> | 516 | 516 | File "<stdin>", line 3, in ValidHandle | 517 | 517 | OSError: [Errno 126] The specified module could not be found. | 518 | 518 | >>> | @@ -583,7 +583,7 @@ Here is a simple example of a POINT structure, which contains two integers named | 583 | 583 | 0 5 | 584 | 584 | >>> POINT(1, 2, 3) | 585 | 585 | Traceback (most recent call last): | 586 | | - File "<stdin>", line 1, in ? | | 586 | + File "<stdin>", line 1, in <module> | 587 | 587 | ValueError: too many initializers | 588 | 588 | >>> | 589 | 589 |
| @@ -786,7 +786,7 @@ new type:: | 786 | 786 | <class 'ctypes.LP_c_long'> | 787 | 787 | >>> PI(42) | 788 | 788 | Traceback (most recent call last): | 789 | | - File "<stdin>", line 1, in ? | | 789 | + File "<stdin>", line 1, in <module> | 790 | 790 | TypeError: expected c_long instead of int | 791 | 791 | >>> PI(c_int(42)) | 792 | 792 | <ctypes.LP_c_long object at 0x...> | @@ -862,7 +862,7 @@ but not instances of other types:: | 862 | 862 |
| 863 | 863 | >>> bar.values = (c_byte * 4)() | 864 | 864 | Traceback (most recent call last): | 865 | | - File "<stdin>", line 1, in ? | | 865 | + File "<stdin>", line 1, in <module> | 866 | 866 | TypeError: incompatible types, c_byte_Array_4 instance instead of LP_c_long instance | 867 | 867 | >>> | 868 | 868 |
| @@ -913,7 +913,7 @@ work:: | 913 | 913 | ... ("next", POINTER(cell))] | 914 | 914 | ... | 915 | 915 | Traceback (most recent call last): | 916 | | - File "<stdin>", line 1, in ? | | 916 | + File "<stdin>", line 1, in <module> | 917 | 917 | File "<stdin>", line 2, in cell | 918 | 918 | NameError: name 'cell' is not defined | 919 | 919 | >>> | |
Collapse file Copy file name to clipboardExpand all lines: Doc/library/doctest.rst +3-3Lines changed: 3 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -408,7 +408,7 @@ Simple example:: | 408 | 408 |
| 409 | 409 | >>> [1, 2, 3].remove(42) | 410 | 410 | Traceback (most recent call last): | 411 | | - File "<stdin>", line 1, in ? | | 411 | + File "<stdin>", line 1, in <module> | 412 | 412 | ValueError: list.remove(x): x not in list | 413 | 413 |
| 414 | 414 | That doctest succeeds if :exc:`ValueError` is raised, with the ``list.remove(x): | @@ -432,7 +432,7 @@ multi-line detail:: | 432 | 432 |
| 433 | 433 | >>> raise ValueError('multi\n line\ndetail') | 434 | 434 | Traceback (most recent call last): | 435 | | - File "<stdin>", line 1, in ? | | 435 | + File "<stdin>", line 1, in <module> | 436 | 436 | ValueError: multi | 437 | 437 | line | 438 | 438 | detail | @@ -591,7 +591,7 @@ doctest decides whether actual output matches an example's expected output: | 591 | 591 |
| 592 | 592 | >>> (1, 2)[3] = 'moo' | 593 | 593 | Traceback (most recent call last): | 594 | | - File "<stdin>", line 1, in ? | | 594 | + File "<stdin>", line 1, in <module> | 595 | 595 | TypeError: object doesn't support item assignment | 596 | 596 |
| 597 | 597 | passes under Python 2.3 and later Python versions with the flag specified, | |
Collapse file Copy file name to clipboardExpand all lines: Doc/library/fpectl.rst +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -89,7 +89,7 @@ The following example demonstrates how to start up and test operation of the | 89 | 89 | >>> import math | 90 | 90 | >>> math.exp(1000) | 91 | 91 | Traceback (most recent call last): | 92 | | - File "<stdin>", line 1, in ? | | 92 | + File "<stdin>", line 1, in <module> | 93 | 93 | FloatingPointError: in math_1 | 94 | 94 |
| 95 | 95 |
| |
Collapse file Copy file name to clipboardExpand all lines: Doc/library/pdb.rst +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -76,7 +76,7 @@ The typical usage to inspect a crashed program is:: | 76 | 76 | >>> import mymodule | 77 | 77 | >>> mymodule.test() | 78 | 78 | Traceback (most recent call last): | 79 | | - File "<stdin>", line 1, in ? | | 79 | + File "<stdin>", line 1, in <module> | 80 | 80 | File "./mymodule.py", line 4, in test | 81 | 81 | test2() | 82 | 82 | File "./mymodule.py", line 3, in test2 | |
Collapse file Copy file name to clipboardExpand all lines: Doc/library/unicodedata.rst +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -158,7 +158,7 @@ Examples: | 158 | 158 | 9 | 159 | 159 | >>> unicodedata.decimal('a') | 160 | 160 | Traceback (most recent call last): | 161 | | - File "<stdin>", line 1, in ? | | 161 | + File "<stdin>", line 1, in <module> | 162 | 162 | ValueError: not a decimal | 163 | 163 | >>> unicodedata.category('A') # 'L'etter, 'u'ppercase | 164 | 164 | 'Lu' | |
Collapse file Copy file name to clipboardExpand all lines: Doc/reference/expressions.rst +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -905,7 +905,7 @@ keyword arguments (and any ``**expression`` arguments -- see below). So:: | 905 | 905 | 2 1 | 906 | 906 | >>> f(a=1, *(2,)) | 907 | 907 | Traceback (most recent call last): | 908 | | - File "<stdin>", line 1, in ? | | 908 | + File "<stdin>", line 1, in <module> | 909 | 909 | TypeError: f() got multiple values for keyword argument 'a' | 910 | 910 | >>> f(1, *(2,)) | 911 | 911 | 1 2 | |
Collapse file Copy file name to clipboardExpand all lines: Doc/tutorial/classes.rst +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -784,7 +784,7 @@ using the :func:`next` built-in function; this example shows how it all works:: | 784 | 784 | 'c' | 785 | 785 | >>> next(it) | 786 | 786 | Traceback (most recent call last): | 787 | | - File "<stdin>", line 1, in ? | | 787 | + File "<stdin>", line 1, in <module> | 788 | 788 | next(it) | 789 | 789 | StopIteration | 790 | 790 |
| |
Collapse file Copy file name to clipboardExpand all lines: Doc/tutorial/controlflow.rst +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -475,7 +475,7 @@ Here's an example that fails due to this restriction:: | 475 | 475 | ... | 476 | 476 | >>> function(0, a=0) | 477 | 477 | Traceback (most recent call last): | 478 | | - File "<stdin>", line 1, in ? | | 478 | + File "<stdin>", line 1, in <module> | 479 | 479 | TypeError: function() got multiple values for keyword argument 'a' | 480 | 480 |
| 481 | 481 | When a final formal parameter of the form ``**name`` is present, it receives a | |
|