You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#127 introduces merge operators. However, the current implementation has two problems:
Since Dict is a subclass of dict, is it necessary to check by isinstance(other, (Dict, dict))? Wouldn't isinstance(other, dict) be enough?
| and |= always return Dict instances, even if the operands may be instances of subclasses. To expatiate, consider the following snippet:
fromaddictimportDictclassMyDict(Dict):
deffunc(self):
print(self)
a=MyDict()
b=MyDict()
c=a|bc.func() # TypeError: 'Dict' object is not callable
Intuitively, we would expect that c is an instance of MyDict but is actually of type Dict. Moreover, since Dict does not have a method called func, when looking up c.func, it returns a new empty Dict, causing the error message to be very misleading.
Will it be possible to return an instance of type self.__class__ in Dict.__or__ and Dict.__ror__?
The text was updated successfully, but these errors were encountered:
#127 introduces merge operators. However, the current implementation has two problems:
Dict
is a subclass ofdict
, is it necessary to check byisinstance(other, (Dict, dict))
? Wouldn'tisinstance(other, dict)
be enough?|
and|=
always returnDict
instances, even if the operands may be instances of subclasses. To expatiate, consider the following snippet:Intuitively, we would expect that
c
is an instance ofMyDict
but is actually of typeDict
. Moreover, sinceDict
does not have a method calledfunc
, when looking upc.func
, it returns a new emptyDict
, causing the error message to be very misleading.Will it be possible to return an instance of type
self.__class__
inDict.__or__
andDict.__ror__
?The text was updated successfully, but these errors were encountered: