Skip to content

Commit

Permalink
gh-99087: Add missing newline for prompts in docs (GH-98993)
Browse files Browse the repository at this point in the history
Add newline for prompts so copying to REPL does not cause errors.
  • Loading branch information
slateny committed Dec 9, 2022
1 parent 3e06b50 commit 286e3c7
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Doc/howto/enum.rst
Expand Up @@ -158,6 +158,7 @@ And a function to display the chores for a given day::
... for chore, days in chores.items():
... if day in days:
... print(chore)
...
>>> show_chores(chores_for_ethan, Weekday.SATURDAY)
answer SO questions

Expand Down Expand Up @@ -712,6 +713,7 @@ It is also possible to name the combinations::
... W = 2
... X = 1
... RWX = 7
...
>>> Perm.RWX
<Perm.RWX: 7>
>>> ~Perm.RWX
Expand Down
1 change: 1 addition & 0 deletions Doc/library/argparse.rst
Expand Up @@ -565,6 +565,7 @@ arguments they contain. For example::

>>> with open('args.txt', 'w', encoding=sys.getfilesystemencoding()) as fp:
... fp.write('-f\nbar')
...
>>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
>>> parser.add_argument('-f')
>>> parser.parse_args(['-f', 'foo', '@args.txt'])
Expand Down
2 changes: 2 additions & 0 deletions Doc/library/bz2.rst
Expand Up @@ -320,9 +320,11 @@ Writing and reading a bzip2-compressed file in binary mode:
>>> with bz2.open("myfile.bz2", "wb") as f:
... # Write compressed data to file
... unused = f.write(data)
...
>>> with bz2.open("myfile.bz2", "rb") as f:
... # Decompress data from file
... content = f.read()
...
>>> content == data # Check equality to original object after round-trip
True

Expand Down
2 changes: 2 additions & 0 deletions Doc/library/collections.rst
Expand Up @@ -229,6 +229,7 @@ For example::
>>> cnt = Counter()
>>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
... cnt[word] += 1
...
>>> cnt
Counter({'blue': 3, 'red': 2, 'green': 1})

Expand Down Expand Up @@ -818,6 +819,7 @@ zero):

>>> def constant_factory(value):
... return lambda: value
...
>>> d = defaultdict(constant_factory('<missing>'))
>>> d.update(name='John', action='ran')
>>> '%(name)s %(action)s to %(object)s' % d
Expand Down
1 change: 1 addition & 0 deletions Doc/library/datetime.rst
Expand Up @@ -765,6 +765,7 @@ Example of counting days to an event::
>>> my_birthday = date(today.year, 6, 24)
>>> if my_birthday < today:
... my_birthday = my_birthday.replace(year=today.year + 1)
...
>>> my_birthday
datetime.date(2008, 6, 24)
>>> time_to_birthday = abs(my_birthday - today)
Expand Down
1 change: 1 addition & 0 deletions Doc/library/decimal.rst
Expand Up @@ -2057,6 +2057,7 @@ to handle the :meth:`quantize` step:

>>> def mul(x, y, fp=TWOPLACES):
... return (x * y).quantize(fp)
...
>>> def div(x, y, fp=TWOPLACES):
... return (x / y).quantize(fp)

Expand Down
2 changes: 2 additions & 0 deletions Doc/library/doctest.rst
Expand Up @@ -351,6 +351,7 @@ The fine print:

>>> def f(x):
... r'''Backslashes in a raw docstring: m\n'''
...
>>> print(f.__doc__)
Backslashes in a raw docstring: m\n

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

>>> def f(x):
... '''Backslashes in a raw docstring: m\\n'''
...
>>> print(f.__doc__)
Backslashes in a raw docstring: m\n

Expand Down
1 change: 1 addition & 0 deletions Doc/library/email.policy.rst
Expand Up @@ -97,6 +97,7 @@ file on disk and pass it to the system ``sendmail`` program on a Unix system:
>>> from subprocess import Popen, PIPE
>>> with open('mymsg.txt', 'rb') as f:
... msg = message_from_binary_file(f, policy=policy.default)
...
>>> p = Popen(['sendmail', msg['To'].addresses[0]], stdin=PIPE)
>>> g = BytesGenerator(p.stdin, policy=msg.policy.clone(linesep='\r\n'))
>>> g.flatten(msg)
Expand Down
13 changes: 13 additions & 0 deletions Doc/library/enum.rst
Expand Up @@ -292,6 +292,7 @@ Data Types
... @classmethod
... def today(cls):
... print('today is %s' % cls(date.today().isoweekday()).name)
...
>>> dir(Weekday.SATURDAY)
['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']

Expand All @@ -312,6 +313,7 @@ Data Types
... return (count + 1) * 3
... FIRST = auto()
... SECOND = auto()
...
>>> PowersOfThree.SECOND.value
6

Expand All @@ -336,6 +338,7 @@ Data Types
... if member.value == value:
... return member
... return None
...
>>> Build.DEBUG.value
'debug'
>>> Build('deBUG')
Expand All @@ -353,6 +356,7 @@ Data Types
... def __repr__(self):
... cls_name = self.__class__.__name__
... return f'{cls_name}.{self.name}'
...
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
(OtherStyle.ALTERNATE, 'OtherStyle.ALTERNATE', 'OtherStyle.ALTERNATE')

Expand All @@ -367,6 +371,7 @@ Data Types
... SOMETHING_ELSE = auto()
... def __str__(self):
... return f'{self.name}'
...
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
(<OtherStyle.ALTERNATE: 1>, 'ALTERNATE', 'ALTERNATE')

Expand All @@ -381,6 +386,7 @@ Data Types
... SOMETHING_ELSE = auto()
... def __format__(self, spec):
... return f'{self.name}'
...
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
(<OtherStyle.ALTERNATE: 1>, 'OtherStyle.ALTERNATE', 'ALTERNATE')

Expand All @@ -403,6 +409,7 @@ Data Types
... ONE = 1
... TWO = 2
... THREE = 3
...
>>> Numbers.THREE
<Numbers.THREE: 3>
>>> Numbers.ONE + Numbers.TWO
Expand Down Expand Up @@ -463,6 +470,7 @@ Data Types
... RED = auto()
... GREEN = auto()
... BLUE = auto()
...
>>> purple = Color.RED | Color.BLUE
>>> white = Color.RED | Color.GREEN | Color.BLUE
>>> Color.GREEN in purple
Expand Down Expand Up @@ -570,6 +578,7 @@ Data Types
... RED = auto()
... GREEN = auto()
... BLUE = auto()
...
>>> Color.RED & 2
<Color: 0>
>>> Color.RED | 2
Expand Down Expand Up @@ -695,6 +704,7 @@ Data Types
... RED = auto()
... GREEN = auto()
... BLUE = auto()
...
>>> StrictFlag(2**2 + 2**4)
Traceback (most recent call last):
...
Expand All @@ -712,6 +722,7 @@ Data Types
... RED = auto()
... GREEN = auto()
... BLUE = auto()
...
>>> ConformFlag(2**2 + 2**4)
<ConformFlag.BLUE: 4>

Expand All @@ -725,6 +736,7 @@ Data Types
... RED = auto()
... GREEN = auto()
... BLUE = auto()
...
>>> EjectFlag(2**2 + 2**4)
20

Expand All @@ -738,6 +750,7 @@ Data Types
... RED = auto()
... GREEN = auto()
... BLUE = auto()
...
>>> KeepFlag(2**2 + 2**4)
<KeepFlag.BLUE|16: 20>

Expand Down
1 change: 1 addition & 0 deletions Doc/library/functions.rst
Expand Up @@ -462,6 +462,7 @@ are always available. They are listed here in alphabetical order.
>>> class Shape:
... def __dir__(self):
... return ['area', 'perimeter', 'location']
...
>>> s = Shape()
>>> dir(s)
['area', 'location', 'perimeter']
Expand Down
1 change: 1 addition & 0 deletions Doc/library/hashlib.rst
Expand Up @@ -497,6 +497,7 @@ update the hash:
>>> h = blake2b()
>>> for item in items:
... h.update(item)
...
>>> h.hexdigest()
'6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183'

Expand Down
2 changes: 2 additions & 0 deletions Doc/library/inspect.rst
Expand Up @@ -715,6 +715,7 @@ function.

>>> def test(a, b):
... pass
...
>>> sig = signature(test)
>>> new_sig = sig.replace(return_annotation="new return anno")
>>> str(new_sig)
Expand Down Expand Up @@ -1054,6 +1055,7 @@ Classes and functions
>>> from inspect import getcallargs
>>> def f(a, b=1, *pos, **named):
... pass
...
>>> getcallargs(f, 1, 2, 3) == {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
True
>>> getcallargs(f, a=2, x=4) == {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}
Expand Down
2 changes: 2 additions & 0 deletions Doc/library/re.rst
Expand Up @@ -973,6 +973,7 @@ Functions
>>> def dashrepl(matchobj):
... if matchobj.group(0) == '-': return ' '
... else: return '-'
...
>>> re.sub('-{1,2}', dashrepl, 'pro----gram-files')
'pro--gram files'
>>> re.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=re.IGNORECASE)
Expand Down Expand Up @@ -1672,6 +1673,7 @@ in each word of a sentence except for the first and last characters::
... inner_word = list(m.group(2))
... random.shuffle(inner_word)
... return m.group(1) + "".join(inner_word) + m.group(3)
...
>>> text = "Professor Abdolmalek, please report your absences promptly."
>>> re.sub(r"(\w)(\w+)(\w)", repl, text)
'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'
Expand Down
1 change: 1 addition & 0 deletions Doc/library/sqlite3.rst
Expand Up @@ -397,6 +397,7 @@ Module functions
>>> con = sqlite3.connect(":memory:")
>>> def evil_trace(stmt):
... 5/0
...
>>> con.set_trace_callback(evil_trace)
>>> def debug(unraisable):
... print(f"{unraisable.exc_value!r} in callback {unraisable.object.__name__}")
Expand Down
1 change: 1 addition & 0 deletions Doc/library/statistics.rst
Expand Up @@ -996,6 +996,7 @@ probability that the Python room will stay within its capacity limits?
>>> seed(8675309)
>>> def trial():
... return choices(('Python', 'Ruby'), (p, q), k=n).count('Python')
...
>>> mean(trial() <= k for i in range(10_000))
0.8398

Expand Down
2 changes: 2 additions & 0 deletions Doc/library/stdtypes.rst
Expand Up @@ -4459,6 +4459,7 @@ can be used interchangeably to index the same dictionary entry.
>>> class Counter(dict):
... def __missing__(self, key):
... return 0
...
>>> c = Counter()
>>> c['red']
0
Expand Down Expand Up @@ -4716,6 +4717,7 @@ An example of dictionary view usage::
>>> n = 0
>>> for val in values:
... n += val
...
>>> print(n)
504

Expand Down
1 change: 1 addition & 0 deletions Doc/library/unittest.mock.rst
Expand Up @@ -1604,6 +1604,7 @@ decorator:
>>> @patch.dict(foo, {'newkey': 'newvalue'})
... def test():
... assert foo == {'newkey': 'newvalue'}
...
>>> test()
>>> assert foo == {}

Expand Down
1 change: 1 addition & 0 deletions Doc/library/xml.etree.elementtree.rst
Expand Up @@ -1212,6 +1212,7 @@ Example of changing the attribute "target" of every link in first paragraph::
[<Element 'a' at 0xb77ec2ac>, <Element 'a' at 0xb77ec1cc>]
>>> for i in links: # Iterates through all found links
... i.attrib["target"] = "blank"
...
>>> tree.write("output.xhtml")

.. _elementtree-qname-objects:
Expand Down
1 change: 1 addition & 0 deletions Doc/library/zipfile.rst
Expand Up @@ -672,6 +672,7 @@ The :class:`PyZipFile` constructor takes the same parameters as the
>>> def notests(s):
... fn = os.path.basename(s)
... return (not (fn == 'test' or fn.startswith('test_')))
...
>>> zf.writepy('myprog', filterfunc=notests)

The :meth:`writepy` method makes archives with file names like
Expand Down
1 change: 1 addition & 0 deletions Doc/whatsnew/2.7.rst
Expand Up @@ -1331,6 +1331,7 @@ changes, or look through the Subversion logs for all the details.
>>> from inspect import getcallargs
>>> def f(a, b=1, *pos, **named):
... pass
...
>>> getcallargs(f, 1, 2, 3)
{'a': 1, 'b': 2, 'pos': (3,), 'named': {}}
>>> getcallargs(f, a=2, x=4)
Expand Down
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.2.rst
Expand Up @@ -468,13 +468,15 @@ Some smaller changes made to the core Python language are:
>>> class LowerCasedDict(dict):
... def __getitem__(self, key):
... return dict.__getitem__(self, key.lower())
...
>>> lcd = LowerCasedDict(part='widgets', quantity=10)
>>> 'There are {QUANTITY} {Part} in stock'.format_map(lcd)
'There are 10 widgets in stock'

>>> class PlaceholderDict(dict):
... def __missing__(self, key):
... return '<{}>'.format(key)
...
>>> 'Hello {name}, welcome to {location}'.format_map(PlaceholderDict())
'Hello <name>, welcome to <location>'

Expand Down Expand Up @@ -1886,6 +1888,7 @@ inspect
>>> from inspect import getgeneratorstate
>>> def gen():
... yield 'demo'
...
>>> g = gen()
>>> getgeneratorstate(g)
'GEN_CREATED'
Expand Down
1 change: 1 addition & 0 deletions Doc/whatsnew/3.3.rst
Expand Up @@ -560,6 +560,7 @@ Example with (non-bound) methods::
>>> class C:
... def meth(self):
... pass
...
>>> C.meth.__name__
'meth'
>>> C.meth.__qualname__
Expand Down

0 comments on commit 286e3c7

Please sign in to comment.