cpython/Lib/email
Michael Selik 2702638eab bpo-34002: Minor efficiency and clarity improvements in email package. (GH-7999)
* Check intersection of two sets explicitly

Comparing ``len(a) > ``len(a - b)`` is essentially looking for an
intersection between the two sets. If set ``b`` does not intersect ``a``
then ``len(a - b)`` will be equal to ``len(a)``. This logic is more
clearly expressed as ``a & b``.

* Change while/pop to a for-loop

Copying the list, then repeatedly popping the first element was
unnecessarily slow. I also cleaned up a couple other inefficiencies.
There's no need to unpack a tuple, then re-pack and append it. The list
can be created with the first element instead of empty. Secondly, the
``endswith`` method returns a bool, so there's no need for an if-
statement to set ``encoding`` to True or False.

* Use set.intersection to check for intersections

``a.intersection(b)`` method is more clear of purpose than ``not
a.isdisjoint(b)`` and avoids an unnecessary set construction that ``a &
set(b)`` performs.

* Use not isdisjoint instead of intersection

While it reads slightly worse, the isdisjoint method will stop when it
finds a counterexample and returns a bool, rather than looping over the
entire iterable and constructing a new set.
2019-09-19 20:25:55 -07:00
..
mime Issue #27445: Merge from 3.5 2016-09-08 19:42:11 +03:00
__init__.py
_encoded_words.py bpo-27397: Make email module properly handle invalid-length base64 strings (#7583) 2018-06-12 15:46:22 +03:00
_header_value_parser.py bpo-37764: Fix infinite loop when parsing unstructured email headers. (GH-15239) 2019-08-31 08:25:35 -07:00
_parseaddr.py bpo-34155: Dont parse domains containing @ (GH-13079) 2019-07-17 14:54:25 -07:00
_policybase.py [email] bpo-29478: Fix passing max_line_length=None from Compat32 policy (GH-595) 2017-06-11 23:43:41 -07:00
architecture.rst Fix typos in multiple `.rst` files (#1668) 2017-05-19 23:37:57 +03:00
base64mime.py Correct misspellings of ISO-8859 2016-08-10 05:25:16 +00:00
charset.py bpo-36793: Remove unneeded __str__ definitions. (GH-13081) 2019-05-06 22:29:40 +03:00
contentmanager.py Merge with 3.5 2016-09-09 12:09:07 -07:00
encoders.py
errors.py bpo-27397: Make email module properly handle invalid-length base64 strings (#7583) 2018-06-12 15:46:22 +03:00
feedparser.py bpo-30835: email: Fix AttributeError when parsing invalid CTE (GH-13598) 2019-06-04 11:00:47 -07:00
generator.py Merge: #19003: Only replace \r and/or \n line endings in email.generator. 2016-09-11 17:23:33 -04:00
header.py bpo-27737: Allow whitespace only headers encoding (#13478) 2019-05-22 21:13:16 -04:00
headerregistry.py bpo-34002: Minor efficiency and clarity improvements in email package. (GH-7999) 2019-09-19 20:25:55 -07:00
iterators.py
message.py bpo-33972: Fix EmailMessage.iter_attachments raising AttributeError. (GH-14119) 2019-06-25 10:03:19 -07:00
parser.py Fix infinite loop in email folding logic (GH-12732) 2019-07-16 10:50:01 -07:00
policy.py bpo-33524: Fix the folding of email header when max_line_length is 0 or None (#13391) 2019-05-17 15:28:44 -04:00
quoprimime.py bpo-32297: Few misspellings found in Python source code comments. (#4803) 2017-12-14 13:04:53 +02:00
utils.py bpo-34002: Minor efficiency and clarity improvements in email package. (GH-7999) 2019-09-19 20:25:55 -07:00