documentation for builtin function
issubclass() says it returns
True for the right conditions but otherwise raises
TypeError. when i call it with a wrong condition it just returns
False.
Wouldn't it help to show the code you're trying? Otherwise, we're having to assume what you mean by "a wrong condition".
This could be an opportunity for you to become a Python core developer by sending a pull request.
(Mar-07-2021, 09:15 AM)Gribouillis Wrote: [ -> ]This could be an opportunity for you to become a Python core developer by sending a pull request.
i don't want to become a Python core developer.
maybe, instead, i'll create Cobra, which if an exception is raised, deletes the source file.
(Mar-06-2021, 11:40 PM)Skaperen Wrote: [ -> ]documentation for builtin function issubclass() says it returns True for the right conditions but otherwise raises TypeError.
No,it say
In any other case, a TypeError exception is raised
.
Any other cases is when not return
True
or
False
.
class Animals:
pass
class Humans(Animals):
pass
>>> issubclass(Humans, Animals)
True
>>> issubclass(Animals, Humans)
False
>>> issubclass(Animals, 'foo')
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
TypeError: issubclass() arg 2 must be a class or tuple of classes
where does it say the part "when not return True or False"? where does is say anything about False?
Given that the function returns True
in some cases, it should be obvious that it would return False
in others (and really if a function is called "is something", you'd expect it to return a Boolean. Throwing an exception in the false case seems like bad design to me, as it's confusing for the caller.
Quote:classinfo may be a tuple of class objects, in which case every entry in classinfo will be checked. In any other case, a TypeError exception is raised.
What it's saying is that it raises
TypeError
when you pass it something other than a tuple.
It might not be perfectly clear from that that a single class is also allowed, but it doesn't say an exception is raised unless the condition is true.
(Mar-08-2021, 06:28 AM)ndc85430 Wrote: [ -> ]Given that the function returns True
in some cases, it should be obvious that it would return False
in others (and really if a function is called "is something", you'd expect it to return a Boolean. Throwing an exception in the false case seems like bad design to me, as it's confusing for the caller.
it may seem obvious but lots of other things are documented complete enough that you don't need to depend on your imagination. besides this documentation does say what it does in
other cases.