summaryrefslogtreecommitdiff
path: root/Lib/collections/__init__.py
diff options
context:
space:
mode:
authordoko <doko@ubuntu.com>2017-01-31 13:35:26 +0100
committerdoko <doko@ubuntu.com>2017-01-31 13:35:26 +0100
commite0cb38ac4330d5e09b5e21c74c5d5e453af99a4f (patch)
treea64fe56edb37bb84d4ffea1990c0ac124a6dba9d /Lib/collections/__init__.py
parentd7764ed2a9255ddb5bdb7d3f184610cdc7a66aad (diff)
parent602663ac0effc2e8e3b615141babd95ed7691dda (diff)
downloadcpython-e0cb38ac4330d5e09b5e21c74c5d5e453af99a4f.tar.gz
merge 3.5
Diffstat (limited to 'Lib/collections/__init__.py')
-rw-r--r--Lib/collections/__init__.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index bea811db7f..85b4c3c19a 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -356,7 +356,7 @@ _field_template = '''\
{name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}')
'''
-def namedtuple(typename, field_names, verbose=False, rename=False):
+def namedtuple(typename, field_names, *, verbose=False, rename=False, module=None):
"""Returns a new subclass of tuple with named fields.
>>> Point = namedtuple('Point', ['x', 'y'])
@@ -396,7 +396,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
field_names[index] = '_%d' % index
seen.add(name)
for name in [typename] + field_names:
- if type(name) != str:
+ if type(name) is not str:
raise TypeError('Type names and field names must be strings')
if not name.isidentifier():
raise ValueError('Type names and field names must be valid '
@@ -437,11 +437,15 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
# For pickling to work, the __module__ variable needs to be set to the frame
# where the named tuple is created. Bypass this step in environments where
# sys._getframe is not defined (Jython for example) or sys._getframe is not
- # defined for arguments greater than 0 (IronPython).
- try:
- result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
- except (AttributeError, ValueError):
- pass
+ # defined for arguments greater than 0 (IronPython), or where the user has
+ # specified a particular module.
+ if module is None:
+ try:
+ module = _sys._getframe(1).f_globals.get('__name__', '__main__')
+ except (AttributeError, ValueError):
+ pass
+ if module is not None:
+ result.__module__ = module
return result
@@ -845,7 +849,7 @@ class Counter(dict):
########################################################################
-### ChainMap (helper for configparser and string.Template)
+### ChainMap
########################################################################
class ChainMap(MutableMapping):
@@ -972,7 +976,7 @@ class UserDict(MutableMapping):
dict = kwargs.pop('dict')
import warnings
warnings.warn("Passing 'dict' as keyword argument is deprecated",
- PendingDeprecationWarning, stacklevel=2)
+ DeprecationWarning, stacklevel=2)
else:
dict = None
self.data = {}