Skip to content

Commit d2d58ca

Browse files
committed
gh-133905: Fix parsing problems in example code
1 parent a05433f commit d2d58ca

28 files changed

+66
-24
lines changed

Doc/faq/programming.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ Why are default values shared between objects?
340340
This type of bug commonly bites neophyte programmers. Consider this function::
341341

342342
def foo(mydict={}): # Danger: shared reference to one dict for all calls
343-
... compute something ...
343+
# ... compute something ...
344344
mydict[key] = value
345345
return mydict
346346

@@ -382,7 +382,7 @@ requested again. This is called "memoizing", and can be implemented like this::
382382
return _cache[(arg1, arg2)]
383383

384384
# Calculate the value
385-
result = ... expensive computation ...
385+
result = ... # ... expensive computation ...
386386
_cache[(arg1, arg2)] = result # Store result in the cache
387387
return result
388388

@@ -1555,7 +1555,8 @@ that does something::
15551555
... # code to search a mailbox
15561556
elif isinstance(obj, Document):
15571557
... # code to search a document
1558-
elif ...
1558+
elif ...:
1559+
...
15591560

15601561
A better approach is to define a ``search()`` method on all the classes and just
15611562
call it::

Doc/howto/ipaddress.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ membership test syntax like this::
255255

256256
if address in network:
257257
# do something
258+
...
258259

259260
Containment testing is done efficiently based on the network prefix::
260261

Doc/howto/logging.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ following example::
190190
numeric_level = getattr(logging, loglevel.upper(), None)
191191
if not isinstance(numeric_level, int):
192192
raise ValueError('Invalid log level: %s' % loglevel)
193-
logging.basicConfig(level=numeric_level, ...)
193+
logging.basicConfig(..., level=numeric_level)
194194

195195
The call to :func:`basicConfig` should come *before* any calls to a logger's
196196
methods such as :meth:`~Logger.debug`, :meth:`~Logger.info`, etc. Otherwise,

Doc/howto/urllib2.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ Number 1
360360
print('Reason: ', e.reason)
361361
else:
362362
# everything is fine
363+
...
363364

364365

365366
.. note::
@@ -386,6 +387,7 @@ Number 2
386387
print('Error code: ', e.code)
387388
else:
388389
# everything is fine
390+
...
389391

390392

391393
info and geturl

Doc/library/argparse.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ upper-cased name. For example::
698698

699699
>>> parser = argparse.ArgumentParser(prog='PROG')
700700
>>> parser.add_argument('--foo-bar')
701-
>>> parser.parse_args(['--foo-bar', 'FOO-BAR']
701+
>>> parser.parse_args(['--foo-bar', 'FOO-BAR'])
702702
Namespace(foo_bar='FOO-BAR')
703703
>>> parser.print_help()
704704
usage: [-h] [--foo-bar FOO-BAR]

Doc/library/ast.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
.. testsetup::
1111

12-
import ast
12+
import ast
1313

1414
**Source code:** :source:`Lib/ast.py`
1515

Doc/library/asyncio-eventloop.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,7 @@ Do not instantiate the :class:`Server` class directly.
16561656

16571657
async with srv:
16581658
# some code
1659+
...
16591660

16601661
# At this point, srv is closed and no longer accepts new connections.
16611662

Doc/library/asyncio-sync.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Lock
5252
# ... later
5353
async with lock:
5454
# access shared state
55+
...
5556

5657
which is equivalent to::
5758

@@ -61,6 +62,7 @@ Lock
6162
await lock.acquire()
6263
try:
6364
# access shared state
65+
...
6466
finally:
6567
lock.release()
6668

@@ -300,6 +302,7 @@ Semaphore
300302
# ... later
301303
async with sem:
302304
# work with shared resource
305+
...
303306

304307
which is equivalent to::
305308

@@ -309,6 +312,7 @@ Semaphore
309312
await sem.acquire()
310313
try:
311314
# work with shared resource
315+
...
312316
finally:
313317
sem.release()
314318

Doc/library/contextlib.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Functions and classes provided:
6969
The function can then be used like this::
7070

7171
>>> with managed_resource(timeout=3600) as resource:
72+
... ...
7273
... # Resource is released at the end of this block,
7374
... # even if code in the block raises an exception
7475

@@ -145,6 +146,7 @@ Functions and classes provided:
145146
@timeit()
146147
async def main():
147148
# ... async code ...
149+
...
148150

149151
When used as a decorator, a new generator instance is implicitly created on
150152
each function call. This allows the otherwise "one-shot" context managers
@@ -241,6 +243,7 @@ Functions and classes provided:
241243
cm = contextlib.nullcontext()
242244
with cm:
243245
# Do something
246+
...
244247

245248
An example using *enter_result*::
246249

@@ -254,6 +257,7 @@ Functions and classes provided:
254257

255258
with cm as file:
256259
# Perform processing on the file
260+
...
257261

258262
It can also be used as a stand-in for
259263
:ref:`asynchronous context managers <async-context-managers>`::
@@ -268,6 +272,7 @@ Functions and classes provided:
268272

269273
async with cm as session:
270274
# Send http requests with session
275+
...
271276

272277
.. versionadded:: 3.7
273278

@@ -438,12 +443,14 @@ Functions and classes provided:
438443
def f():
439444
with cm():
440445
# Do stuff
446+
...
441447

442448
``ContextDecorator`` lets you instead write::
443449

444450
@cm()
445451
def f():
446452
# Do stuff
453+
...
447454

448455
It makes it clear that the ``cm`` applies to the whole function, rather than
449456
just a piece of it (and saving an indentation level is nice, too).
@@ -706,9 +713,11 @@ protocol can be separated slightly in order to allow this::
706713
x = stack.enter_context(cm)
707714
except Exception:
708715
# handle __enter__ exception
716+
...
709717
else:
710718
with stack:
711719
# Handle normal case
720+
...
712721

713722
Actually needing to do this is likely to indicate that the underlying API
714723
should be providing a direct resource management interface for use with

Doc/library/dataclasses.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ Module contents
226226
:meth:`~object.__init__` method, which will be defined as::
227227

228228
def __init__(self, a: int, b: int = 0):
229+
...
229230

230231
:exc:`TypeError` will be raised if a field without a default value
231232
follows a field with a default value. This is true whether this
@@ -670,6 +671,7 @@ type of :attr:`!x` is :class:`int`, as specified in class :class:`!C`.
670671
The generated :meth:`~object.__init__` method for :class:`!C` will look like::
671672

672673
def __init__(self, x: int = 15, y: int = 0, z: int = 10):
674+
...
673675

674676
Re-ordering of keyword-only parameters in :meth:`!__init__`
675677
-----------------------------------------------------------
@@ -698,6 +700,7 @@ fields, and :attr:`!Base.x` and :attr:`!D.z` are regular fields::
698700
The generated :meth:`!__init__` method for :class:`!D` will look like::
699701

700702
def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: int = 0):
703+
...
701704

702705
Note that the parameters have been re-ordered from how they appear in
703706
the list of fields: parameters derived from regular fields are

Doc/library/decimal.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ threads calling :func:`getcontext`. For example::
19031903
t1.start()
19041904
t2.start()
19051905
t3.start()
1906-
. . .
1906+
...
19071907

19081908
.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19091909
@@ -2165,7 +2165,7 @@ applied to the *result* of the computation::
21652165
Decimal('3.1416')
21662166
>>> pi - Decimal('0.00005') # Subtract unrounded numbers, then round
21672167
Decimal('3.1415')
2168-
>>> pi + 0 - Decimal('0.00005'). # Intermediate values are rounded
2168+
>>> pi + 0 - Decimal('0.00005') # Intermediate values are rounded
21692169
Decimal('3.1416')
21702170

21712171
Q. Some decimal values always print with exponential notation. Is there a way

Doc/library/dis.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ not have to be) the original ``STACK[-2]``.
700700

701701
rhs = STACK.pop()
702702
lhs = STACK.pop()
703-
STACK.append(lhs op rhs)
703+
STACK.append(lhs, op, rhs)
704704

705705
.. versionadded:: 3.11
706706
.. versionchanged:: 3.14

Doc/library/inspect.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,7 @@ is considered deprecated and may be removed in the future.
14051405
frame = inspect.currentframe()
14061406
try:
14071407
# do something with the frame
1408+
...
14081409
finally:
14091410
del frame
14101411

Doc/library/logging.config.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ following configuration::
558558
'bar' : 'baz',
559559
'spam' : 99.9,
560560
'answer' : 42,
561-
'.' {
561+
'.' : {
562562
'foo': 'bar',
563563
'baz': 'bozz'
564564
}

Doc/library/logging.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ functions.
11761176

11771177
class MyLogger(logging.getLoggerClass()):
11781178
# ... override behaviour here
1179+
...
11791180

11801181

11811182
.. function:: getLogRecordFactory()

Doc/library/multiprocessing.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,7 +2935,8 @@ Explicitly pass resources to child processes
29352935
from multiprocessing import Process, Lock
29362936

29372937
def f():
2938-
... do something using "lock" ...
2938+
# ... do something using "lock" ...
2939+
...
29392940

29402941
if __name__ == '__main__':
29412942
lock = Lock()
@@ -2947,7 +2948,8 @@ Explicitly pass resources to child processes
29472948
from multiprocessing import Process, Lock
29482949

29492950
def f(l):
2950-
... do something using "l" ...
2951+
# ... do something using "l" ...
2952+
...
29512953

29522954
if __name__ == '__main__':
29532955
lock = Lock()

Doc/library/sys.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,7 @@ always available. Unless explicitly noted otherwise, all variables are read-only
14621462

14631463
if sys.platform.startswith('sunos'):
14641464
# SunOS-specific code here...
1465+
...
14651466

14661467
.. versionchanged:: 3.3
14671468
On Linux, :data:`sys.platform` doesn't contain the major version anymore.

Doc/library/test.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,30 @@ A basic boilerplate is often used::
6262
# Only use setUp() and tearDown() if necessary
6363

6464
def setUp(self):
65-
... code to execute in preparation for tests ...
65+
# ... code to execute in preparation for tests ...
66+
...
6667

6768
def tearDown(self):
68-
... code to execute to clean up after tests ...
69+
# ... code to execute to clean up after tests ...
70+
...
6971

7072
def test_feature_one(self):
7173
# Test feature one.
72-
... testing code ...
74+
# ... testing code ...
75+
...
7376

7477
def test_feature_two(self):
7578
# Test feature two.
76-
... testing code ...
79+
# ... testing code ...
80+
...
7781

78-
... more test methods ...
82+
# ... more test methods ...
7983

8084
class MyTestCase2(unittest.TestCase):
81-
... same structure as MyTestCase1 ...
85+
# ... same structure as MyTestCase1 ...
86+
...
8287

83-
... more test classes ...
88+
# ... more test classes ...
8489

8590
if __name__ == '__main__':
8691
unittest.main()
@@ -1683,6 +1688,7 @@ The :mod:`test.support.warnings_helper` module provides support for warnings tes
16831688
@warning_helper.ignore_warnings(category=DeprecationWarning)
16841689
def test_suppress_warning():
16851690
# do something
1691+
...
16861692

16871693
.. versionadded:: 3.8
16881694

Doc/library/threading.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ when they need to connect to the server::
983983
conn = connectdb()
984984
try:
985985
# ... use connection ...
986+
...
986987
finally:
987988
conn.close()
988989

@@ -1202,12 +1203,14 @@ the following snippet::
12021203

12031204
with some_lock:
12041205
# do something...
1206+
...
12051207

12061208
is equivalent to::
12071209

12081210
some_lock.acquire()
12091211
try:
12101212
# do something...
1213+
...
12111214
finally:
12121215
some_lock.release()
12131216

Doc/library/tkinter.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ and to have a callback function trigger when that event type occurs. The form
872872
of the bind method is::
873873

874874
def bind(self, sequence, func, add=''):
875+
...
875876

876877
where:
877878

Doc/library/urllib.request.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ environment settings::
13751375
The following example uses no proxies at all, overriding environment settings::
13761376

13771377
>>> import urllib.request
1378-
>>> opener = urllib.request.build_opener(urllib.request.ProxyHandler({}}))
1378+
>>> opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
13791379
>>> with opener.open("http://www.python.org/") as f:
13801380
... f.read().decode('utf-8')
13811381
...

Doc/library/weakref.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ third party, such as running code when a module is unloaded::
588588
import weakref, sys
589589
def unloading_module():
590590
# implicit reference to the module globals from the function body
591+
...
591592
weakref.finalize(sys.modules[__name__], unloading_module)
592593

593594

Doc/tutorial/classes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ expressions are also allowed. This can be useful, for example, when the base
583583
class is defined in another module::
584584

585585
class DerivedClassName(modname.BaseClassName):
586+
...
586587

587588
Execution of a derived class definition proceeds the same as for a base class.
588589
When the class object is constructed, the base class is remembered. This is

Doc/tutorial/controlflow.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ Recap
896896
The use case will determine which parameters to use in the function definition::
897897

898898
def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):
899+
...
899900

900901
As guidance:
901902

0 commit comments

Comments
 (0)