summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-01-04 03:22:53 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-01-04 03:22:53 (GMT)
commite0734e7dc0dcccc91ed657191b804b3a846ad3f6 (patch)
tree70cb770b9fb3fbca03fcbb1a53df10f69612a78b /Lib/test
parent123d5c9396a6c12d418bbdf6d7ec861537f4c199 (diff)
downloadcpython-e0734e7dc0dcccc91ed657191b804b3a846ad3f6.zip
cpython-e0734e7dc0dcccc91ed657191b804b3a846ad3f6.tar.gz
cpython-e0734e7dc0dcccc91ed657191b804b3a846ad3f6.tar.bz2
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing. * Using property() to make _fields read-only wasn't a good idea. It caused len(Point._fields) to fail. * Add note to _cast() about length checking and alternative with the star-operator.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py9
1 files changed, 1 insertions, 8 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index edffbbe..5e71399 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -17,6 +17,7 @@ class TestNamedTuple(unittest.TestCase):
self.assertEqual(Point.__slots__, ())
self.assertEqual(Point.__module__, __name__)
self.assertEqual(Point.__getitem__, tuple.__getitem__)
+ self.assertEqual(Point._fields, ('x', 'y'))
self.assertRaises(ValueError, namedtuple, 'abc%', 'efg ghi') # type has non-alpha char
self.assertRaises(ValueError, namedtuple, 'class', 'efg ghi') # type has keyword
@@ -51,14 +52,6 @@ class TestNamedTuple(unittest.TestCase):
self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method
self.assertEqual(p._asdict(), dict(x=11, y=22)) # test _asdict method
- # Verify that _fields is read-only
- try:
- p._fields = ('F1' ,'F2')
- except AttributeError:
- pass
- else:
- self.fail('The _fields attribute needs to be read-only')
-
# verify that field string can have commas
Point = namedtuple('Point', 'x, y')
p = Point(x=11, y=22)