mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Remove assumption that cls is a subclass of dict.
Simplifies the code and gets Just van Rossum's example to work.
This commit is contained in:
parent
4e52ca82ae
commit
e03e5b1f91
2 changed files with 4 additions and 10 deletions
|
|
@ -566,9 +566,9 @@ from UserDict import UserDict
|
|||
class mydict(dict):
|
||||
def __new__(cls, *args, **kwargs):
|
||||
return UserDict(*args, **kwargs)
|
||||
try: mydict.fromkeys('a b c'.split())
|
||||
except TypeError: pass
|
||||
else: raise TestFailed, 'dict.fromkeys() failed to detect non-dict class.'
|
||||
ud = mydict.fromkeys('ab')
|
||||
if ud != {'a':None, 'b':None} or not isinstance(ud,UserDict):
|
||||
raise TestFailed, 'fromkeys did not instantiate using __new__'
|
||||
# dict.copy()
|
||||
d = {1:1, 2:2, 3:3}
|
||||
if d.copy() != {1:1, 2:2, 3:3}: raise TestFailed, 'dict copy'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue