diff --git a/CHANGES.rst b/CHANGES.rst index dc3f5cbf..eeba61ab 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -19,6 +19,8 @@ Unreleased :issue:`4157` - Correctly handle raising deferred errors in CLI lazy loading. :issue:`4096` +- The CLI loader handles ``**kwargs`` in a ``create_app`` function. + :issue:`4170` Version 2.0.1 diff --git a/src/flask/cli.py b/src/flask/cli.py index 81191a1a..0d101d0a 100644 --- a/src/flask/cli.py +++ b/src/flask/cli.py @@ -103,18 +103,21 @@ def call_factory(script_info, app_factory, args=None, kwargs=None): ) kwargs["script_info"] = script_info - if ( - not args - and len(sig.parameters) == 1 - and next(iter(sig.parameters.values())).default is inspect.Parameter.empty - ): - warnings.warn( - "Script info is deprecated and will not be passed as the" - " single argument to the app factory function in Flask" - " 2.1.", - DeprecationWarning, - ) - args.append(script_info) + if not args and len(sig.parameters) == 1: + first_parameter = next(iter(sig.parameters.values())) + + if ( + first_parameter.default is inspect.Parameter.empty + # **kwargs is reported as an empty default, ignore it + and first_parameter.kind is not inspect.Parameter.VAR_KEYWORD + ): + warnings.warn( + "Script info is deprecated and will not be passed as the" + " single argument to the app factory function in Flask" + " 2.1.", + DeprecationWarning, + ) + args.append(script_info) return app_factory(*args, **kwargs) diff --git a/tests/test_cli.py b/tests/test_cli.py index 5a666d8a..e7462bde 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -74,6 +74,15 @@ def test_find_best_app(test_apps): assert isinstance(app, Flask) assert app.name == "appname" + class Module: + @staticmethod + def create_app(**kwargs): + return Flask("appname") + + app = find_best_app(script_info, Module) + assert isinstance(app, Flask) + assert app.name == "appname" + class Module: @staticmethod def create_app(foo):