Skip to content

Commit 9060f0b

Browse files
committed
Remove fast-path __new__ for newdict; add explicit comments for newbytes and newstr
1 parent b89477c commit 9060f0b

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

future/tests/test_dict.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ def test_dict_empty(self):
2222
"""
2323
self.assertEqual(dict(), {})
2424

25+
def test_dict_dict(self):
26+
"""
27+
Exrapolated from issue #50 -- newlist(newlist([...]))
28+
"""
29+
d = dict({1: 2, 2: 4, 3: 9})
30+
d2 = dict(d)
31+
self.assertEqual(len(d2), 3)
32+
self.assertEqual(d2, d)
33+
self.assertTrue(isinstance(d2, dict))
34+
self.assertTrue(type(d2) == dict)
35+
2536
def test_dict_eq(self):
2637
d = self.d1
2738
self.assertEqual(dict(d), d)

future/types/newbytes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def __new__(cls, *args, **kwargs):
6060
# this to be True for all unicode string subclasses. Warning:
6161
# This may render newstr un-subclassable.
6262
if type(args[0]) == newbytes:
63+
# Special-case: for consistency with Py3.3, we return the same object
64+
# (with the same id) if a newbytes object is passed into the
65+
# newbytes constructor.
6366
return args[0]
6467
elif isinstance(args[0], _builtin_bytes):
6568
value = args[0]

future/types/newdict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __new__(cls, *args, **kwargs):
9191
if len(args) == 0:
9292
return super(newdict, cls).__new__(cls)
9393
elif type(args[0]) == newdict:
94-
return args[0]
94+
value = args[0]
9595
else:
9696
value = args[0]
9797
return super(newdict, cls).__new__(cls, value)

future/types/newstr.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def __new__(cls, *args, **kwargs):
8282
if len(args) == 0:
8383
return super(newstr, cls).__new__(cls)
8484
# Special case: If someone requests str(str(u'abc')), return the same
85-
# object (same id) for consistency with Py3.3
85+
# object (same id) for consistency with Py3.3. This is not true for
86+
# other objects like list or dict.
8687
elif type(args[0]) == newstr and cls == newstr:
8788
return args[0]
8889
elif isinstance(args[0], unicode):

0 commit comments

Comments
 (0)