From 9583f64e9183d8d8fedaf83f4cd9dcd87172587e Mon Sep 17 00:00:00 2001 From: Andrei Daraschenka Date: Fri, 15 Nov 2019 09:19:48 +0300 Subject: [PATCH 1/3] Fix format string --- Doc/includes/email-dir.py | 3 ++- Doc/includes/email-simple.py | 2 +- Doc/includes/email-unpack.py | 2 +- .../Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst diff --git a/Doc/includes/email-dir.py b/Doc/includes/email-dir.py index 0dcfbfb4025c85..a2635d6d4ba87e 100644 --- a/Doc/includes/email-dir.py +++ b/Doc/includes/email-dir.py @@ -39,9 +39,10 @@ def main(): directory = args.directory if not directory: directory = '.' + context = os.path.abspath(directory) # Create the message msg = EmailMessage() - msg['Subject'] = 'Contents of directory %s' % os.path.abspath(directory) + msg['Subject'] = 'Contents of directory {}'.format(context) msg['To'] = ', '.join(args.recipients) msg['From'] = args.sender msg.preamble = 'You will not see this in a MIME-aware mail reader.\n' diff --git a/Doc/includes/email-simple.py b/Doc/includes/email-simple.py index f69ef40ff04c93..074e7d82b0e948 100644 --- a/Doc/includes/email-simple.py +++ b/Doc/includes/email-simple.py @@ -12,7 +12,7 @@ # me == the sender's email address # you == the recipient's email address -msg['Subject'] = 'The contents of %s' % textfile +msg['Subject'] = 'The contents of {}'.format(textfile) msg['From'] = me msg['To'] = you diff --git a/Doc/includes/email-unpack.py b/Doc/includes/email-unpack.py index e0a7f01f58bb59..57d4557ad4a1b2 100644 --- a/Doc/includes/email-unpack.py +++ b/Doc/includes/email-unpack.py @@ -43,7 +43,7 @@ def main(): if not ext: # Use a generic bag-of-bits extension ext = '.bin' - filename = 'part-%03d%s' % (counter, ext) + filename = 'part-{:03}{}'.format(counter, ext) counter += 1 with open(os.path.join(args.directory, filename), 'wb') as fp: fp.write(part.get_payload(decode=True)) diff --git a/Misc/NEWS.d/next/Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst b/Misc/NEWS.d/next/Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst new file mode 100644 index 00000000000000..78ad5d10356be8 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst @@ -0,0 +1 @@ +Modernize email example from %-formatting to f-string From 2c4c97b84aa29eca1fc1bbbab32a07220c9d2daf Mon Sep 17 00:00:00 2001 From: Andrei Daraschenka Date: Fri, 15 Nov 2019 09:58:40 +0300 Subject: [PATCH 2/3] Update after review --- Doc/includes/email-dir.py | 2 +- Doc/includes/email-simple.py | 2 +- Doc/includes/email-unpack.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/includes/email-dir.py b/Doc/includes/email-dir.py index a2635d6d4ba87e..47577372081311 100644 --- a/Doc/includes/email-dir.py +++ b/Doc/includes/email-dir.py @@ -42,7 +42,7 @@ def main(): context = os.path.abspath(directory) # Create the message msg = EmailMessage() - msg['Subject'] = 'Contents of directory {}'.format(context) + msg['Subject'] = f'Contents of directory {context}' msg['To'] = ', '.join(args.recipients) msg['From'] = args.sender msg.preamble = 'You will not see this in a MIME-aware mail reader.\n' diff --git a/Doc/includes/email-simple.py b/Doc/includes/email-simple.py index 074e7d82b0e948..07dc30fd066eac 100644 --- a/Doc/includes/email-simple.py +++ b/Doc/includes/email-simple.py @@ -12,7 +12,7 @@ # me == the sender's email address # you == the recipient's email address -msg['Subject'] = 'The contents of {}'.format(textfile) +msg['Subject'] = f'The contents of {textfile}' msg['From'] = me msg['To'] = you diff --git a/Doc/includes/email-unpack.py b/Doc/includes/email-unpack.py index 57d4557ad4a1b2..8028b5c10c432e 100644 --- a/Doc/includes/email-unpack.py +++ b/Doc/includes/email-unpack.py @@ -43,7 +43,7 @@ def main(): if not ext: # Use a generic bag-of-bits extension ext = '.bin' - filename = 'part-{:03}{}'.format(counter, ext) + filename = f'part-{counter:03}{ext}' counter += 1 with open(os.path.join(args.directory, filename), 'wb') as fp: fp.write(part.get_payload(decode=True)) From d417827f0fd95c9bed9d101ac1874a462b37006a Mon Sep 17 00:00:00 2001 From: Andrei Daraschenka Date: Fri, 15 Nov 2019 10:52:53 +0300 Subject: [PATCH 3/3] Update after review --- Doc/includes/email-dir.py | 3 +-- Doc/includes/email-unpack.py | 2 +- .../Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/includes/email-dir.py b/Doc/includes/email-dir.py index 47577372081311..2fc1570e654db6 100644 --- a/Doc/includes/email-dir.py +++ b/Doc/includes/email-dir.py @@ -39,10 +39,9 @@ def main(): directory = args.directory if not directory: directory = '.' - context = os.path.abspath(directory) # Create the message msg = EmailMessage() - msg['Subject'] = f'Contents of directory {context}' + msg['Subject'] = f'Contents of directory {os.path.abspath(directory)}' msg['To'] = ', '.join(args.recipients) msg['From'] = args.sender msg.preamble = 'You will not see this in a MIME-aware mail reader.\n' diff --git a/Doc/includes/email-unpack.py b/Doc/includes/email-unpack.py index 8028b5c10c432e..c8cb0be4560830 100644 --- a/Doc/includes/email-unpack.py +++ b/Doc/includes/email-unpack.py @@ -43,7 +43,7 @@ def main(): if not ext: # Use a generic bag-of-bits extension ext = '.bin' - filename = f'part-{counter:03}{ext}' + filename = f'part-{counter:03d}{ext}' counter += 1 with open(os.path.join(args.directory, filename), 'wb') as fp: fp.write(part.get_payload(decode=True)) diff --git a/Misc/NEWS.d/next/Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst b/Misc/NEWS.d/next/Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst index 78ad5d10356be8..8e0dc9eb4ca2f4 100644 --- a/Misc/NEWS.d/next/Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst +++ b/Misc/NEWS.d/next/Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst @@ -1 +1 @@ -Modernize email example from %-formatting to f-string +Modernize :mod:`email` examples from %-formatting to f-strings. \ No newline at end of file