-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-136914: Use inspect.isroutine() in DocTest's lineno computation #136930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Previously, DocTest's lineno of `functools.cache()`-decorated functions was not properly returned (None was returned) because the underlying computation, in `DocTest._find_lineno()`, relied on `inspect.isfunction()` which does not consider the decorated result as a function. We now use the more generic `inspect.isroutine()`, as elsewhere in doctest's logic, thus fixing lineno computation for functools.cache()-decorated functions.
b1e3185
to
ddf3ab1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it also work for cached_property
?
import functools | ||
|
||
|
||
@functools.cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest using a custom class decorator here instead of functools.cache
. We don't want this to depend on the implementation details of functools.cache
, which could change in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this may add unnecessary complexity to the tests. And such test will not guarantee that the code works also for functools.cached
, which is a comon case. Other tests just test common cases.
@@ -0,0 +1 @@ | |||
Fix retrieval of :attr:`doctest.DocTest.lineno` for :func:`functools.cache`-decorated functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, I'd suggest wording this more generally -- this affects any class decorator that uses functools.update_wrapper
, not just functools.cache
Previously, DocTest's lineno of
functools.cache()
-decorated functions was not properly returned (None was returned) because the underlying computation, inDocTest._find_lineno()
, relied oninspect.isfunction()
which does not consider the decorated result as a function.We now use the more generic
inspect.isroutine()
, as elsewhere in doctest's logic, thus fixing lineno computation for functools.cache()-decorated functions.