8000 Merge pull request #542 from python/main · sthagen/python-cpython@13e7551 · GitHub
[go: up one dir, main page]

Skip to content

Commit 13e7551

Browse files
authored
Merge pull request #542 from python/main
Sync Fork from Upstream Repo
2 parents f209a64 + bce1418 commit 13e7551

File tree

6 files changed

+81
-1
lines changed

6 files changed

+81
-1
lines changed

Lib/email/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def formataddr(pair, charset='utf-8'):
109109

110110
def getaddresses(fieldvalues):
111111
"""Return a list of (REALNAME, EMAIL) for each fieldvalue."""
112-
all = COMMASPACE.join(fieldvalues)
112+
all = COMMASPACE.join(str(v) for v in fieldvalues)
113113
a = _AddressList(all)
114114
return a.addresslist
115115

Lib/test/test_email/test_email.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,6 +3263,11 @@ def test_getaddresses_embedded_comment(self):
32633263
addrs = utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
32643264
eq(addrs[0][1], 'foo@bar.com')
32653265

3266+
def test_getaddresses_header_obj(self):
3267+
"""Test the handling of a Header object."""
3268+
addrs = utils.getaddresses([Header('Al Person <aperson@dom.ain>')])
3269+
self.assertEqual(addrs[0][1], 'aperson@dom.ain')
3270+
32663271
def test_make_msgid_collisions(self):
32673272
# Test make_msgid uniqueness, even with multiple threads
32683273
class MsgidsThread(Thread):

Lib/test/test_typing.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4498,6 +4498,67 @@ def test_no_isinstance(self):
44984498
issubclass(int, TypeGuard)
44994499

45004500

4501+
class SpecialAttrsTests(BaseTestCase):
4502+
def test_special_attrs(self):
4503+
cls_to_check = (
4504+
# ABC classes
4505+
typing.AbstractSet,
4506+
typing.AsyncContextManager,
4507+
typing.AsyncGenerator,
4508+
typing.AsyncIterable,
4509+
typing.AsyncIterator,
4510+
typing.Awaitable,
4511+
typing.ByteString,
4512+
typing.Callable,
4513+
typing.ChainMap,
4514+
typing.Collection,
4515+
typing.Container,
4516+
typing.ContextManager,
4517+
typing.Coroutine,
4518+
typing.Counter,
4519+
typing.DefaultDict,
4520+
typing.Deque,
4521+
typing.Dict,
4522+
typing.FrozenSet,
4523+
typing.Generator,
4524+
typing.Hashable,
4525+
typing.ItemsView,
4526+
typing.Iterable,
4527+
typing.Iterator,
4528+
typing.KeysView,
4529+
typing.List,
4530+
typing.Mapping,
4531+
typing.MappingView,
4532+
typing.MutableMapping,
4533+
typing.MutableSequence,
4534+
typing.MutableSet,
4535+
typing.OrderedDict,
4536+
typing.Reversible,
4537+
typing.Sequence,
4538+
typing.Set,
4539+
typing.Sized,
4540+
typing.Tuple,
4541+
typing.Type,
4542+
typing.ValuesView,
4543+
# Special Forms
4544+
typing.Any,
4545+
typing.NoReturn,
4546+
typing.ClassVar,
4547+
typing.Final,
4548+
typing.Union,
4549+
typing.Optional,
4550+
typing.Literal,
4551+
typing.TypeAlias,
4552+
typing.Concatenate,
4553+
typing.TypeGuard,
4554+
)
4555+
4556+
for cls in cls_to_check:
4557+
with self.subTest(cls=cls):
4558+
self.assertEqual(cls.__name__, cls._name)
4559+
self.assertEqual(cls.__qualname__, cls._name)
4560+
self.assertEqual(cls.__module__, 'typing')
4561+
45014562
class AllTests(BaseTestCase):
45024563
"""Tests for __all__."""
45034564

Lib/typing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ def __init__(self, getitem):
358358
self._name = getitem.__name__
359359
self.__doc__ = getitem.__doc__
360360

361+
def __getattr__(self, item):
362+
if item in {'__name__', '__qualname__'}:
363+
return self._name
364+
365+
raise AttributeError(item)
366+
361367
def __mro_entries__(self, bases):
362368
raise TypeError(f"Cannot subclass {self!r}")
363369

@@ -935,6 +941,9 @@ def __mro_entries__(self, bases):
935941
return tuple(res)
936942

937943
def __getattr__(self, attr):
944+
if attr in {'__name__', '__qualname__'}:
945+
return self._name
946+
938947
# We are careful for copy and pickle.
939948
# Also for simplicity we just don't relay all dunder names
940949
if '__origin__' in self.__dict__ and not _is_dunder(attr):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:func:`email.utils.getaddresses` now accepts
2+
:class:`email.header.Header` objects along with string values.
3+
Patch by Zackery Spytz.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add missing ``__name__`` and ``__qualname__`` attributes to ``typing`` module
2+
classes. Patch provided by Yurii Karabas.

0 commit comments

Comments
 (0)
0