Open mtshiba opened 8 months ago
OptionEq is a patch that allows comparison of optional types. However, the current implementation is broken.
OptionEq
C = Class { .x = Int } C|<: Eq|. __eq__ self, other: C = self.x == other.x c as C or NoneType = C.new { .x = 1 } print! c == None
False
AttributeError: 'NoneType' object has no attribute 'x'
It should be:
C|<: Eq|. __eq__ self, other: C = hasattr(other, "x") and self.x == other.x
But this doesn't mean the original implementation was wrong. It is an implementation mistake that OptionEq allows T or NoneType <: Eq for T <: Eq.
T or NoneType <: Eq
T <: Eq
To allow this, we need to inject an implementation like, for example:
OptionEq. __eq__ slf, other = classof(slf) == classof(other) and slf.__eq__ other c as C or NoneType = C.new { .x = 1 } print! OptionEq.__eq__ c, None
0.6.33
None
Describe the behavior?
OptionEq
is a patch that allows comparison of optional types. However, the current implementation is broken.Reproducible code
Expected result
False
Actual result
AttributeError: 'NoneType' object has no attribute 'x'
Additional context
It should be:
But this doesn't mean the original implementation was wrong. It is an implementation mistake that
OptionEq
allowsT or NoneType <: Eq
forT <: Eq
.To allow this, we need to inject an implementation like, for example:
Erg version
0.6.33
Python version
None
OS
None