Skip to content

Commit

Permalink
Merge branch 'main' into tvkw
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Oct 12, 2023
2 parents fb598e7 + 2c472a8 commit 7558e8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ Data Types
>>> PowersOfThree.SECOND.value
9

.. method:: Enum.__init_subclass__(cls, \**kwds)
.. method:: Enum.__init_subclass__(cls, **kwds)

A *classmethod* that is used to further configure subsequent subclasses.
By default, does nothing.
Expand Down
12 changes: 7 additions & 5 deletions Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import os
import re
import time
import random
import socket
import datetime
import urllib.parse

Expand All @@ -36,9 +34,6 @@

from email._parseaddr import parsedate, parsedate_tz, _parsedate_tz

# Intrapackage imports
from email.charset import Charset

COMMASPACE = ', '
EMPTYSTRING = ''
UEMPTYSTRING = ''
Expand Down Expand Up @@ -94,6 +89,8 @@ def formataddr(pair, charset='utf-8'):
name.encode('ascii')
except UnicodeEncodeError:
if isinstance(charset, str):
# lazy import to improve module import time
from email.charset import Charset
charset = Charset(charset)
encoded_name = charset.header_encode(name)
return "%s <%s>" % (encoded_name, address)
Expand Down Expand Up @@ -181,6 +178,11 @@ def make_msgid(idstring=None, domain=None):
portion of the message id after the '@'. It defaults to the locally
defined hostname.
"""
# Lazy imports to speedup module import time
# (no other functions in email.utils need these modules)
import random
import socket

timeval = int(time.time()*100)
pid = os.getpid()
randint = random.getrandbits(64)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Reduce the import time of :mod:`email.utils` by around 43%. This results in
the import time of :mod:`email.message` falling by around 18%, which in turn
reduces the import time of :mod:`importlib.metadata` by around 6%. Patch by
Alex Waygood.

0 comments on commit 7558e8e

Please sign in to comment.