Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6279686
fix ``SyntaxError`` for invalid type parameters expressions
picnixz Jun 3, 2024
7075bc6
blurb
picnixz Jun 3, 2024
74d330e
improve doc & naming
picnixz Jun 3, 2024
1ff9183
visual improvements of some test
picnixz Jun 3, 2024
234200c
Merge branch 'main' into fix-119933
picnixz Jun 3, 2024
fa7f02f
simplify the flow
picnixz Jun 3, 2024
b77cebb
Merge branch 'main' into fix-119933
picnixz Jun 4, 2024
7482db6
address review
picnixz Jun 4, 2024
2edf665
address review
picnixz Jun 4, 2024
845c7a6
use the same declaration order across files
picnixz Jun 4, 2024
bbfdcb7
Use enumeration members instead of `.value`.
picnixz Jun 5, 2024
f1208c7
export `SymbolTableType` enumeration
picnixz Jun 5, 2024
e533e4d
update NEWS
picnixz Jun 5, 2024
4cf0bf8
simplify `ste_scope_info` creation
picnixz Jun 5, 2024
740c8f2
improve documentation for `TypeVariableBlock`
picnixz Jun 5, 2024
3e329df
update documentation
picnixz Jun 5, 2024
18bc1f3
fixup
picnixz Jun 5, 2024
dd8d461
Merge branch 'main' into fix-119933
picnixz Jun 5, 2024
2ca6fd9
blurb
picnixz Jun 5, 2024
278d1fc
fixup
picnixz Jun 5, 2024
3f6a03e
Merge branch 'main' into fix-119933
picnixz Jun 12, 2024
3667349
Merge branch 'main' into fix-119933
picnixz Jun 12, 2024
82a37b6
Move SyntaxError's NEWS into "Core and Builtins"
picnixz Jun 13, 2024
cf45f40
improve documentation wording
picnixz Jun 13, 2024
e96f6b4
Update Python/symtable.c
picnixz Jun 17, 2024
705a76f
Update Doc/library/symtable.rst
picnixz Jun 17, 2024
abad81b
address review
picnixz Jun 17, 2024
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
Prev Previous commit
Next Next commit
improve doc & naming
  • Loading branch information
picnixz committed Jun 3, 2024
commit 74d330ed03c1ba937f7eb97a7d22d9a143b38c63
17 changes: 10 additions & 7 deletions Include/internal/pycore_symtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,29 @@ typedef enum _comprehension_type {
SetComprehension = 3,
GeneratorExpression = 4 } _Py_comprehension_ty;

/* Additional flags that are set temporarily on a symtable object.
/* Additional flags that are set temporarily on a ``_symtable_entry`` object.
*
* Those flags are only used to add some information on the current context.
*/
typedef enum _extra_flags {
typedef enum _extra_flags_e {
// Mutually exclusive flags indicating the kind of type variable
// being processed.
// being processed. Use this flag to avoid passing or checking
// twice the kind of a ``type_param_ty`` object.
InTypeVar = 1,
InTypeVarTuple = 2,
InParamSpec = (1 << 2),

// Mutually exclusive flags indicating which component of
// a type parameters block (PEP 695) is being processed.
// a type parameters block is being processed. Those flags
// are used in conjunction with 'InTypeVar', 'InTypeVarTuple'
// or 'InParamSpec' but not all combinations are supported.
InTypeParamBound = (1 << 3),
InTypeParamConstraint = (1 << 4),
InTypeParamDefault = (1 << 5),
} _Py_extra_fls;
} _extra_flags_t;

#define CLEAR_TYPE_PARAM_KIND_EXTRA_FLAGS ~(InTypeVar | InTypeVarTuple | InParamSpec)
#define CLEAR_TYPE_PARAM_EXTRA_FLAGS ~(InTypeParamBound | InTypeParamConstraint | InTypeParamDefault)
#define CLEAR_TYPE_PARAM_ATTR_EXTRA_FLAGS ~(InTypeParamBound | InTypeParamConstraint | InTypeParamDefault)

/* source location information */
typedef struct {
Expand Down Expand Up @@ -104,7 +107,7 @@ typedef struct _symtable_entry {
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;
_Py_extra_fls ste_extra_flags;
_extra_flags_t ste_extra_flags; /* extra temporary flags */
Comment thread
picnixz marked this conversation as resolved.
Outdated
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,
Expand Down
4 changes: 2 additions & 2 deletions Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,7 @@ symtable_visit_type_param_bound_or_default(struct symtable *st, expr_ty e, ident
if (!symtable_enter_block(st, name, TypeVarBoundBlock, key, LOCATION(e)))
return 0;

st->st_cur->ste_extra_flags &= CLEAR_TYPE_PARAM_EXTRA_FLAGS;
st->st_cur->ste_extra_flags &= CLEAR_TYPE_PARAM_ATTR_EXTRA_FLAGS;
st->st_cur->ste_extra_flags |= (is_default == 1 ? InTypeParamDefault : (
e->kind == Tuple_kind ? InTypeParamConstraint : InTypeParamBound
));
Expand Down Expand Up @@ -2753,7 +2753,7 @@ symtable_raise_if_annotation_block(struct symtable *st, const char *name, expr_t
if (type == AnnotationBlock)
PyErr_Format(PyExc_SyntaxError, ANNOTATION_NOT_ALLOWED, name);
else if (type == TypeVarBoundBlock) {
enum _extra_flags flags = st->st_cur->ste_extra_flags;
_extra_flags_t flags = st->st_cur->ste_extra_flags;
PyErr_Format(
PyExc_SyntaxError, EXPR_NOT_ALLOWED_IN_TYPE_PARAM_BLOCK, name, (
(flags & InTypeVar) ? "a TypeVar" :
Expand Down