Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 72 additions & 38 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

# General substitutions.
project = 'Python'
copyright = '2001-%s, Python Software Foundation' % time.strftime('%Y')
copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 52-378 refactored with the following changes:

This removes the following comments ( why? ):

# The font size ('10pt', '11pt' or '12pt').
# The paper size ('letter' or 'a4').
# Additional stuff for the LaTeX preamble.


# We look for the Include/patchlevel.h file in the current Python source tree
# and replace the values accordingly.
Expand All @@ -74,7 +74,7 @@
exclude_patterns = ['includes/*.rst', 'venv/*', 'README.rst']
venvdir = os.getenv('VENVDIR')
if venvdir is not None:
exclude_patterns.append(venvdir + '/*')
exclude_patterns.append(f'{venvdir}/*')

nitpick_ignore = [
# Standard C functions
Expand Down Expand Up @@ -277,7 +277,7 @@
print("It may be removed in the future\n")

# Short title used e.g. for <title> HTML tags.
html_short_title = '%s Documentation' % release
html_short_title = f'{release} Documentation'

# Deployment preview information
# (See .readthedocs.yml and https://docs.readthedocs.io/en/stable/reference/environment-variables.html)
Expand Down Expand Up @@ -310,7 +310,7 @@
}

# Output an OpenSearch description file.
html_use_opensearch = 'https://docs.python.org/' + version
html_use_opensearch = f'https://docs.python.org/{version}'

# Additional static files.
html_static_path = ['_static', 'tools/static']
Expand All @@ -329,53 +329,87 @@

# Get LaTeX to handle Unicode correctly
latex_elements = {
}

# Additional stuff for the LaTeX preamble.
latex_elements['preamble'] = r'''
'preamble': '''
\authoraddress{
\sphinxstrong{Python Software Foundation}\\
\sphinxstrong{Python Software Foundation}\
Email: \sphinxemail{docs@python.org}
}
\let\Verbatim=\OriginalVerbatim
\let\endVerbatim=\endOriginalVerbatim
\setcounter{tocdepth}{2}
'''

# The paper size ('letter' or 'a4').
latex_elements['papersize'] = 'a4'

# The font size ('10pt', '11pt' or '12pt').
latex_elements['pointsize'] = '10pt'
''',
'papersize': 'a4',
'pointsize': '10pt',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, document class [howto/manual]).
_stdauthor = 'Guido van Rossum and the Python development team'
latex_documents = [
('c-api/index', 'c-api.tex',
'The Python/C API', _stdauthor, 'manual'),
('extending/index', 'extending.tex',
'Extending and Embedding Python', _stdauthor, 'manual'),
('installing/index', 'installing.tex',
'Installing Python Modules', _stdauthor, 'manual'),
('library/index', 'library.tex',
'The Python Library Reference', _stdauthor, 'manual'),
('reference/index', 'reference.tex',
'The Python Language Reference', _stdauthor, 'manual'),
('tutorial/index', 'tutorial.tex',
'Python Tutorial', _stdauthor, 'manual'),
('using/index', 'using.tex',
'Python Setup and Usage', _stdauthor, 'manual'),
('faq/index', 'faq.tex',
'Python Frequently Asked Questions', _stdauthor, 'manual'),
('whatsnew/' + version, 'whatsnew.tex',
'What\'s New in Python', 'A. M. Kuchling', 'howto'),
('c-api/index', 'c-api.tex', 'The Python/C API', _stdauthor, 'manual'),
(
'extending/index',
'extending.tex',
'Extending and Embedding Python',
_stdauthor,
'manual',
),
(
'installing/index',
'installing.tex',
'Installing Python Modules',
_stdauthor,
'manual',
),
(
'library/index',
'library.tex',
'The Python Library Reference',
_stdauthor,
'manual',
),
(
'reference/index',
'reference.tex',
'The Python Language Reference',
_stdauthor,
'manual',
),
(
'tutorial/index',
'tutorial.tex',
'Python Tutorial',
_stdauthor,
'manual',
),
(
'using/index',
'using.tex',
'Python Setup and Usage',
_stdauthor,
'manual',
),
(
'faq/index',
'faq.tex',
'Python Frequently Asked Questions',
_stdauthor,
'manual',
),
(
f'whatsnew/{version}',
'whatsnew.tex',
'What\'s New in Python',
'A. M. Kuchling',
'howto',
),
]
# Collect all HOWTOs individually
latex_documents.extend(('howto/' + fn[:-4], 'howto-' + fn[:-4] + '.tex',
'', _stdauthor, 'howto')
for fn in os.listdir('howto')
if fn.endswith('.rst') and fn != 'index.rst')
latex_documents.extend(
(f'howto/{fn[:-4]}', f'howto-{fn[:-4]}.tex', '', _stdauthor, 'howto')
for fn in os.listdir('howto')
if fn.endswith('.rst') and fn != 'index.rst'
)

# Documents to append as an appendix to all manuals.
latex_appendices = ['glossary', 'about', 'license', 'copyright']
Expand Down
9 changes: 1 addition & 8 deletions Doc/includes/dbpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ class DBPickler(pickle.Pickler):
def persistent_id(self, obj):
# Instead of pickling MemoRecord as a regular class instance, we emit a
# persistent ID.
if isinstance(obj, MemoRecord):
# Here, our persistent ID is simply a tuple, containing a tag and a
# key, which refers to a specific record in the database.
return ("MemoRecord", obj.key)
else:
# If obj does not have a persistent ID, return None. This means obj
# needs to be pickled as usual.
return None
return ("MemoRecord", obj.key) if isinstance(obj, MemoRecord) else None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DBPickler.persistent_id refactored with the following changes:

This removes the following comments ( why? ):

# If obj does not have a persistent ID, return None. This means obj
# key, which refers to a specific record in the database.
# Here, our persistent ID is simply a tuple, containing a tag and a
# needs to be pickled as usual.



class DBUnpickler(pickle.Unpickler):
Expand Down
10 changes: 5 additions & 5 deletions Doc/includes/email-headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
'Body would go here\n')

# Now the header items can be accessed as a dictionary:
print('To: {}'.format(headers['to']))
print('From: {}'.format(headers['from']))
print('Subject: {}'.format(headers['subject']))
print(f"To: {headers['to']}")
print(f"From: {headers['from']}")
print(f"Subject: {headers['subject']}")

# You can also access the parts of the addresses:
print('Recipient username: {}'.format(headers['to'].addresses[0].username))
print('Sender name: {}'.format(headers['from'].addresses[0].display_name))
print(f"Recipient username: {headers['to'].addresses[0].username}")
print(f"Sender name: {headers['from'].addresses[0].display_name}")
Comment on lines -19 to +25
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 19-25 refactored with the following changes:

36 changes: 20 additions & 16 deletions Doc/includes/email-read-alternative.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,35 @@ def magic_html_parser(html_text, partfiles):
# We can extract the richest alternative in order to display it:
richest = msg.get_body()
partfiles = {}
if richest['content-type'].maintype == 'text':
if richest['content-type'].subtype == 'plain':
for line in richest.get_content().splitlines():
print(line)
sys.exit()
elif richest['content-type'].subtype == 'html':
body = richest
else:
print("Don't know how to display {}".format(richest.get_content_type()))
sys.exit()
elif richest['content-type'].content_type == 'multipart/related':
if (
richest['content-type'].maintype == 'text'
and richest['content-type'].subtype == 'plain'
):
for line in richest.get_content().splitlines():
print(line)
sys.exit()
elif (
richest['content-type'].maintype == 'text'
and richest['content-type'].subtype == 'html'
):
body = richest
elif (
richest['content-type'].maintype == 'text'
or richest['content-type'].content_type != 'multipart/related'
):
print(f"Don't know how to display {richest.get_content_type()}")
sys.exit()
else:
body = richest.get_body(preferencelist=('html'))
for part in richest.iter_attachments():
fn = part.get_filename()
if fn:
if fn := part.get_filename():
Comment on lines -46 to +67
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 46-70 refactored with the following changes:

extension = os.path.splitext(part.get_filename())[1]
else:
extension = mimetypes.guess_extension(part.get_content_type())
with tempfile.NamedTemporaryFile(suffix=extension, delete=False) as f:
f.write(part.get_content())
# again strip the <> to go from email form of cid to html form.
partfiles[part['content-id'][1:-1]] = f.name
else:
print("Don't know how to display {}".format(richest.get_content_type()))
sys.exit()
with tempfile.NamedTemporaryFile(mode='w', delete=False) as f:
f.write(magic_html_parser(body.get_content(), partfiles))
webbrowser.open(f.name)
Expand Down
5 changes: 1 addition & 4 deletions Doc/includes/minidom-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
dom = xml.dom.minidom.parseString(document)

def getText(nodelist):
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
rc = [node.data for node in nodelist if node.nodeType == node.TEXT_NODE]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getText refactored with the following changes:

return ''.join(rc)

def handleSlideshow(slideshow):
Expand Down
8 changes: 2 additions & 6 deletions Doc/includes/mp_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

def calculate(func, args):
result = func(*args)
return '%s says that %s%s = %s' % (
multiprocessing.current_process().name,
func.__name__, args, result
)
return f'{multiprocessing.current_process().name} says that {func.__name__}{args} = {result}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calculate refactored with the following changes:


def calculatestar(args):
return calculate(*args)
Expand Down Expand Up @@ -106,8 +103,7 @@ def test():
try:
x = next(it)
except ZeroDivisionError:
if i == 5:
pass
pass
Comment on lines -109 to +106
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test refactored with the following changes:

except StopIteration:
break
else:
Expand Down
11 changes: 5 additions & 6 deletions Doc/includes/mp_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def worker(input, output):

def calculate(func, args):
result = func(*args)
return '%s says that %s%s = %s' % \
(current_process().name, func.__name__, args, result)
return f'{current_process().name} says that {func.__name__}{args} = {result}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calculate refactored with the following changes:


#
# Functions referenced by tasks
Expand Down Expand Up @@ -51,24 +50,24 @@ def test():
task_queue.put(task)

# Start worker processes
for i in range(NUMBER_OF_PROCESSES):
for _ in range(NUMBER_OF_PROCESSES):
Process(target=worker, args=(task_queue, done_queue)).start()

# Get and print results
print('Unordered results:')
for i in range(len(TASKS1)):
for _ in TASKS1:
Comment on lines -54 to +58
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test refactored with the following changes:

print('\t', done_queue.get())

# Add more tasks using `put()`
for task in TASKS2:
task_queue.put(task)

# Get and print some more results
for i in range(len(TASKS2)):
for _ in range(len(TASKS2)):
print('\t', done_queue.get())

# Tell child processes to stop
for i in range(NUMBER_OF_PROCESSES):
for _ in range(NUMBER_OF_PROCESSES):
task_queue.put('STOP')


Expand Down
2 changes: 1 addition & 1 deletion Doc/includes/ndiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def fopen(fname):
try:
return open(fname)
except IOError as detail:
return fail("couldn't open " + fname + ": " + str(detail))
return fail(f"couldn't open {fname}: {str(detail)}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fopen refactored with the following changes:


# open two files & spray the diff to stdout; return false iff a problem
def fcompare(f1name, f2name):
Expand Down
26 changes: 6 additions & 20 deletions Doc/includes/tzinfo_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
import time as _time

STDOFFSET = timedelta(seconds = -_time.timezone)
if _time.daylight:
DSTOFFSET = timedelta(seconds = -_time.altzone)
else:
DSTOFFSET = STDOFFSET

DSTOFFSET = timedelta(seconds=-_time.altzone) if _time.daylight else STDOFFSET
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 14-18 refactored with the following changes:

DSTDIFF = DSTOFFSET - STDOFFSET

class LocalTimezone(tzinfo):
Expand All @@ -31,16 +27,10 @@ def fromutc(self, dt):
tzinfo=self, fold=fold)

def utcoffset(self, dt):
if self._isdst(dt):
return DSTOFFSET
else:
return STDOFFSET
return DSTOFFSET if self._isdst(dt) else STDOFFSET
Comment on lines -34 to +30
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LocalTimezone.utcoffset refactored with the following changes:


def dst(self, dt):
if self._isdst(dt):
return DSTDIFF
else:
return ZERO
return DSTDIFF if self._isdst(dt) else ZERO
Comment on lines -40 to +33
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LocalTimezone.dst refactored with the following changes:


def tzname(self, dt):
return _time.tzname[self._isdst(dt)]
Expand All @@ -59,8 +49,7 @@ def _isdst(self, dt):
# A complete implementation of current DST rules for major US time zones.

def first_sunday_on_or_after(dt):
days_to_go = 6 - dt.weekday()
if days_to_go:
if days_to_go := 6 - dt.weekday():
Comment on lines -62 to +52
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function first_sunday_on_or_after refactored with the following changes:

dt += timedelta(days_to_go)
return dt

Expand Down Expand Up @@ -93,7 +82,7 @@ def first_sunday_on_or_after(dt):
def us_dst_range(year):
# Find start and end times for US DST. For years before 1967, return
# start = end for no DST.
if 2006 < year:
if year > 2006:
Comment on lines -96 to +85
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function us_dst_range refactored with the following changes:

dststart, dstend = DSTSTART_2007, DSTEND_2007
elif 1986 < year < 2007:
dststart, dstend = DSTSTART_1987_2006, DSTEND_1987_2006
Expand All @@ -119,10 +108,7 @@ def __repr__(self):
return self.reprname

def tzname(self, dt):
if self.dst(dt):
return self.dstname
else:
return self.stdname
return self.dstname if self.dst(dt) else self.stdname
Comment on lines -122 to +111
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function USTimeZone.tzname refactored with the following changes:


def utcoffset(self, dt):
return self.stdoffset + self.dst(dt)
Expand Down
Loading