-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed
Closed
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
When I run def f[Foo, Foo](): ...
from a file, I get a nice error message including the location of the error:
File ".../test.py", line 1
def f[Foo, Foo](): ...
^^^
SyntaxError: duplicate type parameter 'Foo'
However, when I run this in the new repl, the error location is not shown:
>>> def f[Foo, Foo](): ...
File "<python-input-0>", line 1
SyntaxError: duplicate type parameter 'Foo'
The same thing happens with this error as well:
>>> def f(x, x): ...
File "<python-input-0>", line 1
SyntaxError: duplicate argument 'x' in function definition
The missing location seems to be the case for these two errors only as other errors do show it:
>>> def f(42): ...
File "<unknown>", line 1
def f(42): ...
^^
SyntaxError: invalid syntax
What's interesting is that for the first two errors the file shows up as <python-input-0>
while for the last one it's <unknown>
. This could be related to the last error coming from the parser while the previous errors come from symtable:
Lines 1421 to 1435 in 6522f0e
if ((o = PyDict_GetItemWithError(dict, mangled))) { | |
val = PyLong_AS_LONG(o); | |
if ((flag & DEF_PARAM) && (val & DEF_PARAM)) { | |
/* Is it better to use 'mangled' or 'name' here? */ | |
PyErr_Format(PyExc_SyntaxError, DUPLICATE_ARGUMENT, name); | |
SET_ERROR_LOCATION(st->st_filename, loc); | |
goto error; | |
} | |
if ((flag & DEF_TYPE_PARAM) && (val & DEF_TYPE_PARAM)) { | |
PyErr_Format(PyExc_SyntaxError, DUPLICATE_TYPE_PARAM, name); | |
SET_ERROR_LOCATION(st->st_filename, loc); | |
goto error; | |
} | |
val |= flag; | |
} |
Though it looks like that the error location is being set with SET_ERROR_LOCATION
..
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-121804: always show error location for SyntaxError's in new repl #121886
- [3.13] gh-121804: Always show error location for SyntaxError's in new repl (GH-121886) #123148
- gh-121804: always show error location for SyntaxError's in basic repl #123202
- [3.12] gh-121804: Backport idlelib.pyshell change (GH-121886) #123366
- [3.13] gh-121804: always show error location for SyntaxError's in basic repl (GH-123202) #123631
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error