]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38351: Modernize email examples from %-formatting to f-strings (GH-17162)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 15 Nov 2019 09:14:44 +0000 (01:14 -0800)
committerGitHub <noreply@github.com>
Fri, 15 Nov 2019 09:14:44 +0000 (01:14 -0800)
(cherry picked from commit e8acc865a3f112b98417f676c897ca6ec2dac2c7)

Co-authored-by: Andrey Doroschenko <dorosch.github.io@yandex.ru>
Doc/includes/email-dir.py
Doc/includes/email-simple.py
Doc/includes/email-unpack.py
Misc/NEWS.d/next/Documentation/2019-11-15-09-22-28.bpo-38351.xwhlse.rst [new file with mode: 0644]

index 0dcfbfb4025c851266f3fa7b4524830bad5687e1..2fc1570e654db6ab5650f7b8857c2570aaebdbdb 100644 (file)
@@ -41,7 +41,7 @@ must be running an SMTP server.
         directory = '.'
     # Create the message
     msg = EmailMessage()
-    msg['Subject'] = 'Contents of directory %s' % os.path.abspath(directory)
+    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'
index f69ef40ff04c9343c43237f4ce3fd12f179b5c2d..07dc30fd066eace9063de73d99c24723b230bf6b 100644 (file)
@@ -12,7 +12,7 @@ with open(textfile) as fp:
 
 # me == the sender's email address
 # you == the recipient's email address
-msg['Subject'] = 'The contents of %s' % textfile
+msg['Subject'] = f'The contents of {textfile}'
 msg['From'] = me
 msg['To'] = you
 
index e0a7f01f58bb59078e58b00112eda388117b8294..c8cb0be45608308616328960460a761a7f8757ab 100644 (file)
@@ -43,7 +43,7 @@ Unpack a MIME message into a directory of files.
             if not ext:
                 # Use a generic bag-of-bits extension
                 ext = '.bin'
-            filename = 'part-%03d%s' % (counter, 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
new file mode 100644 (file)
index 0000000..8e0dc9e
--- /dev/null
@@ -0,0 +1 @@
+Modernize :mod:`email` examples from %-formatting to f-strings.
\ No newline at end of file