diff options
author | Raymond Hettinger <python@rcn.com> | 2013-05-18 00:14:27 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-05-18 00:14:27 (GMT) |
commit | 4e0172fd9acf7c5e8f30905fc997f904adbe562f (patch) | |
tree | 4b3d9a89af022af0b132a00e73d41fb24a63f36d /Lib | |
parent | 8c03d832b33e02b575b78d53406a3f1ee2706f8d (diff) | |
download | cpython-4e0172fd9acf7c5e8f30905fc997f904adbe562f.zip cpython-4e0172fd9acf7c5e8f30905fc997f904adbe562f.tar.gz cpython-4e0172fd9acf7c5e8f30905fc997f904adbe562f.tar.bz2 |
Deprecate nametuple._asdict()
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/collections/__init__.py | 3 | ||||
-rw-r--r-- | Lib/test/test_collections.py | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 5fd54e8..24daa34 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -280,6 +280,9 @@ class {typename}(tuple): '''Return a new OrderedDict which maps field names to their values. This method is obsolete. Use vars(nt) or nt.__dict__ instead. ''' + import warnings + warnings.warn('_asdict() is deprecated. Use vars(nt) instead.', + DeprecationWarning, stacklevel=2) return self.__dict__ def __getnewargs__(self): diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 8033031..12bd952 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -217,8 +217,11 @@ class TestNamedTuple(unittest.TestCase): self.assertEqual(p, Point._make([11, 22])) # test _make classmethod self.assertEqual(p._fields, ('x', 'y')) # test _fields attribute self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method - self.assertEqual(p._asdict(), dict(x=11, y=22)) # test _asdict method - self.assertEqual(vars(p), p._asdict()) # verify that vars() works + self.assertEqual(p.__dict__, + OrderedDict([('x', 11), ('y', 22)])) # test __dict__ attribute + self.assertEqual(vars(p), p.__dict__) # verify that vars() works + with self.assertWarns(DeprecationWarning): # check deprecate of _asdict + p._asdict() try: p._replace(x=1, error=2) |