Posts: 4,647
Threads: 1,494
Joined: Sep 2016
(Mar-08-2021, 06:36 AM)stranac Wrote: 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.
i think there is a better way to explain it as what it says right now doesn't do it.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 325
Threads: 11
Joined: Feb 2010
(Mar-08-2021, 08:13 AM)Skaperen Wrote: i think there is a better way to explain it as what it says right now doesn't do it. If you're not happy with the current explanation and can come up with a better one, nothing is stopping you from contributing to the docs.
Posts: 1,950
Threads: 8
Joined: Jun 2018
This is example where type hints would improve understanding with very little effort:
issubclass(...) -> bool
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 1,838
Threads: 2
Joined: Apr 2017
You should also get into the habit of looking at the test cases. Tests are another form of documentation.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
(Mar-09-2021, 06:53 AM)ndc85430 Wrote: You should also get into the habit of looking at the test cases. Tests are another form of documentation. the documentation (i have the PDF) has no reference to test cases from these methods.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 1,838
Threads: 2
Joined: Apr 2017
I don't know why you'd look in a PDF for tests - by "tests", I mean code that executes the functions to make sure their behaviour is correct (in this case, those are unit tests). I haven't seen how the standard library code is organised, but it should be quite easy to find the tests in the repo.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
(Mar-11-2021, 03:08 AM)ndc85430 Wrote: I don't know why you'd look in a PDF for tests - by "tests", I mean code that executes the functions to make sure their behaviour is correct (in this case, those are unit tests). I haven't seen how the standard library code is organised, but it should be quite easy to find the tests in the repo.
so basically, this comes down to suggesting that i look a source code to see what it really does?  then, what's the point of having documentation?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 3,458
Threads: 101
Joined: Sep 2016
Mar-11-2021, 07:50 PM
(This post was last modified: Mar-11-2021, 07:51 PM by nilamo.)
I agree with Skaperen here. The docs clearly state that the only result of running issubclass() is either True, or an exception.
Looking at tests to see how internals to Python core work shouldn't (ever) be needed to understand how to use Python, or any library for that matter.
Looking at the source of Python could involve looking at C code, which isn't a viable option for everyone writing Python.
This is a very clear case of the documentation not matching current functionality. Since fixing the bug would involve breaking changes (and returning False to a function who's name clearly indicates it returns a bool), the docs should be updated to more clearly indicate what's actually returned.
Quote:Return True if class is a subclass (direct, indirect or virtual) of classinfo. A class is considered a subclass of itself. 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.
I don't even see this as a discussion. There's no argument about ambiguous docs, they're just incorrect. Either True is returned, or a TypeError is raised. Any other functionality (such as returning False) is undefined behavior.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
it's probably just an oversight. i found it because i was spending some time with it, using it in a project (i ended up taking it back out). documentation writers probably would not catch a little thing like this unless there was a change of behavior which would need a rewrite (what they probably spend most of their time on to get the next release out.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 3,458
Threads: 101
Joined: Sep 2016
To be fair to Python, though, the interactive docs don't have this ambiguous phrasing, and indicate that it returns a bool (though, there's no mention of any exceptions ever being possible...)
>>> help(issubclass)
Help on built-in function issubclass in module builtins:
issubclass(cls, class_or_tuple, /)
Return whether 'cls' is a derived from another class or is the same class.
A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to
check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)
or ...`` etc.
|