From cb683b38e0252d545650d55424ba4f7077c5b813 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini@redhat.com>
Date: Wed, 2 Nov 2022 10:07:17 +0100
Subject: [PATCH 2/9] Revert "decorators: Make unknown kwarg fatal"
Content-Type: text/plain
This reverts commit 88a1bed81b7d9ad262d3b511eb20444c609db235.
---
mesonbuild/interpreterbase/decorators.py | 16 ++++++++++------
.../common/129 build by default/meson.build | 1 +
test cases/frameworks/7 gnome/gir/meson.build | 4 ++++
test cases/unit/22 warning location/meson.build | 2 +-
unittests/allplatformstests.py | 6 +++---
5 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py
index 5dd8b8982..41c959a63 100644
--- a/mesonbuild/interpreterbase/decorators.py
+++ b/mesonbuild/interpreterbase/decorators.py
@@ -119,11 +119,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:
- 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}')
+ 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.')
return f(*wrapped_args, **wrapped_kwargs)
return T.cast('TV_func', wrapped)
@@ -532,8 +532,12 @@ 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)])
- raise InvalidArguments(f'{name} got unknown keyword arguments {ustr}')
+ mlog.warning(f'{name} got unknown keyword arguments {ustr}')
+ for u in unknowns:
+ del kwargs[u]
for info in types:
types_tuple = info.types if isinstance(info.types, tuple) else (info.types,)
diff --git a/test cases/common/129 build by default/meson.build b/test cases/common/129 build by default/meson.build
index b797f76e9..b28b6347c 100644
--- a/test cases/common/129 build by default/meson.build
+++ b/test cases/common/129 build by default/meson.build
@@ -9,6 +9,7 @@ executable('fooprog', 'foo.c',
executable('barprog', 'foo.c',
build_by_default : false,
+ build_always : true,
)
comp = files('mygen.py')
diff --git a/test cases/frameworks/7 gnome/gir/meson.build b/test cases/frameworks/7 gnome/gir/meson.build
index fbff2060e..64c49f729 100644
--- a/test cases/frameworks/7 gnome/gir/meson.build
+++ b/test cases/frameworks/7 gnome/gir/meson.build
@@ -46,6 +46,10 @@ 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)
diff --git a/test cases/unit/22 warning location/meson.build b/test cases/unit/22 warning location/meson.build
index 132939e04..52a93d18c 100644
--- a/test cases/unit/22 warning location/meson.build
+++ b/test cases/unit/22 warning location/meson.build
@@ -1,4 +1,4 @@
-project('warning location', 'c')
+project('warning location', 'c', invalid: 'cheese')
a = library('liba', 'a.c')
b = library('libb', 'b.c')
executable('main', 'main.c', link_with: a, link_with: b)
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index 0b968e7cf..6ba95b652 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -1931,6 +1931,7 @@ 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))
@@ -1980,9 +1981,8 @@ class AllPlatformTests(BasePlatformTests):
def test_permitted_method_kwargs(self):
tdir = os.path.join(self.unit_test_dir, '25 non-permitted kwargs')
- 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)
+ out = self.init(tdir, allow_fail=True)
+ self.assertIn('Function does not take keyword arguments.', out)
def test_templates(self):
ninja = mesonbuild.environment.detect_ninja()
--
2.38.1