You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a note to myself. While looking at another issue I noticed that I never completed the work to make sure that all message defects discovered by feedparser are passed through the policy defect handler. The fix is simple, the time consuming part is writing the tests.
In particular, I noticed InvalidHeaderDefect is not raised if a header line begins with a colon (:), and also MisplacedEnvelopeHeaderDefect, if a header line begins "From ", including a space, and is neither the first or last line of the header section.
Here is a patch to fix the two defects in Lib/email/feedparser.py. I also made some extra changes to the tests:
Remove some tests from Lib/test/test_email/test_email.py, because I think they were redundant with methods of the same name in test_defect_handling.py.
Change a couple of the tests in test_defect_handling.py to verify there are no defects recorded at all even in raise_on_defect=True mode.
test_email/test_email tests the compat32 policy. test_defect_handling tests the default policy. Thus they are not redundant, except of course that they are...it would be better to run the same test with both policies in turn, but I never got as far as setting up that infrastructure.
That said, for defects it may not matter, and for the other "redudant" tests sometimes the result is different, which is the point of the new policy. So, things are in a bit of a limbo currently and could use some sorting out. You'll note that in some cases in test_email I've noted where the corresponding test for the new policy is in the new test files. There are a bunch more tests in test_email that need equivalents for the new policies (and I'm sure we'll find some bugs when that happens, unfortunately).
I see that âcompat32â and âdefaultâ are actually different things (Compat32 vs EmailPolicy classes). IMO âdefaultâ was a bad choice of name, but I guess that ship has already sailed.
This patch adds a test_defect_handling.TestCompat32 subclass, so the test methods are now run with compat32 as well as the âdefaultâ policy.
The name default is future proofing. It will be the default...eventually :) And it is the default now if you use EmailMessage to construct your messages.
Activity
bitdancer commentedon Jun 2, 2015
This is a note to myself. While looking at another issue I noticed that I never completed the work to make sure that all message defects discovered by feedparser are passed through the policy defect handler. The fix is simple, the time consuming part is writing the tests.
vadmium commentedon Jun 16, 2016
In particular, I noticed InvalidHeaderDefect is not raised if a header line begins with a colon (:), and also MisplacedEnvelopeHeaderDefect, if a header line begins "From ", including a space, and is neither the first or last line of the header section.
vadmium commentedon Jun 20, 2016
Here is a patch to fix the two defects in Lib/email/feedparser.py. I also made some extra changes to the tests:
Remove some tests from Lib/test/test_email/test_email.py, because I think they were redundant with methods of the same name in test_defect_handling.py.
Change a couple of the tests in test_defect_handling.py to verify there are no defects recorded at all even in raise_on_defect=True mode.
bitdancer commentedon Jun 21, 2016
test_email/test_email tests the compat32 policy. test_defect_handling tests the default policy. Thus they are not redundant, except of course that they are...it would be better to run the same test with both policies in turn, but I never got as far as setting up that infrastructure.
That said, for defects it may not matter, and for the other "redudant" tests sometimes the result is different, which is the point of the new policy. So, things are in a bit of a limbo currently and could use some sorting out. You'll note that in some cases in test_email I've noted where the corresponding test for the new policy is in the new test files. There are a bunch more tests in test_email that need equivalents for the new policies (and I'm sure we'll find some bugs when that happens, unfortunately).
vadmium commentedon Jun 25, 2016
I see that âcompat32â and âdefaultâ are actually different things (Compat32 vs EmailPolicy classes). IMO âdefaultâ was a bad choice of name, but I guess that ship has already sailed.
This patch adds a test_defect_handling.TestCompat32 subclass, so the test methods are now run with compat32 as well as the âdefaultâ policy.
bitdancer commentedon Jun 25, 2016
The name default is future proofing. It will be the default...eventually :) And it is the default now if you use EmailMessage to construct your messages.
MaxwellDupre commentedon Dec 24, 2021
Yuheng3107 commentedon Jul 29, 2025
Is this issue still open to contributions?
gh-68552: fix defects policy (#138579)
bitdancer commentedon Dec 6, 2025
Thanks for taking care of this long overdue issue.
pythongh-68552: fix defects policy (pythonGH-138579)
pythongh-68552: fix defects policy (pythonGH-138579)
[3.14] gh-68552: fix defects policy (GH-138579) (#142366)
[3.13] gh-68552: fix defects policy (GH-138579) (#142367)