mirror of https://github.com/pallets/flask.git
cli loader handles kwargs in app factory
This commit is contained in:
parent
c3f923d0e0
commit
9f0da9b770
|
@ -19,6 +19,8 @@ Unreleased
|
||||||
:issue:`4157`
|
:issue:`4157`
|
||||||
- Correctly handle raising deferred errors in CLI lazy loading.
|
- Correctly handle raising deferred errors in CLI lazy loading.
|
||||||
:issue:`4096`
|
:issue:`4096`
|
||||||
|
- The CLI loader handles ``**kwargs`` in a ``create_app`` function.
|
||||||
|
:issue:`4170`
|
||||||
|
|
||||||
|
|
||||||
Version 2.0.1
|
Version 2.0.1
|
||||||
|
|
|
@ -103,10 +103,13 @@ def call_factory(script_info, app_factory, args=None, kwargs=None):
|
||||||
)
|
)
|
||||||
kwargs["script_info"] = script_info
|
kwargs["script_info"] = script_info
|
||||||
|
|
||||||
|
if not args and len(sig.parameters) == 1:
|
||||||
|
first_parameter = next(iter(sig.parameters.values()))
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not args
|
first_parameter.default is inspect.Parameter.empty
|
||||||
and len(sig.parameters) == 1
|
# **kwargs is reported as an empty default, ignore it
|
||||||
and next(iter(sig.parameters.values())).default is inspect.Parameter.empty
|
and first_parameter.kind is not inspect.Parameter.VAR_KEYWORD
|
||||||
):
|
):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Script info is deprecated and will not be passed as the"
|
"Script info is deprecated and will not be passed as the"
|
||||||
|
|
|
@ -74,6 +74,15 @@ def test_find_best_app(test_apps):
|
||||||
assert isinstance(app, Flask)
|
assert isinstance(app, Flask)
|
||||||
assert app.name == "appname"
|
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:
|
class Module:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_app(foo):
|
def create_app(foo):
|
||||||
|
|
Loading…
Reference in New Issue