Skip to content

start cleaning up the ast/interpreter.py type mess#15933

Open
bonzini wants to merge 12 commits into
mesonbuild:masterfrom
bonzini:type-ivar
Open

start cleaning up the ast/interpreter.py type mess#15933
bonzini wants to merge 12 commits into
mesonbuild:masterfrom
bonzini:type-ivar

Conversation

@bonzini

@bonzini bonzini commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Commit "ast/interpreter, rewriter: make flatten_args() recursive" is the really scary one. Apart from that it's mostly dead code removal that enables more reasoning on what's going on.

bonzini added 2 commits June 19, 2026 10:07
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
These are now guaranteed by typing annotations.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@bonzini bonzini added the typing label Jun 19, 2026
@bonzini bonzini added this to the 1.13 milestone Jun 19, 2026
bonzini added 4 commits June 19, 2026 11:35
While the typing annotations in ast/interpreter.py are a mess,
the calls to reduce_arguments() are all from the tame evaluate_*
functions.  There is no way that the args argument is a list
instead of an ArgumentNode.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Follow what is specified by TYPE_method_func.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Remove unused argument as well as the non-list case.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
The return type of flatten_args can actually be described more precisely
than T.Any, but in some cases it is used to operate on variables
described as T.List[TYPE_var] specifically and erroneously (because
they can be Unknownvalue, etc.).  Call those out specifically.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
bonzini added 6 commits June 19, 2026 13:19
This also enables using it instead of flatten().

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
The return value of "and" and "or" might be known even if one of the
operands is unknown.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
reduce_arguments and flatten_args operate on values that are TYPE_var
| mparser.BaseNode | some other types, but this is hidden behind Any.
Introduce TYPE_ivar and TYPE_ikwargs to make the representation a bit
closer to the truth.  Of course, because this replaces Any, a lot
of casts and "type: ignore" comments are needed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@bonzini bonzini marked this pull request as ready for review June 19, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant