diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-10-26 06:17:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-26 06:17:28 (GMT) |
commit | 90a1b2859f99a4b07da6c46b99759444e3cefbfa (patch) | |
tree | e7ef4674c8e573906cfab0f3a3f096ac3fe4862d /Lib/linecache.py | |
parent | 3f84a19e6291db682fc9a570e7612e80e2ffbbb5 (diff) | |
download | cpython-90a1b2859f99a4b07da6c46b99759444e3cefbfa.zip cpython-90a1b2859f99a4b07da6c46b99759444e3cefbfa.tar.gz cpython-90a1b2859f99a4b07da6c46b99759444e3cefbfa.tar.bz2 |
gh-67224: Show source lines in tracebacks when using the -c option when running Python (#111200)
Diffstat (limited to 'Lib/linecache.py')
-rw-r--r-- | Lib/linecache.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/linecache.py b/Lib/linecache.py index c1c988d..329a140 100644 --- a/Lib/linecache.py +++ b/Lib/linecache.py @@ -5,10 +5,8 @@ is not found, it will look down the module search path for a file by that name. """ -import functools import sys import os -import tokenize __all__ = ["getline", "clearcache", "checkcache", "lazycache"] @@ -82,6 +80,8 @@ def updatecache(filename, module_globals=None): If something's wrong, print a message, discard the cache entry, and return an empty list.""" + import tokenize + if filename in cache: if len(cache[filename]) != 1: cache.pop(filename, None) @@ -176,11 +176,13 @@ def lazycache(filename, module_globals): get_source = getattr(loader, 'get_source', None) if name and get_source: - get_lines = functools.partial(get_source, name) + def get_lines(name=name, *args, **kwargs): + return get_source(name, *args, **kwargs) cache[filename] = (get_lines,) return True return False + def _register_code(code, string, name): cache[code] = ( len(string), |