tighten the typing of DSL operator implementations - #15996
Open
dcbaker wants to merge 8 commits into
Open
Conversation
We're going to be using this more broadly, so put it in a broader place.
They are TV_FN_operator
Not a tuple of types.
bonzini
reviewed
Aug 12, 2026
| from ...interpreterbase import TYPE_kwargs | ||
|
|
||
| class DictHolder(ObjectHolder[T.Dict[str, TYPE_var]], IterableObject): | ||
| class DictHolder(ObjectHolder[dict[str, TYPE_elementary]], IterableObject): |
Contributor
There was a problem hiding this comment.
This is incorrect, a dictionary can hold non-elementary types. InterpreterObjectTypeVar, as for ArrayHolder?
| if isinstance(other, bool): | ||
| FeatureBroken.single_use('int operations with non-int', '1.2.0', self.subproject, | ||
| 'It is not commutative and only worked because of leaky Python abstractions.', | ||
| location=self.current_node) |
Contributor
There was a problem hiding this comment.
Probably this is broken altogether now due to
if op[0] is not None and not isinstance(other, op[0]):
raise InvalidArguments(f'The `{operator.value}` operator of {self.display_name()} does not accept objects of type {type(other).__name__} ({other})')
and there should be an other = int(other) to fix it?
| return 'int' | ||
|
|
||
| def operator_call(self, operator: MesonOperator, other: TYPE_var) -> TYPE_var: | ||
| def operator_call(self, operator: MesonOperator, other: int) -> int | bool: |
Contributor
There was a problem hiding this comment.
This is incorrect. It's super().operator_call that tightens the type on other, here it's still TYPE_var.
| TYPE_key_resolver = T.Callable[[mparser.BaseNode], str] | ||
|
|
||
| HoldableTypes = (HoldableObject, int, bool, str, list, dict) | ||
| TYPE_HoldableTypes = T.Union[TYPE_var, HoldableObject] |
Contributor
There was a problem hiding this comment.
This is just moved but it seems wrong, because TYPE_var already includes HoldableObject, so this is the same as TYPE_var. Should the bound of InterpreterObjectTypeVar be just TYPE_var.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is another piece of working toward a single, universal, calling interface for all DSL function implementations. This time we're taking aim at Meson operators instead of the optinterpreter like #15966. This really only affects types, and is closing in on the ability to define TV_func without the use of Any, which it currently does.