#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:
from addict import Dict
class MyDict(Dict):
def func(self):
print(self)
a = MyDict()
b = MyDict()
c = a | b
c.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__?
#127 introduces merge operators. However, the current implementation has two problems:
Dictis a subclass ofdict, is it necessary to check byisinstance(other, (Dict, dict))? Wouldn'tisinstance(other, dict)be enough?|and|=always returnDictinstances, even if the operands may be instances of subclasses. To expatiate, consider the following snippet:Intuitively, we would expect that
cis an instance ofMyDictbut is actually of typeDict. Moreover, sinceDictdoes 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__?