Commit dcb7d25
gh-151454: Accept Header values in email.message.Message.add_header
Message.items() can yield (name, Header) pairs under the compat32 policy
(for a header carrying 8-bit data), and Message[name] = value accepts such
Header values, but add_header() raised "TypeError: sequence item 0: expected
str instance, Header found" because it assembled the value with
SEMISPACE.join().
When no extra parameters are given, add_header() now mirrors __setitem__ and
stores the value (Header or str) unmodified, fixing the reported header-copy
loop. None is still coerced to '' to preserve add_header()'s historical
behavior. The parameterized branch is unchanged: it still builds the header
as a string and so continues to require a str value.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 9ad6ba0 commit dcb7d25
4 files changed
Lines changed: 38 additions & 0 deletions
File tree
- Doc/library
- Lib
- email
- test/test_email
- Misc/NEWS.d/next/Library
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
422 | 431 | | |
423 | 432 | | |
424 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
576 | 576 | | |
577 | 577 | | |
578 | 578 | | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
579 | 586 | | |
580 | 587 | | |
581 | 588 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
839 | 839 | | |
840 | 840 | | |
841 | 841 | | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
842 | 859 | | |
843 | 860 | | |
844 | 861 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments