Python Forum
issubclass() not as documented - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: issubclass() not as documented (/thread-32797.html)

Pages: 1 2


issubclass() not as documented - Skaperen - Mar-06-2021

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.


RE: issubclass() not as documented - ndc85430 - Mar-07-2021

Wouldn't it help to show the code you're trying? Otherwise, we're having to assume what you mean by "a wrong condition".


RE: issubclass() not as documented - Gribouillis - Mar-07-2021

This could be an opportunity for you to become a Python core developer by sending a pull request.


RE: issubclass() not as documented - Skaperen - Mar-07-2021

(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.


RE: issubclass() not as documented - Skaperen - Mar-07-2021

maybe, instead, i'll create Cobra, which if an exception is raised, deletes the source file.


RE: issubclass() not as documented - snippsat - Mar-07-2021

(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



RE: issubclass() not as documented - Skaperen - Mar-08-2021

where does it say the part "when not return True or False"? where does is say anything about False?


RE: issubclass() not as documented - ndc85430 - Mar-08-2021

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.


RE: issubclass() not as documented - stranac - Mar-08-2021

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.


RE: issubclass() not as documented - Skaperen - Mar-08-2021

(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.