Merge tag 'v3.7.1rc1' into 3.7
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 23a6415..268adc0 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -169,6 +169,8 @@
the call signature by substituting a literal ellipsis
for the list of arguments in the type hint: ``Callable[..., ReturnType]``.
+.. _generics:
+
Generics
--------
@@ -183,7 +185,7 @@
def notify_by_email(employees: Sequence[Employee],
overrides: Mapping[str, str]) -> None: ...
-Generics can be parametrized by using a new factory available in typing
+Generics can be parameterized by using a new factory available in typing
called :class:`TypeVar`.
::
@@ -488,8 +490,9 @@
required to handle this particular case may change in future revisions of
:pep:`484`.
- The only legal parameters for :class:`Type` are classes, unions of classes, and
- :data:`Any`. For example::
+ The only legal parameters for :class:`Type` are classes, :data:`Any`,
+ :ref:`type variables <generics>`, and unions of any of these types.
+ For example::
def new_non_team_user(user_class: Type[Union[BaseUser, ProUser]]): ...
diff --git a/Lib/pickletools.py b/Lib/pickletools.py
index 8486cbf..ed8bee3 100644
--- a/Lib/pickletools.py
+++ b/Lib/pickletools.py
@@ -1325,9 +1325,7 @@
stack_before=[],
stack_after=[pybool],
proto=2,
- doc="""True.
-
- Push True onto the stack."""),
+ doc="Push True onto the stack."),
I(name='NEWFALSE',
code='\x89',
@@ -1335,9 +1333,7 @@
stack_before=[],
stack_after=[pybool],
proto=2,
- doc="""True.
-
- Push False onto the stack."""),
+ doc="Push False onto the stack."),
# Ways to spell Unicode strings.
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 8f91bc9..e7202cd 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -1961,6 +1961,15 @@
with self.assertRaises(TypeError):
type('A', (B,), {'__slots__': '__weakref__'})
+ def test_namespace_order(self):
+ # bpo-34320: namespace should preserve order
+ od = collections.OrderedDict([('a', 1), ('b', 2)])
+ od.move_to_end('a')
+ expected = list(od.items())
+
+ C = type('C', (), od)
+ self.assertEqual(list(C.__dict__.items())[:2], [('b', 2), ('a', 1)])
+
def load_tests(loader, tests, pattern):
from doctest import DocTestSuite
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py
index 3f9987c..362c31c 100644
--- a/Lib/test/test_call.py
+++ b/Lib/test/test_call.py
@@ -9,6 +9,23 @@
import collections
import itertools
+
+class FunctionCalls(unittest.TestCase):
+
+ def test_kwargs_order(self):
+ # bpo-34320: **kwargs should preserve order of passed OrderedDict
+ od = collections.OrderedDict([('a', 1), ('b', 2)])
+ od.move_to_end('a')
+ expected = list(od.items())
+
+ def fn(**kw):
+ return kw
+
+ res = fn(**od)
+ self.assertIsInstance(res, dict)
+ self.assertEqual(list(res.items()), expected)
+
+
# The test cases here cover several paths through the function calling
# code. They depend on the METH_XXX flag that is used to define a C
# function, which can't be verified from Python. If the METH_XXX decl
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 38521bb..90c0a31 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -1222,6 +1222,36 @@
self.assertRaises(RuntimeError, iter_and_mutate)
+ def test_dict_copy_order(self):
+ # bpo-34320
+ od = collections.OrderedDict([('a', 1), ('b', 2)])
+ od.move_to_end('a')
+ expected = list(od.items())
+
+ copy = dict(od)
+ self.assertEqual(list(copy.items()), expected)
+
+ # dict subclass doesn't override __iter__
+ class CustomDict(dict):
+ pass
+
+ pairs = [('a', 1), ('b', 2), ('c', 3)]
+
+ d = CustomDict(pairs)
+ self.assertEqual(pairs, list(dict(d).items()))
+
+ class CustomReversedDict(dict):
+ def keys(self):
+ return reversed(list(dict.keys(self)))
+
+ __iter__ = keys
+
+ def items(self):
+ return reversed(dict.items(self))
+
+ d = CustomReversedDict(pairs)
+ self.assertEqual(pairs[::-1], list(dict(d).items()))
+
class CAPITest(unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-08-02-22-34-59.bpo-34320.hNshAA.rst b/Misc/NEWS.d/next/Core and Builtins/2018-08-02-22-34-59.bpo-34320.hNshAA.rst
new file mode 100644
index 0000000..ce5b339
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-08-02-22-34-59.bpo-34320.hNshAA.rst
@@ -0,0 +1 @@
+Fix ``dict(od)`` didn't copy iteration order of OrderedDict.
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 828eb99..eb63526 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -235,6 +235,8 @@
static int dictresize(PyDictObject *mp, Py_ssize_t minused);
+static PyObject* dict_iter(PyDictObject *dict);
+
/*Global counter used to set ma_version_tag field of dictionary.
* It is incremented each time that a dictionary is created and each
* time that a dictionary is modified. */
@@ -2379,7 +2381,7 @@
return -1;
}
mp = (PyDictObject*)a;
- if (PyDict_Check(b)) {
+ if (PyDict_Check(b) && (Py_TYPE(b)->tp_iter == (getiterfunc)dict_iter)) {
other = (PyDictObject*)b;
if (other == mp || other->ma_used == 0)
/* a.update(a) or a.update({}); nothing to do */
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 141a47a..461e8dc 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -1062,8 +1062,6 @@
else {
/* shouldn't get here: Gay's code should always return
something starting with a digit, an 'I', or 'N' */
- strncpy(p, "ERR", 3);
- /* p += 3; */
Py_UNREACHABLE();
}
goto exit;