[Python-checkins] cpython (3.5): Issue #29011: Fix an important omission by adding Deque to the typing module.
raymond.hettinger
python-checkins at python.org
Tue Jan 17 01:44:21 EST 2017
https://hg.python.org/cpython/rev/dfefbf6f6c73
changeset: 106184:dfefbf6f6c73
branch: 3.5
parent: 106161:f9cb5b8c17b7
user: Raymond Hettinger <python at rcn.com>
date: Mon Jan 16 22:42:37 2017 -0800
summary:
Issue #29011: Fix an important omission by adding Deque to the typing module.
files:
Doc/library/typing.rst | 4 ++++
Lib/test/test_typing.py | 11 +++++++++++
Lib/typing.py | 10 ++++++++++
Misc/NEWS | 20 ++++++++++++++++----
4 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -557,6 +557,10 @@
As a shorthand for this type, :class:`bytes` can be used to
annotate arguments of any of the types mentioned above.
+.. class:: Deque(deque, MutableSequence[T])
+
+ A generic version of :class:`collections.deque`.
+
.. class:: List(list, MutableSequence[T])
Generic version of :class:`list`.
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -1572,6 +1572,9 @@
def test_list(self):
self.assertIsSubclass(list, typing.List)
+ def test_deque(self):
+ self.assertIsSubclass(collections.deque, typing.Deque)
+
def test_set(self):
self.assertIsSubclass(set, typing.Set)
self.assertNotIsSubclass(frozenset, typing.Set)
@@ -1642,6 +1645,14 @@
self.assertIsSubclass(MyDefDict, collections.defaultdict)
self.assertNotIsSubclass(collections.defaultdict, MyDefDict)
+ def test_no_deque_instantiation(self):
+ with self.assertRaises(TypeError):
+ typing.Deque()
+ with self.assertRaises(TypeError):
+ typing.Deque[T]()
+ with self.assertRaises(TypeError):
+ typing.Deque[int]()
+
def test_no_set_instantiation(self):
with self.assertRaises(TypeError):
typing.Set()
diff --git a/Lib/typing.py b/Lib/typing.py
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -59,6 +59,7 @@
'SupportsRound',
# Concrete collection types.
+ 'Deque',
'Dict',
'DefaultDict',
'List',
@@ -1771,6 +1772,15 @@
"use list() instead")
return _generic_new(list, cls, *args, **kwds)
+class Deque(collections.deque, MutableSequence[T], extra=collections.deque):
+
+ __slots__ = ()
+
+ def __new__(cls, *args, **kwds):
+ if _geqv(cls, Deque):
+ raise TypeError("Type Deque cannot be instantiated; "
+ "use deque() instead")
+ return _generic_new(collections.deque, cls, *args, **kwds)
class Set(set, MutableSet[T], extra=set):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2,6 +2,18 @@
Python News
+++++++++++
+What's New in Python 3.5.4?
+===========================
+
+Core and Builtins
+-----------------
+
+Library
+-------
+
+- Issue #29011: Fix an important omission by adding Deque to the typing module.
+
+
What's New in Python 3.5.3?
===========================
@@ -528,17 +540,17 @@
- Issue #27972: Prohibit Tasks to await on themselves.
-- Issue #26923: Fix asyncio.Gather to refuse being cancelled once all
+- Issue #26923: Fix asyncio.Gather to refuse being cancelled once all
children are done.
Patch by Johannes Ebke.
-- Issue #26796: Don't configure the number of workers for default
+- Issue #26796: Don't configure the number of workers for default
threadpool executor.
Initial patch by Hans Lawrenz.
- Issue #28600: Optimize loop.call_soon().
-- Issue #28613: Fix get_event_loop() return the current loop if
+- Issue #28613: Fix get_event_loop() return the current loop if
called from coroutines/callbacks.
- Issue #28639: Fix inspect.isawaitable to always return bool
@@ -553,7 +565,7 @@
- Issue #24142: Reading a corrupt config file left the parser in an
invalid state. Original patch by Florian Höch.
-- Issue #28990: Fix SSL hanging if connection is closed before handshake
+- Issue #28990: Fix SSL hanging if connection is closed before handshake
completed.
(Patch by HoHo-Ho)
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list