Compare commits

...

4 Commits

Author SHA1 Message Date
Zackery Spytz c56988b88f
bpo-42770: Fix a typo in the email.headerregistry docs (GH-23982)
Automerge-Triggered-By: GH:zware
2020-12-28 20:12:37 -08:00
Ken Jin efb1f0918f
bpo-42740: Support PEP 604, 612 for typing.py get_args and get_origin (GH-23942) 2020-12-28 18:26:19 -08:00
Pablo Galindo a6d63a20df
Fix compiler warnings regarding loss of data (GH-23983) 2020-12-29 00:28:09 +00:00
Pablo Galindo 290f5ae997
Use Py_NewRef in Modules/_struct.c (GH-23981) 2020-12-28 23:59:16 +00:00
7 changed files with 19 additions and 6 deletions

View File

@ -289,7 +289,7 @@ variant, :attr:`~.BaseHeader.max_count` is set to 1.
A :class:`ParameterizedMIMEHeader` class that handles the A :class:`ParameterizedMIMEHeader` class that handles the
:mailheader:`Content-Disposition` header. :mailheader:`Content-Disposition` header.
.. attribute:: content-disposition .. attribute:: content_disposition
``inline`` and ``attachment`` are the only valid values in common use. ``inline`` and ``attachment`` are the only valid values in common use.

View File

@ -3021,6 +3021,7 @@ class GetUtilitiesTestCase(TestCase):
self.assertIs(get_origin(Callable), collections.abc.Callable) self.assertIs(get_origin(Callable), collections.abc.Callable)
self.assertIs(get_origin(list[int]), list) self.assertIs(get_origin(list[int]), list)
self.assertIs(get_origin(list), None) self.assertIs(get_origin(list), None)
self.assertIs(get_origin(list | str), types.Union)
def test_get_args(self): def test_get_args(self):
T = TypeVar('T') T = TypeVar('T')
@ -3053,6 +3054,11 @@ class GetUtilitiesTestCase(TestCase):
self.assertEqual(get_args(collections.abc.Callable[[], str]), ([], str)) self.assertEqual(get_args(collections.abc.Callable[[], str]), ([], str))
self.assertEqual(get_args(collections.abc.Callable[[int], str]), self.assertEqual(get_args(collections.abc.Callable[[int], str]),
get_args(Callable[[int], str])) get_args(Callable[[int], str]))
P = ParamSpec('P')
self.assertEqual(get_args(Callable[P, int]), (P, int))
self.assertEqual(get_args(Callable[Concatenate[int, P], int]),
(Concatenate[int, P], int))
self.assertEqual(get_args(list | str), (list, str))
class CollectionsAbcTests(BaseTestCase): class CollectionsAbcTests(BaseTestCase):

View File

@ -1668,6 +1668,8 @@ def get_origin(tp):
return tp.__origin__ return tp.__origin__
if tp is Generic: if tp is Generic:
return Generic return Generic
if isinstance(tp, types.Union):
return types.Union
return None return None
@ -1686,9 +1688,13 @@ def get_args(tp):
return (tp.__origin__,) + tp.__metadata__ return (tp.__origin__,) + tp.__metadata__
if isinstance(tp, (_GenericAlias, GenericAlias)): if isinstance(tp, (_GenericAlias, GenericAlias)):
res = tp.__args__ res = tp.__args__
if tp.__origin__ is collections.abc.Callable and res[0] is not Ellipsis: if (tp.__origin__ is collections.abc.Callable
and not (res[0] is Ellipsis
or isinstance(res[0], (ParamSpec, _ConcatenateGenericAlias)))):
res = (list(res[:-1]), res[-1]) res = (list(res[:-1]), res[-1])
return res return res
if isinstance(tp, types.Union):
return tp.__args__
return () return ()

View File

@ -0,0 +1,2 @@
:func:`typing.get_args` and :func:`typing.get_origin` now support :pep:`604`
union types and :pep:`612` additions to ``Callable``.

View File

@ -1601,7 +1601,7 @@ pysqlite_connection_backup_impl(pysqlite_Connection *self,
{ {
int rc; int rc;
int callback_error = 0; int callback_error = 0;
int sleep_ms = sleep * 1000.0; int sleep_ms = (int)(sleep * 1000.0);
sqlite3 *bck_conn; sqlite3 *bck_conn;
sqlite3_backup *bck_handle; sqlite3_backup *bck_handle;

View File

@ -1442,8 +1442,7 @@ s_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self = alloc_func(type, 0); self = alloc_func(type, 0);
if (self != NULL) { if (self != NULL) {
PyStructObject *s = (PyStructObject*)self; PyStructObject *s = (PyStructObject*)self;
Py_INCREF(Py_None); s->s_format = Py_NewRef(Py_None);
s->s_format = Py_None;
s->s_codes = NULL; s->s_codes = NULL;
s->s_size = -1; s->s_size = -1;
s->s_len = -1; s->s_len = -1;

View File

@ -2302,7 +2302,7 @@ _PyUnicode_FromId(_Py_Identifier *id)
PyInterpreterState *interp = _PyInterpreterState_GET(); PyInterpreterState *interp = _PyInterpreterState_GET();
struct _Py_unicode_ids *ids = &interp->unicode.ids; struct _Py_unicode_ids *ids = &interp->unicode.ids;
int index = _Py_atomic_size_get(&id->index); Py_ssize_t index = _Py_atomic_size_get(&id->index);
if (index < 0) { if (index < 0) {
struct _Py_unicode_runtime_ids *rt_ids = &interp->runtime->unicode_ids; struct _Py_unicode_runtime_ids *rt_ids = &interp->runtime->unicode_ids;