Skip to content

Commit 5274faf

Browse files
authored
[3.5] bpo-28315: Improve code examples in docs (GH-1372) (#1446)
Replace File "<stdin>", line 1, in ? with File "<stdin>", line 1, in <module> (cherry picked from commit 8856940)
1 parent 4b15e45 commit 5274faf

File tree

12 files changed

+30
-30
lines changed

12 files changed

+30
-30
lines changed

Doc/extending/newtypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ our objects and in some error messages, for example::
124124

125125
>>> "" + noddy.new_noddy()
126126
Traceback (most recent call last):
127-
File "<stdin>", line 1, in ?
127+
File "<stdin>", line 1, in <module>
128128
TypeError: cannot add type "noddy.Noddy" to string
129129

130130
Note that the name is a dotted name that includes both the module name and the

Doc/howto/functional.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ You can experiment with the iteration interface manually:
210210
3
211211
>>> next(it)
212212
Traceback (most recent call last):
213-
File "<stdin>", line 1, in ?
213+
File "<stdin>", line 1, in <module>
214214
StopIteration
215215
>>>
216216

@@ -474,7 +474,7 @@ Here's a sample usage of the ``generate_ints()`` generator:
474474
2
475475
>>> next(gen)
476476
Traceback (most recent call last):
477-
File "stdin", line 1, in ?
477+
File "stdin", line 1, in <module>
478478
File "stdin", line 2, in generate_ints
479479
StopIteration
480480

@@ -577,7 +577,7 @@ And here's an example of changing the counter:
577577
9
578578
>>> next(it) #doctest: +SKIP
579579
Traceback (most recent call last):
580-
File "t.py", line 15, in ?
580+
File "t.py", line 15, in <module>
581581
it.next()
582582
StopIteration
583583

Doc/library/ctypes.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Functions are accessed as attributes of dll objects::
9797
<_FuncPtr object at 0x...>
9898
>>> print(windll.kernel32.MyOwnFunction) # doctest: +WINDOWS
9999
Traceback (most recent call last):
100-
File "<stdin>", line 1, in ?
100+
File "<stdin>", line 1, in <module>
101101
File "ctypes.py", line 239, in __getattr__
102102
func = _StdcallFuncPtr(name, self)
103103
AttributeError: function 'MyOwnFunction' not found
@@ -135,7 +135,7 @@ functions can be accessed by indexing the dll object with the ordinal number::
135135
<_FuncPtr object at 0x...>
136136
>>> cdll.kernel32[0] # doctest: +WINDOWS
137137
Traceback (most recent call last):
138-
File "<stdin>", line 1, in ?
138+
File "<stdin>", line 1, in <module>
139139
File "ctypes.py", line 310, in __getitem__
140140
func = _StdcallFuncPtr(name, self)
141141
AttributeError: function ordinal 0 not found
@@ -168,11 +168,11 @@ although an error is raised the function *has* been called::
168168

169169
>>> windll.kernel32.GetModuleHandleA() # doctest: +WINDOWS
170170
Traceback (most recent call last):
171-
File "<stdin>", line 1, in ?
171+
File "<stdin>", line 1, in <module>
172172
ValueError: Procedure probably called with not enough arguments (4 bytes missing)
173173
>>> windll.kernel32.GetModuleHandleA(0, 0) # doctest: +WINDOWS
174174
Traceback (most recent call last):
175-
File "<stdin>", line 1, in ?
175+
File "<stdin>", line 1, in <module>
176176
ValueError: Procedure probably called with too many arguments (4 bytes in excess)
177177
>>>
178178

@@ -181,13 +181,13 @@ The same exception is raised when you call an ``stdcall`` function with the
181181

182182
>>> cdll.kernel32.GetModuleHandleA(None) # doctest: +WINDOWS
183183
Traceback (most recent call last):
184-
File "<stdin>", line 1, in ?
184+
File "<stdin>", line 1, in <module>
185185
ValueError: Procedure probably called with not enough arguments (4 bytes missing)
186186
>>>
187187

188188
>>> windll.msvcrt.printf(b"spam") # doctest: +WINDOWS
189189
Traceback (most recent call last):
190-
File "<stdin>", line 1, in ?
190+
File "<stdin>", line 1, in <module>
191191
ValueError: Procedure probably called with too many arguments (4 bytes in excess)
192192
>>>
193193

@@ -200,7 +200,7 @@ argument values::
200200

201201
>>> windll.kernel32.GetModuleHandleA(32) # doctest: +WINDOWS
202202
Traceback (most recent call last):
203-
File "<stdin>", line 1, in ?
203+
File "<stdin>", line 1, in <module>
204204
OSError: exception: access violation reading 0x00000020
205205
>>>
206206

@@ -373,7 +373,7 @@ from within *IDLE* or *PythonWin*::
373373
19
374374
>>> printf(b"%f bottles of beer\n", 42.5)
375375
Traceback (most recent call last):
376-
File "<stdin>", line 1, in ?
376+
File "<stdin>", line 1, in <module>
377377
ArgumentError: argument 2: exceptions.TypeError: Don't know how to convert parameter 2
378378
>>>
379379

@@ -436,7 +436,7 @@ prototype for a C function), and tries to convert the arguments to valid types::
436436

437437
>>> printf(b"%d %d %d", 1, 2, 3)
438438
Traceback (most recent call last):
439-
File "<stdin>", line 1, in ?
439+
File "<stdin>", line 1, in <module>
440440
ArgumentError: argument 2: exceptions.TypeError: wrong type
441441
>>> printf(b"%s %d %f\n", b"X", 2, 3)
442442
X 2 3.000000
@@ -486,7 +486,7 @@ single character Python bytes object into a C char::
486486
'def'
487487
>>> strchr(b"abcdef", b"def")
488488
Traceback (most recent call last):
489-
File "<stdin>", line 1, in ?
489+
File "<stdin>", line 1, in <module>
490490
ArgumentError: argument 2: exceptions.TypeError: one character string expected
491491
>>> print(strchr(b"abcdef", b"x"))
492492
None
@@ -512,7 +512,7 @@ useful to check for error return values and automatically raise an exception::
512512
486539264
513513
>>> GetModuleHandle("something silly") # doctest: +WINDOWS
514514
Traceback (most recent call last):
515-
File "<stdin>", line 1, in ?
515+
File "<stdin>", line 1, in <module>
516516
File "<stdin>", line 3, in ValidHandle
517517
OSError: [Errno 126] The specified module could not be found.
518518
>>>
@@ -583,7 +583,7 @@ Here is a simple example of a POINT structure, which contains two integers named
583583
0 5
584584
>>> POINT(1, 2, 3)
585585
Traceback (most recent call last):
586-
File "<stdin>", line 1, in ?
586+
File "<stdin>", line 1, in <module>
587587
ValueError: too many initializers
588588
>>>
589589

@@ -786,7 +786,7 @@ new type::
786786
<class 'ctypes.LP_c_long'>
787787
>>> PI(42)
788788
Traceback (most recent call last):
789-
File "<stdin>", line 1, in ?
789+
File "<stdin>", line 1, in <module>
790790
TypeError: expected c_long instead of int
791791
>>> PI(c_int(42))
792792
<ctypes.LP_c_long object at 0x...>
@@ -862,7 +862,7 @@ but not instances of other types::
862862

863863
>>> bar.values = (c_byte * 4)()
864864
Traceback (most recent call last):
865-
File "<stdin>", line 1, in ?
865+
File "<stdin>", line 1, in <module>
866866
TypeError: incompatible types, c_byte_Array_4 instance instead of LP_c_long instance
867867
>>>
868868

@@ -913,7 +913,7 @@ work::
913913
... ("next", POINTER(cell))]
914914
...
915915
Traceback (most recent call last):
916-
File "<stdin>", line 1, in ?
916+
File "<stdin>", line 1, in <module>
917917
File "<stdin>", line 2, in cell
918918
NameError: name 'cell' is not defined
919919
>>>

Doc/library/doctest.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ Simple example::
408408

409409
>>> [1, 2, 3].remove(42)
410410
Traceback (most recent call last):
411-
File "<stdin>", line 1, in ?
411+
File "<stdin>", line 1, in <module>
412412
ValueError: list.remove(x): x not in list
413413

414414
That doctest succeeds if :exc:`ValueError` is raised, with the ``list.remove(x):
@@ -432,7 +432,7 @@ multi-line detail::
432432

433433
>>> raise ValueError('multi\n line\ndetail')
434434
Traceback (most recent call last):
435-
File "<stdin>", line 1, in ?
435+
File "<stdin>", line 1, in <module>
436436
ValueError: multi
437437
line
438438
detail
@@ -591,7 +591,7 @@ doctest decides whether actual output matches an example's expected output:
591591

592592
>>> (1, 2)[3] = 'moo'
593593
Traceback (most recent call last):
594-
File "<stdin>", line 1, in ?
594+
File "<stdin>", line 1, in <module>
595595
TypeError: object doesn't support item assignment
596596

597597
passes under Python 2.3 and later Python versions with the flag specified,

Doc/library/fpectl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ The following example demonstrates how to start up and test operation of the
8989
>>> import math
9090
>>> math.exp(1000)
9191
Traceback (most recent call last):
92-
File "<stdin>", line 1, in ?
92+
File "<stdin>", line 1, in <module>
9393
FloatingPointError: in math_1
9494

9595

Doc/library/pdb.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ The typical usage to inspect a crashed program is::
7676
>>> import mymodule
7777
>>> mymodule.test()
7878
Traceback (most recent call last):
79-
File "<stdin>", line 1, in ?
79+
File "<stdin>", line 1, in <module>
8080
File "./mymodule.py", line 4, in test
8181
test2()
8282
File "./mymodule.py", line 3, in test2

Doc/library/unicodedata.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Examples:
158158
9
159159
>>> unicodedata.decimal('a')
160160
Traceback (most recent call last):
161-
File "<stdin>", line 1, in ?
161+
File "<stdin>", line 1, in <module>
162162
ValueError: not a decimal
163163
>>> unicodedata.category('A') # 'L'etter, 'u'ppercase
164164
'Lu'

Doc/reference/expressions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ keyword arguments (and any ``**expression`` arguments -- see below). So::
745745
2 1
746746
>>> f(a=1, *(2,))
747747
Traceback (most recent call last):
748-
File "<stdin>", line 1, in ?
748+
File "<stdin>", line 1, in <module>
749749
TypeError: f() got multiple values for keyword argument 'a'
750750
>>> f(1, *(2,))
751751
1 2

Doc/tutorial/classes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ using the :func:`next` built-in function; this example shows how it all works::
784784
'c'
785785
>>> next(it)
786786
Traceback (most recent call last):
787-
File "<stdin>", line 1, in ?
787+
File "<stdin>", line 1, in <module>
788788
next(it)
789789
StopIteration
790790

Doc/tutorial/controlflow.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ Here's an example that fails due to this restriction::
472472
...
473473
>>> function(0, a=0)
474474
Traceback (most recent call last):
475-
File "<stdin>", line 1, in ?
475+
File "<stdin>", line 1, in <module>
476476
TypeError: function() got multiple values for keyword argument 'a'
477477

478478
When a final formal parameter of the form ``**name`` is present, it receives a

Doc/tutorial/datastructures.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ it must be parenthesized. ::
261261
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
262262
>>> # the tuple must be parenthesized, otherwise an error is raised
263263
>>> [x, x**2 for x in range(6)]
264-
File "<stdin>", line 1, in ?
264+
File "<stdin>", line 1, in <module>
265265
[x, x**2 for x in range(6)]
266266
^
267267
SyntaxError: invalid syntax

Doc/tutorial/inputoutput.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ attempts to use the file object will automatically fail. ::
361361
>>> f.close()
362362
>>> f.read()
363363
Traceback (most recent call last):
364-
File "<stdin>", line 1, in ?
364+
File "<stdin>", line 1, in <module>
365365
ValueError: I/O operation on closed file
366366

367367
It is good practice to use the :keyword:`with` keyword when dealing with file

0 commit comments

Comments
 (0)