Skip to content

Commit 88a1bed

Browse files
committed
decorators: Make unknown kwarg fatal
1 parent 276063a commit 88a1bed

File tree

5 files changed

+10
-19
lines changed

5 files changed

+10
-19
lines changed

mesonbuild/interpreterbase/decorators.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ def __init__(self, permitted: T.Set[str]):
102102
def __call__(self, f: TV_func) -> TV_func:
103103
@wraps(f)
104104
def wrapped(*wrapped_args: T.Any, **wrapped_kwargs: T.Any) -> T.Any:
105-
node, args, kwargs, _ = get_callee_args(wrapped_args)
106-
for k in kwargs:
107-
if k not in self.permitted:
108-
mlog.warning(f'''Passed invalid keyword argument "{k}".''', location=node)
109-
mlog.warning('This will become a hard error in the future.')
105+
kwargs = get_callee_args(wrapped_args)[2]
106+
unknowns = set(kwargs).difference(self.permitted)
107+
if unknowns:
108+
ustr = ', '.join([f'"{u}"' for u in sorted(unknowns)])
109+
raise InvalidArguments(f'Got unknown keyword arguments {ustr}')
110110
return f(*wrapped_args, **wrapped_kwargs)
111111
return T.cast(TV_func, wrapped)
112112

@@ -406,12 +406,8 @@ def wrapper(*wrapped_args: T.Any, **wrapped_kwargs: T.Any) -> T.Any:
406406
all_names = {t.name for t in types}
407407
unknowns = set(kwargs).difference(all_names)
408408
if unknowns:
409-
# Warn about unknown argumnts, delete them and continue. This
410-
# keeps current behavior
411409
ustr = ', '.join([f'"{u}"' for u in sorted(unknowns)])
412-
mlog.warning(f'{name} got unknown keyword arguments {ustr}')
413-
for u in unknowns:
414-
del kwargs[u]
410+
raise InvalidArguments(f'{name} got unknown keyword arguments {ustr}')
415411

416412
for info in types:
417413
value = kwargs.get(info.name)

test cases/common/129 build by default/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ executable('fooprog', 'foo.c',
99

1010
executable('barprog', 'foo.c',
1111
build_by_default : false,
12-
build_always : true,
1312
)
1413

1514
comp = files('mygen.py')

test cases/frameworks/7 gnome/gir/meson.build

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ gnome.generate_gir(
4646
dependencies : [[fake_dep, dep1_dep]],
4747
install : true,
4848
build_by_default : true,
49-
# Test that unknown kwargs do not crash the parser.
50-
# Unknown kwargs will eventually become a hard error.
51-
# Once that happens remove this.
52-
unknown_kwarg : true,
5349
)
5450

5551
test('gobject introspection/c', girexe)

test cases/unit/22 warning location/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project('warning location', 'c', invalid: 'cheese')
1+
project('warning location', 'c')
22
a = library('liba', 'a.c')
33
b = library('libb', 'b.c')
44
executable('main', 'main.c', link_with: a, link_with: b)

unittests/allplatformstests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,6 @@ def test_warning_location(self):
17771777
r'sub' + os.path.sep + r'meson.build:4: WARNING: subdir warning',
17781778
r'meson.build:7: WARNING: Module unstable-simd has no backwards or forwards compatibility and might not exist in future releases.',
17791779
r"meson.build:11: WARNING: The variable(s) 'MISSING' in the input file 'conf.in' are not present in the given configuration data.",
1780-
r'meson.build:1: WARNING: Passed invalid keyword argument "invalid".',
17811780
]:
17821781
self.assertRegex(out, re.escape(expected))
17831782

@@ -1827,8 +1826,9 @@ def test_error_location_path(self):
18271826

18281827
def test_permitted_method_kwargs(self):
18291828
tdir = os.path.join(self.unit_test_dir, '25 non-permitted kwargs')
1830-
out = self.init(tdir, allow_fail=True)
1831-
self.assertIn('Function does not take keyword arguments.', out)
1829+
with self.assertRaises(subprocess.CalledProcessError) as cm:
1830+
self.init(tdir)
1831+
self.assertIn('ERROR: compiler.has_header_symbol got unknown keyword arguments "prefixxx"', cm.exception.output)
18321832

18331833
def test_templates(self):
18341834
ninja = mesonbuild.environment.detect_ninja()

0 commit comments

Comments
 (0)