@@ -1939,8 +1939,11 @@ def test_fromkeys(self):
19391939 # Subclass which overrides the constructor
19401940 created = frozendict (x = 1 )
19411941 class FrozenDictSubclass (frozendict ):
1942- def __new__ (self ):
1943- return created
1942+ def __new__ (cls , * args , ** kwargs ):
1943+ if args or kwargs :
1944+ return super ().__new__ (cls , * args , ** kwargs )
1945+ else :
1946+ return created
19441947
19451948 fd = FrozenDictSubclass .fromkeys ("abc" )
19461949 self .assertEqual (fd , frozendict (x = 1 , a = None , b = None , c = None ))
@@ -1952,6 +1955,20 @@ def __new__(self):
19521955 self .assertEqual (type (fd ), FrozenDictSubclass )
19531956 self .assertEqual (created , frozendict (x = 1 ))
19541957
1958+ # Dict subclass with a constructor which returns a frozendict
1959+ # by default
1960+ class DictSubclass (dict ):
1961+ def __new__ (cls , * args , ** kwargs ):
1962+ if args or kwargs :
1963+ return super ().__new__ (cls , * args , ** kwargs )
1964+ else :
1965+ return created
1966+
1967+ fd = DictSubclass .fromkeys ("abc" )
1968+ self .assertEqual (fd , frozendict (x = 1 , a = None , b = None , c = None ))
1969+ self .assertEqual (type (fd ), DictSubclass )
1970+ self .assertEqual (created , frozendict (x = 1 ))
1971+
19551972 # Subclass which doesn't override the constructor
19561973 class FrozenDictSubclass2 (frozendict ):
19571974 pass
@@ -1960,16 +1977,6 @@ class FrozenDictSubclass2(frozendict):
19601977 self .assertEqual (fd , frozendict (a = None , b = None , c = None ))
19611978 self .assertEqual (type (fd ), FrozenDictSubclass2 )
19621979
1963- # Dict subclass which overrides the constructor
1964- class DictSubclass (dict ):
1965- def __new__ (self ):
1966- return created
1967-
1968- fd = DictSubclass .fromkeys ("abc" )
1969- self .assertEqual (fd , frozendict (x = 1 , a = None , b = None , c = None ))
1970- self .assertEqual (type (fd ), DictSubclass )
1971- self .assertEqual (created , frozendict (x = 1 ))
1972-
19731980 def test_pickle (self ):
19741981 for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
19751982 for fd in (
0 commit comments