[issue38878] os.PathLike subclasshook causes subclass checks true on abstract implementation
Ivan Levkivskyi
report at bugs.python.org
Fri Nov 22 20:19:53 EST 2019
Ivan Levkivskyi <levkivskyi at gmail.com> added the comment:
> So why is it bad that in the example class B is considered a "subclass" of os.PathLike by implementing the protocol?
This is not bad, my understanding of the problem is that currently B is considered a subclass of A, while the latter should not be structural.
To give an analogy with PEP 544 (sorry, this is my favourite one :-)) consider this:
class P(Protocol):
def some(self): ...
class C:
def some(self): ...
Here C is obviously a "subclass" of P, but:
class Bad(P): # <- this is _no_ a protocol, just a nominal class
pass # explicitly subclassing P
class Good(P, Protocol): # <- this is a subprotocol that
pass # happened to be identical to P
So here C is a "subclass" of Good, but not a "subclass" of Bad.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38878>
_______________________________________
More information about the Python-bugs-list
mailing list