Skip to content

tighten the typing of DSL operator implementations - #15996

Open
dcbaker wants to merge 8 commits into
mesonbuild:masterfrom
dcbaker:submit/fixup-operator-typing
Open

tighten the typing of DSL operator implementations#15996
dcbaker wants to merge 8 commits into
mesonbuild:masterfrom
dcbaker:submit/fixup-operator-typing

Conversation

@dcbaker

@dcbaker dcbaker commented Jul 10, 2026

Copy link
Copy Markdown
Member

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.

@dcbaker dcbaker added this to the 1.13 milestone Jul 10, 2026
@dcbaker
dcbaker requested a review from jpakkane as a code owner July 10, 2026 20:42
@dcbaker dcbaker added the typing label Jul 10, 2026
from ...interpreterbase import TYPE_kwargs

class DictHolder(ObjectHolder[T.Dict[str, TYPE_var]], IterableObject):
class DictHolder(ObjectHolder[dict[str, TYPE_elementary]], IterableObject):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

2 participants