Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def formataddr(pair, charset='utf-8'):

def getaddresses(fieldvalues):
"""Return a list of (REALNAME, EMAIL) for each fieldvalue."""
all = COMMASPACE.join(fieldvalues)
all = COMMASPACE.join(str(v) for v in fieldvalues)
a = _AddressList(all)
return a.addresslist

Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -3263,6 +3263,11 @@ def test_getaddresses_embedded_comment(self):
addrs = utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
eq(addrs[0][1], 'foo@bar.com')

def test_getaddresses_header_obj(self):
"""Test the handling of a Header object."""
addrs = utils.getaddresses([Header('Al Person <aperson@dom.ain>')])
self.assertEqual(addrs[0][1], 'aperson@dom.ain')

def test_make_msgid_collisions(self):
# Test make_msgid uniqueness, even with multiple threads
class MsgidsThread(Thread):
Expand Down
61 changes: 61 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4498,6 +4498,67 @@ def test_no_isinstance(self):
issubclass(int, TypeGuard)


class SpecialAttrsTests(BaseTestCase):
def test_special_attrs(self):
cls_to_check = (
# ABC classes
typing.AbstractSet,
typing.AsyncContextManager,
typing.AsyncGenerator,
typing.AsyncIterable,
typing.AsyncIterator,
typing.Awaitable,
typing.ByteString,
typing.Callable,
typing.ChainMap,
typing.Collection,
typing.Container,
typing.ContextManager,
typing.Coroutine,
typing.Counter,
typing.DefaultDict,
typing.Deque,
typing.Dict,
typing.FrozenSet,
typing.Generator,
typing.Hashable,
typing.ItemsView,
typing.Iterable,
typing.Iterator,
typing.KeysView,
typing.List,
typing.Mapping,
typing.MappingView,
typing.MutableMapping,
typing.MutableSequence,
typing.MutableSet,
typing.OrderedDict,
typing.Reversible,
typing.Sequence,
typing.Set,
typing.Sized,
typing.Tuple,
typing.Type,
typing.ValuesView,
# Special Forms
typing.Any,
typing.NoReturn,
typing.ClassVar,
typing.Final,
typing.Union,
typing.Optional,
typing.Literal,
typing.TypeAlias,
typing.Concatenate,
typing.TypeGuard,
)

for cls in cls_to_check:
with self.subTest(cls=cls):
self.assertEqual(cls.__name__, cls._name)
self.assertEqual(cls.__qualname__, cls._name)
self.assertEqual(cls.__module__, 'typing')

class AllTests(BaseTestCase):
"""Tests for __all__."""

Expand Down
9 changes: 9 additions & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ def __init__(self, getitem):
self._name = getitem.__name__
self.__doc__ = getitem.__doc__

def __getattr__(self, item):
if item in {'__name__', '__qualname__'}:
return self._name

raise AttributeError(item)

def __mro_entries__(self, bases):
raise TypeError(f"Cannot subclass {self!r}")

Expand Down Expand Up @@ -935,6 +941,9 @@ def __mro_entries__(self, bases):
return tuple(res)

def __getattr__(self, attr):
if attr in {'__name__', '__qualname__'}:
return self._name

# We are careful for copy and pickle.
# Also for simplicity we just don't relay all dunder names
if '__origin__' in self.__dict__ and not _is_dunder(attr):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`email.utils.getaddresses` now accepts
:class:`email.header.Header` objects along with string values.
Patch by Zackery Spytz.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add missing ``__name__`` and ``__qualname__`` attributes to ``typing`` module
classes. Patch provided by Yurii Karabas.