Path 1: 4 calls (0.33)

module (4)

'create_app()' (1) 'create_app2("foo", "bar")' (1) 'create_app2("foo", "bar", )' (1) ' create_app () ' (1)

Flask (4)

1def find_app_by_string(module, app_name):
2    """Check if the given string is a variable name or a function. Call
3    a function to get the app instance, or return the variable directly.
4    """
5    from . import Flask
6
7    # Parse app_name as a single expression to determine if it's a valid
8    # attribute name or function call.
9    try:
10        expr = ast.parse(app_name.strip(), mode="eval").body
11    except SyntaxError:
12        raise NoAppException(
13            f"Failed to parse {app_name!r} as an attribute name or function call."
14        ) from None
15
16    if isinstance(expr, ast.Name):
17        name = expr.id
18        args = []
19        kwargs = {}
20    elif isinstance(expr, ast.Call):
21        # Ensure the function name is an attribute name only.
22        if not isinstance(expr.func, ast.Name):
23            raise NoAppException(
24                f"Function reference must be a simple name: {app_name!r}."
25            )
26
27        name = expr.func.id
28
29        # Parse the positional and keyword arguments as literals.
30        try:
31            args = [ast.literal_eval(arg) for arg in expr.args]
32            kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in expr.keywords}
33        except ValueError:
34            # literal_eval gives cryptic error messages, show a generic
35            # message with the full expression instead.
36            raise NoAppException(
37                f"Failed to parse arguments as literal values: {app_name!r}."
38            ) from None
39    else:
40        raise NoAppException(
41            f"Failed to parse {app_name!r} as an attribute name or function call."
42        )
43
44    try:
45        attr = getattr(module, name)
46    except AttributeError as e:
47        raise NoAppException(
48            f"Failed to find attribute {name!r} in {module.__name__!r}."
49        ) from e
50
51    # If the attribute is a function, call it with any args and kwargs
52    # to get the real application.
53    if inspect.isfunction(attr):
54        try:
55            app = attr(*args, **kwargs)
56        except TypeError as e:
57            if not _called_with_wrong_args(attr):
58                raise
59
60            raise NoAppException(
61                f"The factory {app_name!r} in module"
62                f" {module.__name__!r} could not be called with the"
63                " specified arguments."
64            ) from e
65    else:
66        app = attr
67
68    if isinstance(app, Flask):
69        return app
70
71    raise NoAppException(
72        "A valid Flask application was not obtained from"
73        f" '{module.__name__}:{app_name}'."
74    )
            

Path 2: 3 calls (0.25)

module (3)

'testapp' (3)

Flask (3)

1def find_app_by_string(module, app_name):
2    """Check if the given string is a variable name or a function. Call
3    a function to get the app instance, or return the variable directly.
4    """
5    from . import Flask
6
7    # Parse app_name as a single expression to determine if it's a valid
8    # attribute name or function call.
9    try:
10        expr = ast.parse(app_name.strip(), mode="eval").body
11    except SyntaxError:
12        raise NoAppException(
13            f"Failed to parse {app_name!r} as an attribute name or function call."
14        ) from None
15
16    if isinstance(expr, ast.Name):
17        name = expr.id
18        args = []
19        kwargs = {}
20    elif isinstance(expr, ast.Call):
21        # Ensure the function name is an attribute name only.
22        if not isinstance(expr.func, ast.Name):
23            raise NoAppException(
24                f"Function reference must be a simple name: {app_name!r}."
25            )
26
27        name = expr.func.id
28
29        # Parse the positional and keyword arguments as literals.
30        try:
31            args = [ast.literal_eval(arg) for arg in expr.args]
32            kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in expr.keywords}
33        except ValueError:
34            # literal_eval gives cryptic error messages, show a generic
35            # message with the full expression instead.
36            raise NoAppException(
37                f"Failed to parse arguments as literal values: {app_name!r}."
38            ) from None
39    else:
40        raise NoAppException(
41            f"Failed to parse {app_name!r} as an attribute name or function call."
42        )
43
44    try:
45        attr = getattr(module, name)
46    except AttributeError as e:
47        raise NoAppException(
48            f"Failed to find attribute {name!r} in {module.__name__!r}."
49        ) from e
50
51    # If the attribute is a function, call it with any args and kwargs
52    # to get the real application.
53    if inspect.isfunction(attr):
54        try:
55            app = attr(*args, **kwargs)
56        except TypeError as e:
57            if not _called_with_wrong_args(attr):
58                raise
59
60            raise NoAppException(
61                f"The factory {app_name!r} in module"
62                f" {module.__name__!r} could not be called with the"
63                " specified arguments."
64            ) from e
65    else:
66        app = attr
67
68    if isinstance(app, Flask):
69        return app
70
71    raise NoAppException(
72        "A valid Flask application was not obtained from"
73        f" '{module.__name__}:{app_name}'."
74    )
            

Path 3: 1 calls (0.08)

module (1)

'create_app' (1)

Flask (1)

1def find_app_by_string(module, app_name):
2    """Check if the given string is a variable name or a function. Call
3    a function to get the app instance, or return the variable directly.
4    """
5    from . import Flask
6
7    # Parse app_name as a single expression to determine if it's a valid
8    # attribute name or function call.
9    try:
10        expr = ast.parse(app_name.strip(), mode="eval").body
11    except SyntaxError:
12        raise NoAppException(
13            f"Failed to parse {app_name!r} as an attribute name or function call."
14        ) from None
15
16    if isinstance(expr, ast.Name):
17        name = expr.id
18        args = []
19        kwargs = {}
20    elif isinstance(expr, ast.Call):
21        # Ensure the function name is an attribute name only.
22        if not isinstance(expr.func, ast.Name):
23            raise NoAppException(
24                f"Function reference must be a simple name: {app_name!r}."
25            )
26
27        name = expr.func.id
28
29        # Parse the positional and keyword arguments as literals.
30        try:
31            args = [ast.literal_eval(arg) for arg in expr.args]
32            kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in expr.keywords}
33        except ValueError:
34            # literal_eval gives cryptic error messages, show a generic
35            # message with the full expression instead.
36            raise NoAppException(
37                f"Failed to parse arguments as literal values: {app_name!r}."
38            ) from None
39    else:
40        raise NoAppException(
41            f"Failed to parse {app_name!r} as an attribute name or function call."
42        )
43
44    try:
45        attr = getattr(module, name)
46    except AttributeError as e:
47        raise NoAppException(
48            f"Failed to find attribute {name!r} in {module.__name__!r}."
49        ) from e
50
51    # If the attribute is a function, call it with any args and kwargs
52    # to get the real application.
53    if inspect.isfunction(attr):
54        try:
55            app = attr(*args, **kwargs)
56        except TypeError as e:
57            if not _called_with_wrong_args(attr):
58                raise
59
60            raise NoAppException(
61                f"The factory {app_name!r} in module"
62                f" {module.__name__!r} could not be called with the"
63                " specified arguments."
64            ) from e
65    else:
66        app = attr
67
68    if isinstance(app, Flask):
69        return app
70
71    raise NoAppException(
72        "A valid Flask application was not obtained from"
73        f" '{module.__name__}:{app_name}'."
74    )
            

Path 4: 1 calls (0.08)

module (1)

'notanapp' (1)

NoAppException (1)

1def find_app_by_string(module, app_name):
2    """Check if the given string is a variable name or a function. Call
3    a function to get the app instance, or return the variable directly.
4    """
5    from . import Flask
6
7    # Parse app_name as a single expression to determine if it's a valid
8    # attribute name or function call.
9    try:
10        expr = ast.parse(app_name.strip(), mode="eval").body
11    except SyntaxError:
12        raise NoAppException(
13            f"Failed to parse {app_name!r} as an attribute name or function call."
14        ) from None
15
16    if isinstance(expr, ast.Name):
17        name = expr.id
18        args = []
19        kwargs = {}
20    elif isinstance(expr, ast.Call):
21        # Ensure the function name is an attribute name only.
22        if not isinstance(expr.func, ast.Name):
23            raise NoAppException(
24                f"Function reference must be a simple name: {app_name!r}."
25            )
26
27        name = expr.func.id
28
29        # Parse the positional and keyword arguments as literals.
30        try:
31            args = [ast.literal_eval(arg) for arg in expr.args]
32            kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in expr.keywords}
33        except ValueError:
34            # literal_eval gives cryptic error messages, show a generic
35            # message with the full expression instead.
36            raise NoAppException(
37                f"Failed to parse arguments as literal values: {app_name!r}."
38            ) from None
39    else:
40        raise NoAppException(
41            f"Failed to parse {app_name!r} as an attribute name or function call."
42        )
43
44    try:
45        attr = getattr(module, name)
46    except AttributeError as e:
47        raise NoAppException(
48            f"Failed to find attribute {name!r} in {module.__name__!r}."
49        ) from e
50
51    # If the attribute is a function, call it with any args and kwargs
52    # to get the real application.
53    if inspect.isfunction(attr):
54        try:
55            app = attr(*args, **kwargs)
56        except TypeError as e:
57            if not _called_with_wrong_args(attr):
58                raise
59
60            raise NoAppException(
61                f"The factory {app_name!r} in module"
62                f" {module.__name__!r} could not be called with the"
63                " specified arguments."
64            ) from e
65    else:
66        app = attr
67
68    if isinstance(app, Flask):
69        return app
70
71    raise NoAppException(
72        "A valid Flask application was not obtained from"
73        f" '{module.__name__}:{app_name}'."
74    )
            

Path 5: 1 calls (0.08)

module (1)

'create_app2("foo")' (1)

NoAppException (1)

1def find_app_by_string(module, app_name):
2    """Check if the given string is a variable name or a function. Call
3    a function to get the app instance, or return the variable directly.
4    """
5    from . import Flask
6
7    # Parse app_name as a single expression to determine if it's a valid
8    # attribute name or function call.
9    try:
10        expr = ast.parse(app_name.strip(), mode="eval").body
11    except SyntaxError:
12        raise NoAppException(
13            f"Failed to parse {app_name!r} as an attribute name or function call."
14        ) from None
15
16    if isinstance(expr, ast.Name):
17        name = expr.id
18        args = []
19        kwargs = {}
20    elif isinstance(expr, ast.Call):
21        # Ensure the function name is an attribute name only.
22        if not isinstance(expr.func, ast.Name):
23            raise NoAppException(
24                f"Function reference must be a simple name: {app_name!r}."
25            )
26
27        name = expr.func.id
28
29        # Parse the positional and keyword arguments as literals.
30        try:
31            args = [ast.literal_eval(arg) for arg in expr.args]
32            kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in expr.keywords}
33        except ValueError:
34            # literal_eval gives cryptic error messages, show a generic
35            # message with the full expression instead.
36            raise NoAppException(
37                f"Failed to parse arguments as literal values: {app_name!r}."
38            ) from None
39    else:
40        raise NoAppException(
41            f"Failed to parse {app_name!r} as an attribute name or function call."
42        )
43
44    try:
45        attr = getattr(module, name)
46    except AttributeError as e:
47        raise NoAppException(
48            f"Failed to find attribute {name!r} in {module.__name__!r}."
49        ) from e
50
51    # If the attribute is a function, call it with any args and kwargs
52    # to get the real application.
53    if inspect.isfunction(attr):
54        try:
55            app = attr(*args, **kwargs)
56        except TypeError as e:
57            if not _called_with_wrong_args(attr):
58                raise
59
60            raise NoAppException(
61                f"The factory {app_name!r} in module"
62                f" {module.__name__!r} could not be called with the"
63                " specified arguments."
64            ) from e
65    else:
66        app = attr
67
68    if isinstance(app, Flask):
69        return app
70
71    raise NoAppException(
72        "A valid Flask application was not obtained from"
73        f" '{module.__name__}:{app_name}'."
74    )
            

Path 6: 1 calls (0.08)

module (1)

'create_app(' (1)

NoAppException (1)

1def find_app_by_string(module, app_name):
2    """Check if the given string is a variable name or a function. Call
3    a function to get the app instance, or return the variable directly.
4    """
5    from . import Flask
6
7    # Parse app_name as a single expression to determine if it's a valid
8    # attribute name or function call.
9    try:
10        expr = ast.parse(app_name.strip(), mode="eval").body
11    except SyntaxError:
12        raise NoAppException(
13            f"Failed to parse {app_name!r} as an attribute name or function call."
14        ) from None
15
16    if isinstance(expr, ast.Name):
17        name = expr.id
18        args = []
19        kwargs = {}
20    elif isinstance(expr, ast.Call):
21        # Ensure the function name is an attribute name only.
22        if not isinstance(expr.func, ast.Name):
23            raise NoAppException(
24                f"Function reference must be a simple name: {app_name!r}."
25            )
26
27        name = expr.func.id
28
29        # Parse the positional and keyword arguments as literals.
30        try:
31            args = [ast.literal_eval(arg) for arg in expr.args]
32            kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in expr.keywords}
33        except ValueError:
34            # literal_eval gives cryptic error messages, show a generic
35            # message with the full expression instead.
36            raise NoAppException(
37                f"Failed to parse arguments as literal values: {app_name!r}."
38            ) from None
39    else:
40        raise NoAppException(
41            f"Failed to parse {app_name!r} as an attribute name or function call."
42        )
43
44    try:
45        attr = getattr(module, name)
46    except AttributeError as e:
47        raise NoAppException(
48            f"Failed to find attribute {name!r} in {module.__name__!r}."
49        ) from e
50
51    # If the attribute is a function, call it with any args and kwargs
52    # to get the real application.
53    if inspect.isfunction(attr):
54        try:
55            app = attr(*args, **kwargs)
56        except TypeError as e:
57            if not _called_with_wrong_args(attr):
58                raise
59
60            raise NoAppException(
61                f"The factory {app_name!r} in module"
62                f" {module.__name__!r} could not be called with the"
63                " specified arguments."
64            ) from e
65    else:
66        app = attr
67
68    if isinstance(app, Flask):
69        return app
70
71    raise NoAppException(
72        "A valid Flask application was not obtained from"
73        f" '{module.__name__}:{app_name}'."
74    )
            

Path 7: 1 calls (0.08)

module (1)

'no_app' (1)

NoAppException (1)

1def find_app_by_string(module, app_name):
2    """Check if the given string is a variable name or a function. Call
3    a function to get the app instance, or return the variable directly.
4    """
5    from . import Flask
6
7    # Parse app_name as a single expression to determine if it's a valid
8    # attribute name or function call.
9    try:
10        expr = ast.parse(app_name.strip(), mode="eval").body
11    except SyntaxError:
12        raise NoAppException(
13            f"Failed to parse {app_name!r} as an attribute name or function call."
14        ) from None
15
16    if isinstance(expr, ast.Name):
17        name = expr.id
18        args = []
19        kwargs = {}
20    elif isinstance(expr, ast.Call):
21        # Ensure the function name is an attribute name only.
22        if not isinstance(expr.func, ast.Name):
23            raise NoAppException(
24                f"Function reference must be a simple name: {app_name!r}."
25            )
26
27        name = expr.func.id
28
29        # Parse the positional and keyword arguments as literals.
30        try:
31            args = [ast.literal_eval(arg) for arg in expr.args]
32            kwargs = {kw.arg: ast.literal_eval(kw.value) for kw in expr.keywords}
33        except ValueError:
34            # literal_eval gives cryptic error messages, show a generic
35            # message with the full expression instead.
36            raise NoAppException(
37                f"Failed to parse arguments as literal values: {app_name!r}."
38            ) from None
39    else:
40        raise NoAppException(
41            f"Failed to parse {app_name!r} as an attribute name or function call."
42        )
43
44    try:
45        attr = getattr(module, name)
46    except AttributeError as e:
47        raise NoAppException(
48            f"Failed to find attribute {name!r} in {module.__name__!r}."
49        ) from e
50
51    # If the attribute is a function, call it with any args and kwargs
52    # to get the real application.
53    if inspect.isfunction(attr):
54        try:
55            app = attr(*args, **kwargs)
56        except TypeError as e:
57            if not _called_with_wrong_args(attr):
58                raise
59
60            raise NoAppException(
61                f"The factory {app_name!r} in module"
62                f" {module.__name__!r} could not be called with the"
63                " specified arguments."
64            ) from e
65    else:
66        app = attr
67
68    if isinstance(app, Flask):
69        return app
70
71    raise NoAppException(
72        "A valid Flask application was not obtained from"
73        f" '{module.__name__}:{app_name}'."
74    )