Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The new repl sometimes does not show the error location whenSyntaxError is raised #121804

Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error
@tomasr8

Description

@tomasr8

Bug report

Bug description:

When I rundef f[Foo, Foo](): ... from a file, I get a nice error message including the location of the error:

File".../test.py",line1deff[Foo,Foo](): ...^^^SyntaxError:duplicate typeparameter'Foo'

However, when I run this in the new repl, the error location is not shown:

>>>deff[Foo,Foo](): ...File"<python-input-0>",line1SyntaxError:duplicate typeparameter'Foo'

The same thing happens with this error as well:

>>>deff(x,x): ...File"<python-input-0>",line1SyntaxError:duplicateargument'x'infunctiondefinition

The missing location seems to be the case for these two errors only as other errors do show it:

>>>deff(42): ...File"<unknown>",line1deff(42): ...^^SyntaxError:invalidsyntax

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:

cpython/Python/symtable.c

Lines 1421 to 1435 in6522f0e

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);
gotoerror;
}
if ((flag&DEF_TYPE_PARAM)&& (val&DEF_TYPE_PARAM)) {
PyErr_Format(PyExc_SyntaxError,DUPLICATE_TYPE_PARAM,name);
SET_ERROR_LOCATION(st->st_filename,loc);
gotoerror;
}
val |=flag;
}

Though it looks like that the error location is being set withSET_ERROR_LOCATION..

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp