Skip to content

Commit

Permalink
fix regression that broke string.format with list objects
Browse files Browse the repository at this point in the history
String formatting should validly assume that printing a list means
printing the list itself. Instead, something like this broke:

'one is: @0@ and two is: @1@'.format(['foo',  'bar'], ['baz'])

which would evaluate as:

'one is: foo and two is: bar'

or:

'the value of array option foobar is: @0@'.format(get_option('foobar'))

which should evaluate with '-Dfoobar=[]' as

'the value of array option foobar is: []'

But instead produced:

meson.build:7:0: ERROR: Format placeholder @0@ out of range.

Fixes mesonbuild#9530
  • Loading branch information
eli-schwartz committed Nov 4, 2021
1 parent 1104b82 commit 2023547
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mesonbuild/interpreter/primitives/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
MesonOperator,
FeatureNew,
typed_operator,
noArgsFlattening,
noKwargs,
noPosargs,
typed_pos_args,
Expand Down Expand Up @@ -85,6 +86,7 @@ def startswith_method(self, args: T.Tuple[str], kwargs: TYPE_kwargs) -> bool:
def endswith_method(self, args: T.Tuple[str], kwargs: TYPE_kwargs) -> bool:
return self.held_object.endswith(args[0])

@noArgsFlattening
@noKwargs
@typed_pos_args('str.format', varargs=object)
def format_method(self, args: T.Tuple[T.List[object]], kwargs: TYPE_kwargs) -> str:
Expand Down

0 comments on commit 2023547

Please sign in to comment.