Skip to content

typed argument convergance - #16134

Open
dcbaker wants to merge 52 commits into
mesonbuild:masterfrom
dcbaker:submit/typed-args
Open

typed argument convergance#16134
dcbaker wants to merge 52 commits into
mesonbuild:masterfrom
dcbaker:submit/typed-args

Conversation

@dcbaker

@dcbaker dcbaker commented Aug 20, 2026

Copy link
Copy Markdown
Member

We have a series of decorators that are used to check argument typing, one for positional arguments, one for keyword arguments, one for no positional arguments, and one for no keyword arguments.

This is annoying for a number of reasons.

  • repeating the name of the function
  • the no* variants don't take the function name
  • everyone has to remember to use both of these
  • the keyword argument validators are richer and more powerful than the non-keyword argument

To end that, I give you TypedArgs, the one decorator to rule them all. It does the work of typed_pos_args, typed_kwargs, noPosArgs, and noKwArgs, in one decorator. It also reworks positional arguments to be more like keyword arguments, using special classes that describe the various kinds of positional arguments, and allowing more conversion and checking to be done at in the decorator than in the function body.

Part of the goal is that this forces the developer to deal with all of the types, rather than just the positional or keyword arguments. Part of the goal is to make it easier to re-use pieces like with keyword arguments.

There is a significant LOC increase, most of this is in additional unit tests for new features, and not in the implementation, which ends up being roughly even.

dcbaker added 30 commits August 20, 2026 16:27
This will eventually take over for both typed_kwargs and typed_pos_args,
but for now it implements just the typed_kwarg info.
@dcbaker
dcbaker force-pushed the submit/typed-args branch from 12da74a to 9c55028 Compare August 20, 2026 21:12
@dcbaker
dcbaker force-pushed the submit/typed-args branch from 9c55028 to b7087ba Compare August 20, 2026 21:18
Comment thread mesonbuild/interpreter/primitives/integer.py
raise InvalidArguments(f'Array index {index} is out of bounds for array of size {len(self.held_object)}.')
return args[1]
return self.held_object[index]
index, fallback = args

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.

Separate PR?

@bonzini bonzini left a comment

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.

I would start by moving to a separate PR:

elif n == value:
warning = f'value "{n}"'
if warning:
feature.single_use(f'"{self.name}" positional argument "{index}" {warning}', version, subproject, msg, location=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.

No quotes around {index}.

Comment thread mesonbuild/interpreter/primitives/integer.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants