Message293471
> he said, "I'm not sure if this was placed inside there due to some wild edge-case,"
As a new contributor, I'll always lean on the side of me not seeing something rather than confidently stating that something is definitely wrong. I'm new, the code-base is 20 years old and worked on by a dozen of experienced devs :-)
> Does a "Not-A-Class" class which is not a subclass of itself (issubclass(C, C) returns False) makes any sense?
I'm not sure. Apart from the performance impact, there's a behavioral discrepancy between isinstance and issubclass as you also stated.
In isinstance, __instancecheck__ doesn't *always* get a chance to override the behavior. The `if type(inst) == Cls` [1] stops it before it gets a chance.
In issubclass, __subclasscheck__ does override it:
class Meta(type):
def __instancecheck__(self, other):
print("invoked")
return False
def __subclasscheck__(self, other):
print("invoked")
return False
class Cls(metaclass=Meta):
pass
isinstance(Cls(), Cls)
True
issubclass(Cls, Cls)
invoked
False
So, I guess the question might be re-framed to: Is it guaranteed that __instancecheck__ and __subclasscheck__ are *always* called?
If yes: PyObject_IsInstance should be tweaked.
If no: PyObject_IsSubclass should be tweaked.
p.s Should I maybe move this to python-dev?
[1]: https://github.com/python/cpython/blob/master/Objects/abstract.c#L2338 |
|
Date |
User |
Action |
Args |
2017-05-11 02:50:16 | Jim Fasarakis-Hilliard | set | recipients:
+ Jim Fasarakis-Hilliard, georg.brandl, rhettinger, pitrou, serhiy.storchaka |
2017-05-11 02:50:16 | Jim Fasarakis-Hilliard | set | messageid: <1494471016.46.0.395643512893.issue30230@psf.upfronthosting.co.za> |
2017-05-11 02:50:16 | Jim Fasarakis-Hilliard | link | issue30230 messages |
2017-05-11 02:50:15 | Jim Fasarakis-Hilliard | create | |
|