decorators: Make unknown kwarg fatal

pull/9196/head
Xavier Claessens 4 years ago committed by Xavier Claessens
parent 276063a1d2
commit 88a1bed81b
  1. 16
      mesonbuild/interpreterbase/decorators.py
  2. 1
      test cases/common/129 build by default/meson.build
  3. 4
      test cases/frameworks/7 gnome/gir/meson.build
  4. 2
      test cases/unit/22 warning location/meson.build
  5. 6
      unittests/allplatformstests.py

@ -102,11 +102,11 @@ class permittedKwargs:
def __call__(self, f: TV_func) -> TV_func:
@wraps(f)
def wrapped(*wrapped_args: T.Any, **wrapped_kwargs: T.Any) -> T.Any:
node, args, kwargs, _ = get_callee_args(wrapped_args)
for k in kwargs:
if k not in self.permitted:
mlog.warning(f'''Passed invalid keyword argument "{k}".''', location=node)
mlog.warning('This will become a hard error in the future.')
kwargs = get_callee_args(wrapped_args)[2]
unknowns = set(kwargs).difference(self.permitted)
if unknowns:
ustr = ', '.join([f'"{u}"' for u in sorted(unknowns)])
raise InvalidArguments(f'Got unknown keyword arguments {ustr}')
return f(*wrapped_args, **wrapped_kwargs)
return T.cast(TV_func, wrapped)
@ -406,12 +406,8 @@ def typed_kwargs(name: str, *types: KwargInfo) -> T.Callable[..., T.Any]:
all_names = {t.name for t in types}
unknowns = set(kwargs).difference(all_names)
if unknowns:
# Warn about unknown argumnts, delete them and continue. This
# keeps current behavior
ustr = ', '.join([f'"{u}"' for u in sorted(unknowns)])
mlog.warning(f'{name} got unknown keyword arguments {ustr}')
for u in unknowns:
del kwargs[u]
raise InvalidArguments(f'{name} got unknown keyword arguments {ustr}')
for info in types:
value = kwargs.get(info.name)

@ -9,7 +9,6 @@ executable('fooprog', 'foo.c',
executable('barprog', 'foo.c',
build_by_default : false,
build_always : true,
)
comp = files('mygen.py')

@ -46,10 +46,6 @@ gnome.generate_gir(
dependencies : [[fake_dep, dep1_dep]],
install : true,
build_by_default : true,
# Test that unknown kwargs do not crash the parser.
# Unknown kwargs will eventually become a hard error.
# Once that happens remove this.
unknown_kwarg : true,
)
test('gobject introspection/c', girexe)

@ -1,4 +1,4 @@
project('warning location', 'c', invalid: 'cheese')
project('warning location', 'c')
a = library('liba', 'a.c')
b = library('libb', 'b.c')
executable('main', 'main.c', link_with: a, link_with: b)

@ -1777,7 +1777,6 @@ class AllPlatformTests(BasePlatformTests):
r'sub' + os.path.sep + r'meson.build:4: WARNING: subdir warning',
r'meson.build:7: WARNING: Module unstable-simd has no backwards or forwards compatibility and might not exist in future releases.',
r"meson.build:11: WARNING: The variable(s) 'MISSING' in the input file 'conf.in' are not present in the given configuration data.",
r'meson.build:1: WARNING: Passed invalid keyword argument "invalid".',
]:
self.assertRegex(out, re.escape(expected))
@ -1827,8 +1826,9 @@ class AllPlatformTests(BasePlatformTests):
def test_permitted_method_kwargs(self):
tdir = os.path.join(self.unit_test_dir, '25 non-permitted kwargs')
out = self.init(tdir, allow_fail=True)
self.assertIn('Function does not take keyword arguments.', out)
with self.assertRaises(subprocess.CalledProcessError) as cm:
self.init(tdir)
self.assertIn('ERROR: compiler.has_header_symbol got unknown keyword arguments "prefixxx"', cm.exception.output)
def test_templates(self):
ninja = mesonbuild.environment.detect_ninja()

Loading…
Cancel
Save