Skip to content
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

Uninformative syntax errors from codeop._maybe_compile (IDLE Shell) #111366

Closed
Mehdical-Man opened this issue Oct 26, 2023 · 5 comments
Closed

Uninformative syntax errors from codeop._maybe_compile (IDLE Shell) #111366

Mehdical-Man opened this issue Oct 26, 2023 · 5 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Mehdical-Man
Copy link

Mehdical-Man commented Oct 26, 2023

>>> def function(duplicate, duplicate):
...     pass
# Expected error message:
SyntaxError: duplicate argument 'duplicate' in function definition
# Actual error message:
SyntaxError: incomplete input
>>> def global_and_parameter(argument, /):
...    global argument # It may not be clear for less experienced coders
                       # that a name cannot be global and parameter
SyntaxError: incomplete input
# However when executed with exec():
SyntaxError: name 'argument' is parameter and global

Linked PRs

@hugovk
Copy link
Member

hugovk commented Oct 26, 2023

cc @pablogsal

pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 27, 2023
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 27, 2023
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 27, 2023
@terryjreedy terryjreedy added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir and removed topic-IDLE labels Oct 27, 2023
@terryjreedy terryjreedy changed the title Less informative errors in IDLE Shell Uninformative syntax errors from codeop._maybe_compile Oct 27, 2023
@Mehdical-Man Mehdical-Man changed the title Uninformative syntax errors from codeop._maybe_compile Uninformative syntax errors from codeop._maybe_compile (IDLE Shell) Oct 28, 2023
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 30, 2023
…n the codeop module functions (pythonGH-111384).

(cherry picked from commit cd6e0a0)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 30, 2023
…n the codeop module functions (pythonGH-111384).

(cherry picked from commit cd6e0a0)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 30, 2023
…sages in the codeop module functions (pythonGH-111384). (cherry picked from commit cd6e0a0)
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 30, 2023
…sages in the codeop module functions (pythonGH-111384). (cherry picked from commit cd6e0a0)
pablogsal added a commit that referenced this issue Oct 30, 2023
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 31, 2023
…n the codeop module functions (pythonGH-111384).

(cherry picked from commit cd6e0a0)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit that referenced this issue Oct 31, 2023
…codeop module functions (GH-111384). (#111516)

(cherry picked from commit cd6e0a0)
FullteaR pushed a commit to FullteaR/cpython that referenced this issue Nov 3, 2023
@hugovk
Copy link
Member

hugovk commented Nov 9, 2023

Closing as the PRs have been merged. Thanks for the report!

@hugovk hugovk closed this as completed Nov 9, 2023
@terryjreedy
Copy link
Member

Either codeop is not fixed for errors on line 1 or code is using codeop wrong. Fresh compile after update:

f:\dev\3x>python
# REPL splash lines
>>> def f(x,x): pass
...
SyntaxError: duplicate argument 'x' in function definition

# Switch  to simulated REPL, also used by IDLE, with same result.
>>> import code
>>> code.interact()
(InteractiveConsole)
>>> def f(x,x): pass
  File "<console>", line 1
    def f(x,x): pass
SyntaxError: invalid syntax
# Improvement over "incomplete input" in released versions (at least in IDLE), but not best.
>>> def f(x,x):
...   pass
  File "<console>", line 1
SyntaxError: duplicate argument 'x' in function definition

@terryjreedy
Copy link
Member

I still think that the fix for ._maybe_compile is to expose the REPL logic disintangled from terminal interaction, much as Python tokening code in tokenize was replaced by access to the real tokener. I have the impression that Pablo has taken steps toward the needed separation.

@hugovk
Copy link
Member

hugovk commented Nov 10, 2023

(Feel free to reopen this issue if needed)

aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants