summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2024-06-17 15:01:49 (GMT)
committerGitHub <noreply@github.com>2024-06-17 15:01:49 (GMT)
commit7c47f93dff878bdc43f5162dd878cbb375711570 (patch)
tree7b02b412d2bc0f718d9df2912fa0b6cd66205de1 /Include
parent03b89e3a3d155a06827f58d51238a731d8800cc9 (diff)
downloadcpython-7c47f93dff878bdc43f5162dd878cbb375711570.zip
cpython-7c47f93dff878bdc43f5162dd878cbb375711570.tar.gz
cpython-7c47f93dff878bdc43f5162dd878cbb375711570.tar.bz2
[3.13] gh-119933: Improve ``SyntaxError`` message for invalid type parameters expressions (GH-119976) (#120641)
(cherry picked from commit 4bf17c381fb7b465f0f26aecb94a6c54cf9be2d3) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_symtable.h31
1 files changed, 26 insertions, 5 deletions
diff --git a/Include/internal/pycore_symtable.h b/Include/internal/pycore_symtable.h
index ac6c499..90252bf 100644
--- a/Include/internal/pycore_symtable.h
+++ b/Include/internal/pycore_symtable.h
@@ -15,11 +15,23 @@ typedef enum _block_type {
// Used for annotations if 'from __future__ import annotations' is active.
// Annotation blocks cannot bind names and are not evaluated.
AnnotationBlock,
- // Used for generics and type aliases. These work mostly like functions
- // (see PEP 695 for details). The three different blocks function identically;
- // they are different enum entries only so that error messages can be more
- // precise.
- TypeVarBoundBlock, TypeAliasBlock, TypeParamBlock
+
+ // The following blocks are used for generics and type aliases. These work
+ // mostly like functions (see PEP 695 for details). The three different
+ // blocks function identically; they are different enum entries only so
+ // that error messages can be more precise.
+
+ // The block to enter when processing a "type" (PEP 695) construction,
+ // e.g., "type MyGeneric[T] = list[T]".
+ TypeAliasBlock,
+ // The block to enter when processing a "generic" (PEP 695) object,
+ // e.g., "def foo[T](): pass" or "class A[T]: pass".
+ TypeParametersBlock,
+ // The block to enter when processing the bound, the constraint tuple
+ // or the default value of a single "type variable" in the formal sense,
+ // i.e., a TypeVar, a TypeVarTuple or a ParamSpec object (the latter two
+ // do not support a bound or a constraint tuple).
+ TypeVariableBlock,
} _Py_block_ty;
typedef enum _comprehension_type {
@@ -82,7 +94,16 @@ typedef struct _symtable_entry {
PyObject *ste_children; /* list of child blocks */
PyObject *ste_directives;/* locations of global and nonlocal statements */
PyObject *ste_mangled_names; /* set of names for which mangling should be applied */
+
_Py_block_ty ste_type;
+ // Optional string set by symtable.c and used when reporting errors.
+ // The content of that string is a description of the current "context".
+ //
+ // For instance, if we are processing the default value of the type
+ // variable "T" in "def foo[T = int](): pass", `ste_scope_info` is
+ // set to "a TypeVar default".
+ const char *ste_scope_info;
+
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,