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

__futures__ parsing can be simplified using complete source locations for error detection. Also the error's offset is off by one sometimes. #98811

Closed
Assignees
iritkatriel
Labels
3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errortype-featureA feature request or enhancement
@iritkatriel

Description

@iritkatriel

The check for whether there are__future__ imports which are not in the beginning of the script appears in two places:

infuture.c, future_parse, the ff_lineno is stored (last lineno of a__future__ import) and there is a check forbad__future__ imports on the same line.

Then incompile.c, compiler_from_import(), any import from__future__ which is in a line afterc->c_future->ff_lineno is rejected.

If we replace ff_lineno by ff_location (the complete location information) then the check in compile.c can use the column info to detect the same-line case, and we no longer need to check for this in future.c. The code of future_parse will become much simpler.

There is also a bug in the future.c exception - the offset is off by 1, and this results in incorrect hilighting of the bad import:

python.exe -c "import test.badsyntax_future7.py"Traceback (most recent call last):  File "<string>", line 1, in <module>  File "/Users/iritkatriel/src/cpython/Lib/test/badsyntax_future7.py", line 3    from __future__ import nested_scopes; import string; from __future__ import \                                                        ^SyntaxError: from __future__ imports must occur at the beginning of the file

My patch will result in this output instead:

Traceback (most recent call last):  File "<string>", line 1, in <module>  File "/Users/iritkatriel/src/cpython-654/Lib/test/badsyntax_future7.py", line 3    from __future__ import nested_scopes; import string; from __future__ import \                                                         ^^^^^^^^^^^^^^^^^^^^^^^^SyntaxError: from __future__ imports must occur at the beginning of the file

Metadata

Metadata

Assignees

Labels

3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errortype-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp