diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2023-04-21 02:12:48 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-21 02:12:48 (GMT) |
| commit | 3e0fec7e07a71bdeeab7554e980110fbc47763b9 (patch) | |
| tree | c95fc47a9ee48d5606f4eb6cc45703f7be568769 /Lib/importlib/metadata/_adapters.py | |
| parent | 5c00a6224d55f8818ef567b93f484b5429e2ae80 (diff) | |
| download | cpython-3e0fec7e07a71bdeeab7554e980110fbc47763b9.zip cpython-3e0fec7e07a71bdeeab7554e980110fbc47763b9.tar.gz cpython-3e0fec7e07a71bdeeab7554e980110fbc47763b9.tar.bz2 | |
Sync with importlib_metadata 6.5 (GH-103584)
Diffstat (limited to 'Lib/importlib/metadata/_adapters.py')
| -rw-r--r-- | Lib/importlib/metadata/_adapters.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/importlib/metadata/_adapters.py b/Lib/importlib/metadata/_adapters.py index aa460d3..6aed69a 100644 --- a/Lib/importlib/metadata/_adapters.py +++ b/Lib/importlib/metadata/_adapters.py @@ -1,3 +1,5 @@ +import functools +import warnings import re import textwrap import email.message @@ -5,6 +7,15 @@ import email.message from ._text import FoldedCase +# Do not remove prior to 2024-01-01 or Python 3.14 +_warn = functools.partial( + warnings.warn, + "Implicit None on return values is deprecated and will raise KeyErrors.", + DeprecationWarning, + stacklevel=2, +) + + class Message(email.message.Message): multiple_use_keys = set( map( @@ -39,6 +50,16 @@ class Message(email.message.Message): def __iter__(self): return super().__iter__() + def __getitem__(self, item): + """ + Warn users that a ``KeyError`` can be expected when a + mising key is supplied. Ref python/importlib_metadata#371. + """ + res = super().__getitem__(item) + if res is None: + _warn() + return res + def _repair_headers(self): def redent(value): "Correct for RFC822 indentation" |
