Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-46042: Improve SyntaxError locations in the symbol table #30059

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

Merged
merged 3 commits into from
Dec 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Include/internal/pycore_symtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ struct _mod; // Type defined in pycore_ast.h
typedef enum _block_type { FunctionBlock, ClassBlock, ModuleBlock, AnnotationBlock }
_Py_block_ty;

typedef enum _comprehension_type {
NoComprehension = 0,
ListComprehension = 1,
DictComprehension = 2,
SetComprehension = 3,
GeneratorExpression = 4 } _Py_comprehension_ty;

struct _symtable_entry;

struct symtable {
Expand Down Expand Up @@ -42,14 +49,14 @@ typedef struct _symtable_entry {
PyObject *ste_varnames; /* list of function parameters */
PyObject *ste_children; /* list of child blocks */
PyObject *ste_directives;/* locations of global and nonlocal statements */
_Py_block_ty ste_type; /* module, class, or function */
_Py_block_ty ste_type; /* module, class or function */
int ste_nested; /* true if block is nested */
unsigned ste_free : 1; /* true if block has free variables */
unsigned ste_child_free : 1; /* true if a child block has free vars,
including free refs to globals */
unsigned ste_generator : 1; /* true if namespace is a generator */
unsigned ste_coroutine : 1; /* true if namespace is a coroutine */
unsigned ste_comprehension : 1; /* true if namespace is a list comprehension */
_Py_comprehension_ty ste_comprehension; /* Kind of comprehension (if any) */
unsigned ste_varargs : 1; /* true if block has varargs */
unsigned ste_varkeywords : 1; /* true if block has varkeywords */
unsigned ste_returns_value : 1; /* true if namespace uses return with
Expand Down
7 changes: 4 additions & 3 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ def baz():
check(b"\xef\xbb\xbf#coding: utf8\nprint('\xe6\x88\x91')\n", 0, -1)

# Errors thrown by symtable.c
check('x = [(yield i) for i in range(3)]', 1, 5)
check('def f():\n from _ import *', 1, 1)
check('def f(x, x):\n pass', 1, 1)
check('x = [(yield i) for i in range(3)]', 1, 7)
check('def f():\n from _ import *', 2, 17)
check('def f(x, x):\n pass', 1, 10)
check('{i for i in range(5) if (j := 0) for j in range(5)}', 1, 38)
check('def f(x):\n nonlocal x', 2, 3)
check('def f(x):\n x = 1\n global x', 3, 3)
check('nonlocal x', 1, 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve the location of the caret in :exc:`SyntaxError` exceptions emitted
by the symbol table. Patch by Pablo Galindo.
Loading