Skip to content

Commit 286e3c7

Browse files
authored
gh-99087: Add missing newline for prompts in docs (GH-98993)
Add newline for prompts so copying to REPL does not cause errors.
1 parent 3e06b50 commit 286e3c7

22 files changed

+43
-0
lines changed

Doc/howto/enum.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ And a function to display the chores for a given day::
158158
... for chore, days in chores.items():
159159
... if day in days:
160160
... print(chore)
161+
...
161162
>>> show_chores(chores_for_ethan, Weekday.SATURDAY)
162163
answer SO questions
163164

@@ -712,6 +713,7 @@ It is also possible to name the combinations::
712713
... W = 2
713714
... X = 1
714715
... RWX = 7
716+
...
715717
>>> Perm.RWX
716718
<Perm.RWX: 7>
717719
>>> ~Perm.RWX

Doc/library/argparse.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ arguments they contain. For example::
565565

566566
>>> with open('args.txt', 'w', encoding=sys.getfilesystemencoding()) as fp:
567567
... fp.write('-f\nbar')
568+
...
568569
>>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
569570
>>> parser.add_argument('-f')
570571
>>> parser.parse_args(['-f', 'foo', '@args.txt'])

Doc/library/bz2.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,11 @@ Writing and reading a bzip2-compressed file in binary mode:
320320
>>> with bz2.open("myfile.bz2", "wb") as f:
321321
... # Write compressed data to file
322322
... unused = f.write(data)
323+
...
323324
>>> with bz2.open("myfile.bz2", "rb") as f:
324325
... # Decompress data from file
325326
... content = f.read()
327+
...
326328
>>> content == data # Check equality to original object after round-trip
327329
True
328330

Doc/library/collections.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ For example::
229229
>>> cnt = Counter()
230230
>>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
231231
... cnt[word] += 1
232+
...
232233
>>> cnt
233234
Counter({'blue': 3, 'red': 2, 'green': 1})
234235

@@ -818,6 +819,7 @@ zero):
818819

819820
>>> def constant_factory(value):
820821
... return lambda: value
822+
...
821823
>>> d = defaultdict(constant_factory('<missing>'))
822824
>>> d.update(name='John', action='ran')
823825
>>> '%(name)s %(action)s to %(object)s' % d

Doc/library/datetime.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ Example of counting days to an event::
765765
>>> my_birthday = date(today.year, 6, 24)
766766
>>> if my_birthday < today:
767767
... my_birthday = my_birthday.replace(year=today.year + 1)
768+
...
768769
>>> my_birthday
769770
datetime.date(2008, 6, 24)
770771
>>> time_to_birthday = abs(my_birthday - today)

Doc/library/decimal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,7 @@ to handle the :meth:`quantize` step:
20572057

20582058
>>> def mul(x, y, fp=TWOPLACES):
20592059
... return (x * y).quantize(fp)
2060+
...
20602061
>>> def div(x, y, fp=TWOPLACES):
20612062
... return (x / y).quantize(fp)
20622063

Doc/library/doctest.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ The fine print:
351351

352352
>>> def f(x):
353353
... r'''Backslashes in a raw docstring: m\n'''
354+
...
354355
>>> print(f.__doc__)
355356
Backslashes in a raw docstring: m\n
356357

@@ -360,6 +361,7 @@ The fine print:
360361

361362
>>> def f(x):
362363
... '''Backslashes in a raw docstring: m\\n'''
364+
...
363365
>>> print(f.__doc__)
364366
Backslashes in a raw docstring: m\n
365367

Doc/library/email.policy.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ file on disk and pass it to the system ``sendmail`` program on a Unix system:
9797
>>> from subprocess import Popen, PIPE
9898
>>> with open('mymsg.txt', 'rb') as f:
9999
... msg = message_from_binary_file(f, policy=policy.default)
100+
...
100101
>>> p = Popen(['sendmail', msg['To'].addresses[0]], stdin=PIPE)
101102
>>> g = BytesGenerator(p.stdin, policy=msg.policy.clone(linesep='\r\n'))
102103
>>> g.flatten(msg)

Doc/library/enum.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ Data Types
292292
... @classmethod
293293
... def today(cls):
294294
... print('today is %s' % cls(date.today().isoweekday()).name)
295+
...
295296
>>> dir(Weekday.SATURDAY)
296297
['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']
297298

@@ -312,6 +313,7 @@ Data Types
312313
... return (count + 1) * 3
313314
... FIRST = auto()
314315
... SECOND = auto()
316+
...
315317
>>> PowersOfThree.SECOND.value
316318
6
317319

@@ -336,6 +338,7 @@ Data Types
336338
... if member.value == value:
337339
... return member
338340
... return None
341+
...
339342
>>> Build.DEBUG.value
340343
'debug'
341344
>>> Build('deBUG')
@@ -353,6 +356,7 @@ Data Types
353356
... def __repr__(self):
354357
... cls_name = self.__class__.__name__
355358
... return f'{cls_name}.{self.name}'
359+
...
356360
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
357361
(OtherStyle.ALTERNATE, 'OtherStyle.ALTERNATE', 'OtherStyle.ALTERNATE')
358362

@@ -367,6 +371,7 @@ Data Types
367371
... SOMETHING_ELSE = auto()
368372
... def __str__(self):
369373
... return f'{self.name}'
374+
...
370375
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
371376
(<OtherStyle.ALTERNATE: 1>, 'ALTERNATE', 'ALTERNATE')
372377

@@ -381,6 +386,7 @@ Data Types
381386
... SOMETHING_ELSE = auto()
382387
... def __format__(self, spec):
383388
... return f'{self.name}'
389+
...
384390
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
385391
(<OtherStyle.ALTERNATE: 1>, 'OtherStyle.ALTERNATE', 'ALTERNATE')
386392

@@ -403,6 +409,7 @@ Data Types
403409
... ONE = 1
404410
... TWO = 2
405411
... THREE = 3
412+
...
406413
>>> Numbers.THREE
407414
<Numbers.THREE: 3>
408415
>>> Numbers.ONE + Numbers.TWO
@@ -463,6 +470,7 @@ Data Types
463470
... RED = auto()
464471
... GREEN = auto()
465472
... BLUE = auto()
473+
...
466474
>>> purple = Color.RED | Color.BLUE
467475
>>> white = Color.RED | Color.GREEN | Color.BLUE
468476
>>> Color.GREEN in purple
@@ -570,6 +578,7 @@ Data Types
570578
... RED = auto()
571579
... GREEN = auto()
572580
... BLUE = auto()
581+
...
573582
>>> Color.RED & 2
574583
<Color: 0>
575584
>>> Color.RED | 2
@@ -695,6 +704,7 @@ Data Types
695704
... RED = auto()
696705
... GREEN = auto()
697706
... BLUE = auto()
707+
...
698708
>>> StrictFlag(2**2 + 2**4)
699709
Traceback (most recent call last):
700710
...
@@ -712,6 +722,7 @@ Data Types
712722
... RED = auto()
713723
... GREEN = auto()
714724
... BLUE = auto()
725+
...
715726
>>> ConformFlag(2**2 + 2**4)
716727
<ConformFlag.BLUE: 4>
717728

@@ -725,6 +736,7 @@ Data Types
725736
... RED = auto()
726737
... GREEN = auto()
727738
... BLUE = auto()
739+
...
728740
>>> EjectFlag(2**2 + 2**4)
729741
20
730742

@@ -738,6 +750,7 @@ Data Types
738750
... RED = auto()
739751
... GREEN = auto()
740752
... BLUE = auto()
753+
...
741754
>>> KeepFlag(2**2 + 2**4)
742755
<KeepFlag.BLUE|16: 20>
743756

Doc/library/functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ are always available. They are listed here in alphabetical order.
462462
>>> class Shape:
463463
... def __dir__(self):
464464
... return ['area', 'perimeter', 'location']
465+
...
465466
>>> s = Shape()
466467
>>> dir(s)
467468
['area', 'location', 'perimeter']

Doc/library/hashlib.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ update the hash:
497497
>>> h = blake2b()
498498
>>> for item in items:
499499
... h.update(item)
500+
...
500501
>>> h.hexdigest()
501502
'6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183'
502503

Doc/library/inspect.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ function.
715715

716716
>>> def test(a, b):
717717
... pass
718+
...
718719
>>> sig = signature(test)
719720
>>> new_sig = sig.replace(return_annotation="new return anno")
720721
>>> str(new_sig)
@@ -1054,6 +1055,7 @@ Classes and functions
10541055
>>> from inspect import getcallargs
10551056
>>> def f(a, b=1, *pos, **named):
10561057
... pass
1058+
...
10571059
>>> getcallargs(f, 1, 2, 3) == {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
10581060
True
10591061
>>> getcallargs(f, a=2, x=4) == {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}

Doc/library/re.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ Functions
973973
>>> def dashrepl(matchobj):
974974
... if matchobj.group(0) == '-': return ' '
975975
... else: return '-'
976+
...
976977
>>> re.sub('-{1,2}', dashrepl, 'pro----gram-files')
977978
'pro--gram files'
978979
>>> re.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=re.IGNORECASE)
@@ -1672,6 +1673,7 @@ in each word of a sentence except for the first and last characters::
16721673
... inner_word = list(m.group(2))
16731674
... random.shuffle(inner_word)
16741675
... return m.group(1) + "".join(inner_word) + m.group(3)
1676+
...
16751677
>>> text = "Professor Abdolmalek, please report your absences promptly."
16761678
>>> re.sub(r"(\w)(\w+)(\w)", repl, text)
16771679
'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'

Doc/library/sqlite3.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ Module functions
397397
>>> con = sqlite3.connect(":memory:")
398398
>>> def evil_trace(stmt):
399399
... 5/0
400+
...
400401
>>> con.set_trace_callback(evil_trace)
401402
>>> def debug(unraisable):
402403
... print(f"{unraisable.exc_value!r} in callback {unraisable.object.__name__}")

Doc/library/statistics.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ probability that the Python room will stay within its capacity limits?
996996
>>> seed(8675309)
997997
>>> def trial():
998998
... return choices(('Python', 'Ruby'), (p, q), k=n).count('Python')
999+
...
9991000
>>> mean(trial() <= k for i in range(10_000))
10001001
0.8398
10011002

Doc/library/stdtypes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4459,6 +4459,7 @@ can be used interchangeably to index the same dictionary entry.
44594459
>>> class Counter(dict):
44604460
... def __missing__(self, key):
44614461
... return 0
4462+
...
44624463
>>> c = Counter()
44634464
>>> c['red']
44644465
0
@@ -4716,6 +4717,7 @@ An example of dictionary view usage::
47164717
>>> n = 0
47174718
>>> for val in values:
47184719
... n += val
4720+
...
47194721
>>> print(n)
47204722
504
47214723

Doc/library/unittest.mock.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,7 @@ decorator:
16041604
>>> @patch.dict(foo, {'newkey': 'newvalue'})
16051605
... def test():
16061606
... assert foo == {'newkey': 'newvalue'}
1607+
...
16071608
>>> test()
16081609
>>> assert foo == {}
16091610

Doc/library/xml.etree.elementtree.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ Example of changing the attribute "target" of every link in first paragraph::
12121212
[<Element 'a' at 0xb77ec2ac>, <Element 'a' at 0xb77ec1cc>]
12131213
>>> for i in links: # Iterates through all found links
12141214
... i.attrib["target"] = "blank"
1215+
...
12151216
>>> tree.write("output.xhtml")
12161217

12171218
.. _elementtree-qname-objects:

Doc/library/zipfile.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ The :class:`PyZipFile` constructor takes the same parameters as the
672672
>>> def notests(s):
673673
... fn = os.path.basename(s)
674674
... return (not (fn == 'test' or fn.startswith('test_')))
675+
...
675676
>>> zf.writepy('myprog', filterfunc=notests)
676677

677678
The :meth:`writepy` method makes archives with file names like

Doc/whatsnew/2.7.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ changes, or look through the Subversion logs for all the details.
13311331
>>> from inspect import getcallargs
13321332
>>> def f(a, b=1, *pos, **named):
13331333
... pass
1334+
...
13341335
>>> getcallargs(f, 1, 2, 3)
13351336
{'a': 1, 'b': 2, 'pos': (3,), 'named': {}}
13361337
>>> getcallargs(f, a=2, x=4)

Doc/whatsnew/3.2.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,15 @@ Some smaller changes made to the core Python language are:
468468
>>> class LowerCasedDict(dict):
469469
... def __getitem__(self, key):
470470
... return dict.__getitem__(self, key.lower())
471+
...
471472
>>> lcd = LowerCasedDict(part='widgets', quantity=10)
472473
>>> 'There are {QUANTITY} {Part} in stock'.format_map(lcd)
473474
'There are 10 widgets in stock'
474475

475476
>>> class PlaceholderDict(dict):
476477
... def __missing__(self, key):
477478
... return '<{}>'.format(key)
479+
...
478480
>>> 'Hello {name}, welcome to {location}'.format_map(PlaceholderDict())
479481
'Hello <name>, welcome to <location>'
480482

@@ -1886,6 +1888,7 @@ inspect
18861888
>>> from inspect import getgeneratorstate
18871889
>>> def gen():
18881890
... yield 'demo'
1891+
...
18891892
>>> g = gen()
18901893
>>> getgeneratorstate(g)
18911894
'GEN_CREATED'

Doc/whatsnew/3.3.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ Example with (non-bound) methods::
560560
>>> class C:
561561
... def meth(self):
562562
... pass
563+
...
563564
>>> C.meth.__name__
564565
'meth'
565566
>>> C.meth.__qualname__

0 commit comments

Comments
 (0)