| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
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.
There was a problem hiding this comment.
Does it also work for cached_property?
Sorry, something went wrong.
| import functools | ||
|
|
||
|
|
||
| @functools.cache |
There was a problem hiding this comment.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
| @@ -0,0 +1 @@ | |||
| Fix retrieval of :attr:`doctest.DocTest.lineno` for :func:`functools.cache`-decorated functions. | |||
There was a problem hiding this comment.
Likewise, I'd suggest wording this more generally -- this affects any class decorator that uses functools.update_wrapper, not just functools.cache
Sorry, something went wrong.
Apparently not; should I make it work in the scope of this PR? |
Sorry, something went wrong.
|
If this is easy, why not? Otherwise this can be a separate PR. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM. 👍
Sorry, something went wrong.
|
Added a commit to handle functools.cached_property. |
Sorry, something went wrong.
…cTest's lineno computation (pythonGH-136930) Previously, DocTest's lineno of functions and methods decorated with functools.cache(), functools.lru_cache() and functools.cached_property() was not properly returned (None was returned) because the computation 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. Also, added a special case for functools.cached_property().
Fixes: Checking branch 3.13 From https://github.com/python/cpython * [new branch] 3.13 -> 3.13 1 1 10000 python/cpython#136930 gh-136914: Fix support of cached functions and properties in DocTest's lineno computation (GH-136930) Backport to 3.13 missing 2 1 10000 python/cpython#136890 Fix typos in Doc/extending/extending.rst and Doc/library/shelve.rst (GH-136890) Backport to 3.13 missing 3 1 10000 python/cpython#136709 gh-136710: Fix bad indentation in `os.chdir` docstring (GH-136709) Backport to 3.13 missing 4 1 10000 python/cpython#136519 Omit `Python/perf_jit_trampoline.c` from the `**/*jit*` CODEOWNERS rule (#136519) fatal: command line, 'Omit `Python/perf_jit_trampoline.c` from the `**/*jit*` CODEOWNERS rule (#136519)': Invalid preceding regular expression Traceback (most recent call last): File "/home/runner/work/dashboard/dashboard/github-tools/needs_backport.py", line 214, in <module> main() ~~~~^^ File "/home/runner/work/dashboard/dashboard/github-tools/needs_backport.py", line 170, in main candidates = check_prs( api, args.repo_path, branch, args.start, args.number, args.sort ) File "/home/runner/work/dashboard/dashboard/github-tools/needs_backport.py", line 109, in check_prs if is_commit_title_in_branch(repo_path, title, branch_to_check): ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/runner/work/dashboard/dashboard/github-tools/needs_backport.py", line 60, in is_commit_title_in_branch output = subprocess.check_output( ~~~~~~~~~~~~~~~~~~~~~~~^ ["git", "log", "--grep", title, branch], cwd=repo_path ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ).decode("utf-8") ^ File "/opt/hostedtoolcache/Python/3.13.5/x64/lib/python3.13/subprocess.py", line 472, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ **kwargs).stdout ^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.13.5/x64/lib/python3.13/subprocess.py", line 577, in run raise CalledProcessError(retcode, process.args, output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['git', 'log', '--grep', 'Omit `Python/perf_jit_trampoline.c` from the `**/*jit*` CODEOWNERS rule (#136519)', '3.13']' returned non-zero exit status 128.
|
Thanks @dlax for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, something went wrong.
|
Thanks @dlax for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
Sorry, something went wrong.
…cTest's lineno computation (pythonGH-136930) Previously, DocTest's lineno of functions and methods decorated with functools.cache(), functools.lru_cache() and functools.cached_property() was not properly returned (None was returned) because the computation 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. Also, added a special case for functools.cached_property(). (cherry picked from commit fece15d) Co-authored-by: Denis Laxalde <denis@laxalde.org>
…cTest's lineno computation (pythonGH-136930) Previously, DocTest's lineno of functions and methods decorated with functools.cache(), functools.lru_cache() and functools.cached_property() was not properly returned (None was returned) because the computation 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. Also, added a special case for functools.cached_property(). (cherry picked from commit fece15d) Co-authored-by: Denis Laxalde <denis@laxalde.org>
|
GH-137615 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
|
GH-137616 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
…ocTest's lineno computation (GH-136930) (GH-137615) Previously, DocTest's lineno of functions and methods decorated with functools.cache(), functools.lru_cache() and functools.cached_property() was not properly returned (None was returned) because the computation 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. Also, added a special case for functools.cached_property(). (cherry picked from commit fece15d) Co-authored-by: Denis Laxalde <denis@laxalde.org>
…cTest's lineno computation (pythonGH-136930) Previously, DocTest's lineno of functions and methods decorated with functools.cache(), functools.lru_cache() and functools.cached_property() was not properly returned (None was returned) because the computation 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. Also, added a special case for functools.cached_property().
…ocTest's lineno computation (GH-136930) (#137616) gh-136914: Fix support of cached functions and properties in DocTest's lineno computation (GH-136930) Previously, DocTest's lineno of functions and methods decorated with functools.cache(), functools.lru_cache() and functools.cached_property() was not properly returned (None was returned) because the computation 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. Also, added a special case for functools.cached_property(). (cherry picked from commit fece15d) Co-authored-by: Denis Laxalde <denis@laxalde.org>
| Back | FazBrowse Home | New Git URL |
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.