-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
REPL shows source code from _pyrepl.__main__.py
#129098
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
Comments
cc @pablogsal @ambv |
Traceback seems like good place to check for it instead of linecache, but I did not find any reference to Lines 341 to 351 in ed6934e
So I would need someone to point me in the right direction where it should be handled as I don't have much context here. |
I'm sorry, I wasn't explicit enough. What I meant is that we should fix Btw, I think we have an existing issue for this one but I don't remember which one it is... |
I will try to get more context and see how it can be fixed better if that's okay. |
The current state of things is already due to an attempt to hide _pyrepl internals. I'm not sure there's an easy way to change I disagree that it's somehow invalid to patch |
Wouldn't it be possible with some custom
What I meant is that I'm more worried about the fact that we have some hardcoded |
Hm, |
By adding >>> eval(compile("val", "missing", "eval"))
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
eval(compile("val", "missing", "eval"))
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "missing", line 1, in <module>
NameError: name 'val' is not defined. Did you mean: 'eval'?
>>> So it appears to work. In # Try for a __loader__, if available
if module_globals and '__name__' in module_globals: # <- ok
spec = module_globals.get('__spec__') # will be explicitly None
name = getattr(spec, 'name', None) or module_globals['__name__']
loader = getattr(spec, 'loader', None) # will be None
if loader is None:
loader = module_globals.get('__loader__') # will be None
get_source = getattr(loader, 'get_source', None) # will be None
if name and get_source: # will be skipped
def get_lines(name=name, *args, **kwargs):
return get_source(name, *args, **kwargs)
cache[filename] = (get_lines,)
return True
return False # and we get here |
Doesn't it break other things somewhere? |
I don't think so because we're only changing the loader and spec of a specific module. But we should investigate (I don't have time now and I'm leaving for 2 weeks tomorrow) |
Benedkit's fix does not work for me. The error does not occur when using a "<foo>" placeholder
|
I don't understand the problem. My fix is to avoid jumping to the pyrepl main. In this case Note: traceback or linecache treats |
Ok: the reason why Lines 98 to 99 in ddc27f9
Lines 179 to 180 in ddc27f9
|
I don't think this is just a repl issue, this is just that when the file does not exist it returns the first line of the file being run, why on earth is it implemented this way? |
That's how tracebacks are constructed. The problem is just that we should actually skip that file when reporting the traceback, namely, making it "inexisting" from a summary PoV. In addition, it's probably because we're actually using |
I see, you should open a PR with your fix then :-) |
@picnixz thanks for writing the fix as I did not have time to do it myself. We can close my PR, right? |
I think we can, because I don't think we'll go that way at least. |
…porting tracebacks (pythonGH-130721) (cherry picked from commit 492e3e6) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
… when reporting tracebacks (python#130721)" This reverts commit 492e3e6.
Bug report
Bug description:
When using
compile
built-in function and providing non-existing filename, REPL shows source lines from_pyrepl.__main__.py
if exception occurs. Reproducer:Results in:
traceback with following line:
# Important: don't add things to this module, as they will end up in the REPL's
. This is first line fromLib/_pyrepl/__main__.py
.CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
_pyrepl.__main__.py
inside REPL #129099_pyrepl/__main__.py
when reporting tracebacks #130721_pyrepl/__main__.py
when reporting tracebacks (GH-130721) #132755The text was updated successfully, but these errors were encountered: