The following issues were found

tests/test_basic.py
789 issues
A Flask app appears to be run with debug=True, which exposes the Werkzeug debugger and allows the execution of arbitrary code.
Security misconfiguration

Line: 1957
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b201_flask_debug_true.html

              
    monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)
    hostname, port = "localhost", 8000
    app.run(hostname, port, debug=True)
    assert rv["result"] == f"running on {hostname}:{port} ..."


@pytest.mark.parametrize(
    "host,port,server_name,expect_host,expect_port",

            

Reported by Bandit.

Unable to import 'pytest'
Error

Line: 11 Column: 1

              from platform import python_implementation
from threading import Thread

import pytest
import werkzeug.serving
from werkzeug.exceptions import BadRequest
from werkzeug.exceptions import Forbidden
from werkzeug.exceptions import NotFound
from werkzeug.http import parse_date

            

Reported by Pylint.

Unused variable 'index'
Error

Line: 30 Column: 5

              
def test_options_work(app, client):
    @app.route("/", methods=["GET", "POST"])
    def index():
        return "Hello World"

    rv = client.open("/", method="OPTIONS")
    assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]
    assert rv.data == b""

            

Reported by Pylint.

Unused variable 'index'
Error

Line: 40 Column: 5

              
def test_options_on_multiple_rules(app, client):
    @app.route("/", methods=["GET", "POST"])
    def index():
        return "Hello World"

    @app.route("/", methods=["PUT"])
    def index_put():
        return "Aha!"

            

Reported by Pylint.

Unused variable 'index_put'
Error

Line: 44 Column: 5

                      return "Hello World"

    @app.route("/", methods=["PUT"])
    def index_put():
        return "Aha!"

    rv = client.open("/", method="OPTIONS")
    assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST", "PUT"]


            

Reported by Pylint.

Unused variable 'hello'
Error

Line: 57 Column: 5

                  client_method = getattr(client, method)

    @method_route("/")
    def hello():
        return "Hello"

    assert client_method("/").data == b"Hello"



            

Reported by Pylint.

Unused variable 'index'
Error

Line: 129 Column: 5

              
def test_request_dispatching(app, client):
    @app.route("/")
    def index():
        return flask.request.method

    @app.route("/more", methods=["GET", "POST"])
    def more():
        return flask.request.method

            

Reported by Pylint.

Unused variable 'more'
Error

Line: 133 Column: 5

                      return flask.request.method

    @app.route("/more", methods=["GET", "POST"])
    def more():
        return flask.request.method

    assert client.get("/").data == b"GET"
    rv = client.post("/")
    assert rv.status_code == 405

            

Reported by Pylint.

Unused variable 'index'
Error

Line: 154 Column: 9

                  with pytest.raises(TypeError):

        @app.route("/", methods="GET POST")
        def index():
            return "Hey"


def test_url_mapping(app, client):
    random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"

            

Reported by Pylint.

Unused variable 'bar'
Error

Line: 222 Column: 5

                  )

    @app.endpoint("bar")
    def bar():
        return "bar"

    @app.endpoint("index")
    def index():
        return "index"

            

Reported by Pylint.

tests/test_blueprints.py
346 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest
from jinja2 import TemplateNotFound
from werkzeug.http import parse_cache_control_header

import flask


def test_blueprint_specific_error_handling(app, client):
    frontend = flask.Blueprint("frontend", __name__)

            

Reported by Pylint.

Unable to import 'blueprintapp'
Error

Line: 177 Column: 5

              

def test_templates_and_static(test_apps):
    from blueprintapp import app

    client = app.test_client()

    rv = client.get("/")
    assert rv.data == b"Hello from the Frontend"

            

Reported by Pylint.

Unable to import 'blueprintapp'
Error

Line: 248 Column: 5

              

def test_templates_list(test_apps):
    from blueprintapp import app

    templates = sorted(app.jinja_env.list_templates())
    assert templates == ["admin/index.html", "frontend/index.html"]



            

Reported by Pylint.

Instance of 'Blueprint' has no 'register_blueprint' member
Error

Line: 828 Column: 5

                  def grandchild_no():
        flask.abort(403)

    child.register_blueprint(grandchild, url_prefix="/grandchild")
    parent.register_blueprint(child, url_prefix="/child")
    app.register_blueprint(parent, url_prefix="/parent")

    assert client.get("/parent/").data == b"Parent yes"
    assert client.get("/parent/child/").data == b"Child yes"

            

Reported by Pylint.

Instance of 'Blueprint' has no 'register_blueprint' member
Error

Line: 829 Column: 5

                      flask.abort(403)

    child.register_blueprint(grandchild, url_prefix="/grandchild")
    parent.register_blueprint(child, url_prefix="/child")
    app.register_blueprint(parent, url_prefix="/parent")

    assert client.get("/parent/").data == b"Parent yes"
    assert client.get("/parent/child/").data == b"Child yes"
    assert client.get("/parent/child/grandchild/").data == b"Grandchild yes"

            

Reported by Pylint.

Instance of 'Blueprint' has no 'register_blueprint' member
Error

Line: 864 Column: 5

                  def index():
        return "index"

    parent.register_blueprint(child, url_prefix=child_registration)
    app.register_blueprint(parent, url_prefix=parent_registration)

    response = client.get("/parent/child/")
    assert response.status_code == 200


            

Reported by Pylint.

Instance of 'Blueprint' has no 'register_blueprint' member
Error

Line: 891 Column: 9

              def test_self_registration(app, client) -> None:
    bp = flask.Blueprint("bp", __name__)
    with pytest.raises(ValueError):
        bp.register_blueprint(bp)


def test_blueprint_renaming(app, client) -> None:
    bp = flask.Blueprint("bp", __name__)
    bp2 = flask.Blueprint("bp2", __name__)

            

Reported by Pylint.

Instance of 'Blueprint' has no 'get' member
Error

Line: 898 Column: 6

                  bp = flask.Blueprint("bp", __name__)
    bp2 = flask.Blueprint("bp2", __name__)

    @bp.get("/")
    def index():
        return flask.request.endpoint

    @bp.get("/error")
    def error():

            

Reported by Pylint.

Instance of 'Blueprint' has no 'get' member
Error

Line: 902 Column: 6

                  def index():
        return flask.request.endpoint

    @bp.get("/error")
    def error():
        flask.abort(403)

    @bp.errorhandler(403)
    def forbidden(_: Exception):

            

Reported by Pylint.

Instance of 'Blueprint' has no 'get' member
Error

Line: 910 Column: 6

                  def forbidden(_: Exception):
        return "Error", 403

    @bp2.get("/")
    def index2():
        return flask.request.endpoint

    bp.register_blueprint(bp2, url_prefix="/a", name="sub")
    app.register_blueprint(bp, url_prefix="/a")

            

Reported by Pylint.

tests/test_cli.py
229 issues
Unable to import 'pytest'
Error

Line: 12 Column: 1

              from unittest.mock import patch

import click
import pytest
from _pytest.monkeypatch import notset
from click.testing import CliRunner

from flask import Blueprint
from flask import current_app

            

Reported by Pylint.

Unable to import '_pytest.monkeypatch'
Error

Line: 13 Column: 1

              
import click
import pytest
from _pytest.monkeypatch import notset
from click.testing import CliRunner

from flask import Blueprint
from flask import current_app
from flask import Flask

            

Reported by Pylint.

Unable to import 'cliapp.app'
Error

Line: 45 Column: 5

              
def test_cli_name(test_apps):
    """Make sure the CLI object's name is the app's name and not the app itself"""
    from cliapp.app import testapp

    assert testapp.cli.name == testapp.name


def test_find_best_app(test_apps):

            

Reported by Pylint.

class already defined line 53
Error

Line: 58 Column: 5

              
    assert find_best_app(script_info, Module) == Module.app

    class Module:
        application = Flask("appname")

    assert find_best_app(script_info, Module) == Module.application

    class Module:

            

Reported by Pylint.

class already defined line 53
Error

Line: 63 Column: 5

              
    assert find_best_app(script_info, Module) == Module.application

    class Module:
        myapp = Flask("appname")

    assert find_best_app(script_info, Module) == Module.myapp

    class Module:

            

Reported by Pylint.

class already defined line 53
Error

Line: 68 Column: 5

              
    assert find_best_app(script_info, Module) == Module.myapp

    class Module:
        @staticmethod
        def create_app():
            return Flask("appname")

    app = find_best_app(script_info, Module)

            

Reported by Pylint.

class already defined line 53
Error

Line: 77 Column: 5

                  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)

            

Reported by Pylint.

class already defined line 53
Error

Line: 86 Column: 5

                  assert isinstance(app, Flask)
    assert app.name == "appname"

    class Module:
        @staticmethod
        def create_app(foo):
            return Flask("appname")

    with pytest.deprecated_call(match="Script info"):

            

Reported by Pylint.

class already defined line 53
Error

Line: 97 Column: 5

                  assert isinstance(app, Flask)
    assert app.name == "appname"

    class Module:
        @staticmethod
        def create_app(foo=None, script_info=None):
            return Flask("appname")

    with pytest.deprecated_call(match="script_info"):

            

Reported by Pylint.

class already defined line 53
Error

Line: 108 Column: 5

                  assert isinstance(app, Flask)
    assert app.name == "appname"

    class Module:
        @staticmethod
        def make_app():
            return Flask("appname")

    app = find_best_app(script_info, Module)

            

Reported by Pylint.

tests/test_templating.py
179 issues
A Flask app appears to be run with debug=True, which exposes the Werkzeug debugger and allows the execution of arbitrary code.
Security misconfiguration

Line: 394
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b201_flask_debug_true.html

                  assert not app.templates_auto_reload
    assert not app.jinja_env.auto_reload

    app.run(debug=True)
    assert app.templates_auto_reload
    assert app.jinja_env.auto_reload


def test_template_loader_debugging(test_apps, monkeypatch):

            

Reported by Bandit.

Unable to import 'pytest'
Error

Line: 3 Column: 1

              import logging

import pytest
import werkzeug.serving
from jinja2 import TemplateNotFound

import flask



            

Reported by Pylint.

Unable to import 'blueprintapp'
Error

Line: 400 Column: 5

              

def test_template_loader_debugging(test_apps, monkeypatch):
    from blueprintapp import app

    called = []

    class _TestHandler(logging.Handler):
        def handle(self, record):

            

Reported by Pylint.

Unused variable 'context_processor'
Error

Line: 12 Column: 5

              
def test_context_processing(app, client):
    @app.context_processor
    def context_processor():
        return {"injected_value": 42}

    @app.route("/")
    def index():
        return flask.render_template("context_template.html", value=23)

            

Reported by Pylint.

Unused variable 'index'
Error

Line: 16 Column: 5

                      return {"injected_value": 42}

    @app.route("/")
    def index():
        return flask.render_template("context_template.html", value=23)

    rv = client.get("/")
    assert rv.data == b"<p>23|42"


            

Reported by Pylint.

Unused variable 'index'
Error

Line: 25 Column: 5

              
def test_original_win(app, client):
    @app.route("/")
    def index():
        return flask.render_template_string("{{ config }}", config=42)

    rv = client.get("/")
    assert rv.data == b"42"


            

Reported by Pylint.

Unused argument 'app_ctx'
Error

Line: 32 Column: 38

                  assert rv.data == b"42"


def test_request_less_rendering(app, app_ctx):
    app.config["WORLD_NAME"] = "Special World"

    @app.context_processor
    def context_processor():
        return dict(foo=42)

            

Reported by Pylint.

Unused variable 'context_processor'
Error

Line: 36 Column: 5

                  app.config["WORLD_NAME"] = "Special World"

    @app.context_processor
    def context_processor():
        return dict(foo=42)

    rv = flask.render_template_string("Hello {{ config.WORLD_NAME }} {{ foo }}")
    assert rv == "Hello Special World 42"


            

Reported by Pylint.

Unused variable 'index'
Error

Line: 45 Column: 5

              
def test_standard_context(app, client):
    @app.route("/")
    def index():
        flask.g.foo = 23
        flask.session["test"] = "aha"
        return flask.render_template_string(
            """
            {{ request.args.foo }}

            

Reported by Pylint.

Unused variable 'index'
Error

Line: 65 Column: 5

                  text = "<p>Hello World!"

    @app.route("/")
    def index():
        return flask.render_template(
            "escaping_template.html", text=text, html=flask.Markup(text)
        )

    lines = client.get("/").data.splitlines()

            

Reported by Pylint.

tests/test_testing.py
167 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import click
import pytest
import werkzeug

import flask
from flask import appcontext_popped
from flask.cli import ScriptInfo
from flask.json import jsonify
from flask.testing import EnvironBuilder

            

Reported by Pylint.

Unused variable 'index'
Error

Line: 23 Column: 5

                  app.config["APPLICATION_ROOT"] = "/foo"

    @app.route("/")
    def index():
        return flask.request.url

    ctx = app.test_request_context()
    assert ctx.request.url == "http://example.com:1234/foo/"


            

Reported by Pylint.

Unused argument 'app_ctx'
Error

Line: 33 Column: 40

                  assert rv.data == b"http://example.com:1234/foo/"


def test_environ_defaults(app, client, app_ctx, req_ctx):
    @app.route("/")
    def index():
        return flask.request.url

    ctx = app.test_request_context()

            

Reported by Pylint.

Unused argument 'req_ctx'
Error

Line: 33 Column: 49

                  assert rv.data == b"http://example.com:1234/foo/"


def test_environ_defaults(app, client, app_ctx, req_ctx):
    @app.route("/")
    def index():
        return flask.request.url

    ctx = app.test_request_context()

            

Reported by Pylint.

Unused variable 'index'
Error

Line: 35 Column: 5

              
def test_environ_defaults(app, client, app_ctx, req_ctx):
    @app.route("/")
    def index():
        return flask.request.url

    ctx = app.test_request_context()
    assert ctx.request.url == "http://localhost/"
    with client:

            

Reported by Pylint.

Unused argument 'app_ctx'
Error

Line: 45 Column: 44

                      assert rv.data == b"http://localhost/"


def test_environ_base_default(app, client, app_ctx):
    @app.route("/")
    def index():
        flask.g.user_agent = flask.request.headers["User-Agent"]
        return flask.request.remote_addr


            

Reported by Pylint.

Unused variable 'index'
Error

Line: 47 Column: 5

              
def test_environ_base_default(app, client, app_ctx):
    @app.route("/")
    def index():
        flask.g.user_agent = flask.request.headers["User-Agent"]
        return flask.request.remote_addr

    rv = client.get("/")
    assert rv.data == b"127.0.0.1"

            

Reported by Pylint.

Unused argument 'app_ctx'
Error

Line: 56 Column: 45

                  assert flask.g.user_agent == f"werkzeug/{werkzeug.__version__}"


def test_environ_base_modified(app, client, app_ctx):
    @app.route("/")
    def index():
        flask.g.user_agent = flask.request.headers["User-Agent"]
        return flask.request.remote_addr


            

Reported by Pylint.

Unused variable 'index'
Error

Line: 58 Column: 5

              
def test_environ_base_modified(app, client, app_ctx):
    @app.route("/")
    def index():
        flask.g.user_agent = flask.request.headers["User-Agent"]
        return flask.request.remote_addr

    client.environ_base["REMOTE_ADDR"] = "0.0.0.0"
    client.environ_base["HTTP_USER_AGENT"] = "Foo"

            

Reported by Pylint.

Possible binding to all interfaces.
Security

Line: 62
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b104_hardcoded_bind_all_interfaces.html

                      flask.g.user_agent = flask.request.headers["User-Agent"]
        return flask.request.remote_addr

    client.environ_base["REMOTE_ADDR"] = "0.0.0.0"
    client.environ_base["HTTP_USER_AGENT"] = "Foo"
    rv = client.get("/")
    assert rv.data == b"0.0.0.0"
    assert flask.g.user_agent == "Foo"


            

Reported by Bandit.

src/flask/app.py
138 issues
No name 'ContextVar' in module 'werkzeug.local'
Error

Line: 19 Column: 1

              from werkzeug.exceptions import BadRequestKeyError
from werkzeug.exceptions import HTTPException
from werkzeug.exceptions import InternalServerError
from werkzeug.local import ContextVar
from werkzeug.routing import BuildError
from werkzeug.routing import Map
from werkzeug.routing import MapAdapter
from werkzeug.routing import RequestRedirect
from werkzeug.routing import RoutingException

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 28 Column: 1

              from werkzeug.routing import Rule
from werkzeug.wrappers import Response as BaseResponse

from . import cli
from . import json
from .config import Config
from .config import ConfigAttribute
from .ctx import _AppCtxGlobals
from .ctx import AppContext

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 29 Column: 1

              from werkzeug.wrappers import Response as BaseResponse

from . import cli
from . import json
from .config import Config
from .config import ConfigAttribute
from .ctx import _AppCtxGlobals
from .ctx import AppContext
from .ctx import RequestContext

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 30 Column: 1

              
from . import cli
from . import json
from .config import Config
from .config import ConfigAttribute
from .ctx import _AppCtxGlobals
from .ctx import AppContext
from .ctx import RequestContext
from .globals import _request_ctx_stack

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 31 Column: 1

              from . import cli
from . import json
from .config import Config
from .config import ConfigAttribute
from .ctx import _AppCtxGlobals
from .ctx import AppContext
from .ctx import RequestContext
from .globals import _request_ctx_stack
from .globals import g

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 32 Column: 1

              from . import json
from .config import Config
from .config import ConfigAttribute
from .ctx import _AppCtxGlobals
from .ctx import AppContext
from .ctx import RequestContext
from .globals import _request_ctx_stack
from .globals import g
from .globals import request

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 33 Column: 1

              from .config import Config
from .config import ConfigAttribute
from .ctx import _AppCtxGlobals
from .ctx import AppContext
from .ctx import RequestContext
from .globals import _request_ctx_stack
from .globals import g
from .globals import request
from .globals import session

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 34 Column: 1

              from .config import ConfigAttribute
from .ctx import _AppCtxGlobals
from .ctx import AppContext
from .ctx import RequestContext
from .globals import _request_ctx_stack
from .globals import g
from .globals import request
from .globals import session
from .helpers import _split_blueprint_path

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 35 Column: 1

              from .ctx import _AppCtxGlobals
from .ctx import AppContext
from .ctx import RequestContext
from .globals import _request_ctx_stack
from .globals import g
from .globals import request
from .globals import session
from .helpers import _split_blueprint_path
from .helpers import get_debug_flag

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 36 Column: 1

              from .ctx import AppContext
from .ctx import RequestContext
from .globals import _request_ctx_stack
from .globals import g
from .globals import request
from .globals import session
from .helpers import _split_blueprint_path
from .helpers import get_debug_flag
from .helpers import get_env

            

Reported by Pylint.

tests/test_helpers.py
125 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              import io
import os

import pytest

import flask
from flask.helpers import get_debug_flag
from flask.helpers import get_env


            

Reported by Pylint.

Unused argument 'req_ctx'
Error

Line: 34 Column: 35

              

class TestSendfile:
    def test_send_file(self, app, req_ctx):
        rv = flask.send_file("static/index.html")
        assert rv.direct_passthrough
        assert rv.mimetype == "text/html"

        with app.open_resource("static/index.html") as f:

            

Reported by Pylint.

Unused argument 'req_ctx'
Error

Line: 45 Column: 37

              
        rv.close()

    def test_static_file(self, app, req_ctx):
        # Default max_age is None.

        # Test with static file handler.
        rv = app.send_static_file("index.html")
        assert rv.cache_control.max_age is None

            

Reported by Pylint.

Unused argument 'req_ctx'
Error

Line: 92 Column: 45

                          assert rv.cache_control.max_age == 10
            rv.close()

    def test_send_from_directory(self, app, req_ctx):
        app.root_path = os.path.join(
            os.path.dirname(__file__), "test_apps", "subdomaintestmodule"
        )
        rv = flask.send_from_directory("static", "hello.txt")
        rv.direct_passthrough = False

            

Reported by Pylint.

Unused argument 'req_ctx'
Error

Line: 103 Column: 45

              

class TestUrlFor:
    def test_url_for_with_anchor(self, app, req_ctx):
        @app.route("/")
        def index():
            return "42"

        assert flask.url_for("index", _anchor="x y") == "/#x%20y"

            

Reported by Pylint.

Unused variable 'index'
Error

Line: 105 Column: 9

              class TestUrlFor:
    def test_url_for_with_anchor(self, app, req_ctx):
        @app.route("/")
        def index():
            return "42"

        assert flask.url_for("index", _anchor="x y") == "/#x%20y"

    def test_url_for_with_scheme(self, app, req_ctx):

            

Reported by Pylint.

Unused argument 'req_ctx'
Error

Line: 110 Column: 45

              
        assert flask.url_for("index", _anchor="x y") == "/#x%20y"

    def test_url_for_with_scheme(self, app, req_ctx):
        @app.route("/")
        def index():
            return "42"

        assert (

            

Reported by Pylint.

Unused variable 'index'
Error

Line: 112 Column: 9

              
    def test_url_for_with_scheme(self, app, req_ctx):
        @app.route("/")
        def index():
            return "42"

        assert (
            flask.url_for("index", _external=True, _scheme="https")
            == "https://localhost/"

            

Reported by Pylint.

Unused argument 'req_ctx'
Error

Line: 120 Column: 58

                          == "https://localhost/"
        )

    def test_url_for_with_scheme_not_external(self, app, req_ctx):
        @app.route("/")
        def index():
            return "42"

        pytest.raises(ValueError, flask.url_for, "index", _scheme="https")

            

Reported by Pylint.

Unused variable 'index'
Error

Line: 122 Column: 9

              
    def test_url_for_with_scheme_not_external(self, app, req_ctx):
        @app.route("/")
        def index():
            return "42"

        pytest.raises(ValueError, flask.url_for, "index", _scheme="https")

    def test_url_for_with_alternating_schemes(self, app, req_ctx):

            

Reported by Pylint.

tests/test_user_error_handler.py
118 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest
from werkzeug.exceptions import Forbidden
from werkzeug.exceptions import HTTPException
from werkzeug.exceptions import InternalServerError
from werkzeug.exceptions import NotFound

import flask



            

Reported by Pylint.

Unused variable 'custom_exception_handler'
Error

Line: 18 Column: 5

                      pass

    @app.errorhandler(CustomException)
    def custom_exception_handler(e):
        assert isinstance(e, CustomException)
        return "custom"

    with pytest.raises(
        AssertionError, match="Custom exceptions must be subclasses of Exception."

            

Reported by Pylint.

Unused variable 'handle_500'
Error

Line: 28 Column: 5

                      app.register_error_handler(UnacceptableCustomException, None)

    @app.errorhandler(500)
    def handle_500(e):
        assert isinstance(e, InternalServerError)
        original = getattr(e, "original_exception", None)

        if original is not None:
            return f"wrapped {type(original).__name__}"

            

Reported by Pylint.

Unused variable 'custom_test'
Error

Line: 38 Column: 5

                      return "direct"

    @app.route("/custom")
    def custom_test():
        raise CustomException()

    @app.route("/keyerror")
    def key_error():
        raise KeyError()

            

Reported by Pylint.

Unused variable 'key_error'
Error

Line: 42 Column: 5

                      raise CustomException()

    @app.route("/keyerror")
    def key_error():
        raise KeyError()

    @app.route("/abort")
    def do_abort():
        flask.abort(500)

            

Reported by Pylint.

Unused variable 'do_abort'
Error

Line: 46 Column: 5

                      raise KeyError()

    @app.route("/abort")
    def do_abort():
        flask.abort(500)

    app.testing = False
    assert client.get("/custom").data == b"custom"
    assert client.get("/keyerror").data == b"wrapped KeyError"

            

Reported by Pylint.

Unused variable 'parent_exception_handler'
Error

Line: 66 Column: 5

                      pass

    @app.errorhandler(ParentException)
    def parent_exception_handler(e):
        assert isinstance(e, ParentException)
        return "parent"

    @app.errorhandler(ChildExceptionRegistered)
    def child_exception_handler(e):

            

Reported by Pylint.

Unused variable 'child_exception_handler'
Error

Line: 71 Column: 5

                      return "parent"

    @app.errorhandler(ChildExceptionRegistered)
    def child_exception_handler(e):
        assert isinstance(e, ChildExceptionRegistered)
        return "child-registered"

    @app.route("/parent")
    def parent_test():

            

Reported by Pylint.

Unused variable 'parent_test'
Error

Line: 76 Column: 5

                      return "child-registered"

    @app.route("/parent")
    def parent_test():
        raise ParentException()

    @app.route("/child-unregistered")
    def unregistered_test():
        raise ChildExceptionUnregistered()

            

Reported by Pylint.

Unused variable 'unregistered_test'
Error

Line: 80 Column: 5

                      raise ParentException()

    @app.route("/child-unregistered")
    def unregistered_test():
        raise ChildExceptionUnregistered()

    @app.route("/child-registered")
    def registered_test():
        raise ChildExceptionRegistered()

            

Reported by Pylint.

tests/test_json.py
109 issues
Unable to import 'pytest'
Error

Line: 6 Column: 1

              import io
import uuid

import pytest
from werkzeug.http import http_date

import flask
from flask import json


            

Reported by Pylint.

An attribute defined in simplejson.decoder line 351 hides this method
Error

Line: 239 Column: 9

                          kwargs.setdefault("object_hook", self.object_hook)
            flask.json.JSONDecoder.__init__(self, *args, **kwargs)

        def object_hook(self, obj):
            if len(obj) == 1 and "_foo" in obj:
                return X(obj["_foo"])
            return obj

    app.json_encoder = MyEncoder

            

Reported by Pylint.

An attribute defined in simplejson.decoder line 351 hides this method
Error

Line: 278 Column: 9

                          kwargs.setdefault("object_hook", self.object_hook)
            flask.json.JSONDecoder.__init__(self, *args, **kwargs)

        def object_hook(self, obj):
            if len(obj) == 1 and "_foo" in obj:
                return X(obj["_foo"])

            return obj


            

Reported by Pylint.

Unused variable 'post_json'
Error

Line: 19 Column: 5

                  app.config["TRAP_BAD_REQUEST_ERRORS"] = False

    @app.route("/json", methods=["POST"])
    def post_json():
        flask.request.get_json()
        return None

    rv = client.post("/json", data=None, content_type="application/json")
    assert rv.status_code == 400

            

Reported by Pylint.

Unused variable 'return_json'
Error

Line: 31 Column: 5

              
def test_json_bad_requests(app, client):
    @app.route("/json", methods=["POST"])
    def return_json():
        return flask.jsonify(foo=str(flask.request.get_json()))

    rv = client.post("/json", data="malformed", content_type="application/json")
    assert rv.status_code == 400


            

Reported by Pylint.

Unused variable 'return_json'
Error

Line: 40 Column: 5

              
def test_json_custom_mimetypes(app, client):
    @app.route("/json", methods=["POST"])
    def return_json():
        return flask.request.get_json()

    rv = client.post("/json", data='"foo"', content_type="application/x+json")
    assert rv.data == b"foo"


            

Reported by Pylint.

Unused argument 'app_ctx'
Error

Line: 50 Column: 53

              @pytest.mark.parametrize(
    "test_value,expected", [(True, '"\\u2603"'), (False, '"\u2603"')]
)
def test_json_as_unicode(test_value, expected, app, app_ctx):

    app.config["JSON_AS_ASCII"] = test_value
    rv = flask.json.dumps("\N{SNOWMAN}")
    assert rv == expected


            

Reported by Pylint.

Unused argument 'app_ctx'
Error

Line: 57 Column: 33

                  assert rv == expected


def test_json_dump_to_file(app, app_ctx):
    test_data = {"name": "Flask"}
    out = io.StringIO()

    flask.json.dump(test_data, out)
    out.seek(0)

            

Reported by Pylint.

Unused argument 'app'
Error

Line: 57 Column: 28

                  assert rv == expected


def test_json_dump_to_file(app, app_ctx):
    test_data = {"name": "Flask"}
    out = io.StringIO()

    flask.json.dump(test_data, out)
    out.seek(0)

            

Reported by Pylint.

Unused variable 'return_kwargs'
Error

Line: 92 Column: 5

                  }

    @app.route("/kw")
    def return_kwargs():
        return flask.jsonify(**d)

    @app.route("/dict")
    def return_dict():
        return flask.jsonify(d)

            

Reported by Pylint.

tests/test_views.py
109 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest
from werkzeug.http import parse_set_header

import flask.views


def common_test(app):
    c = app.test_client()


            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 44 Column: 13

              def test_view_patching(app):
    class Index(flask.views.MethodView):
        def get(self):
            1 // 0

        def post(self):
            1 // 0

    class Other(Index):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 47 Column: 13

                          1 // 0

        def post(self):
            1 // 0

    class Other(Index):
        def get(self):
            return "GET"


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest
from werkzeug.http import parse_set_header

import flask.views


def common_test(app):
    c = app.test_client()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 7 Column: 1

              import flask.views


def common_test(app):
    c = app.test_client()

    assert c.get("/").data == b"GET"
    assert c.post("/").data == b"POST"
    assert c.put("/").status_code == 405

            

Reported by Pylint.

Variable name "c" doesn't conform to snake_case naming style
Error

Line: 8 Column: 5

              

def common_test(app):
    c = app.test_client()

    assert c.get("/").data == b"GET"
    assert c.post("/").data == b"POST"
    assert c.put("/").status_code == 405
    meths = parse_set_header(c.open("/", method="OPTIONS").headers["Allow"])

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 10
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def common_test(app):
    c = app.test_client()

    assert c.get("/").data == b"GET"
    assert c.post("/").data == b"POST"
    assert c.put("/").status_code == 405
    meths = parse_set_header(c.open("/", method="OPTIONS").headers["Allow"])
    assert sorted(meths) == ["GET", "HEAD", "OPTIONS", "POST"]


            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 11
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  c = app.test_client()

    assert c.get("/").data == b"GET"
    assert c.post("/").data == b"POST"
    assert c.put("/").status_code == 405
    meths = parse_set_header(c.open("/", method="OPTIONS").headers["Allow"])
    assert sorted(meths) == ["GET", "HEAD", "OPTIONS", "POST"]



            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 12
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
    assert c.get("/").data == b"GET"
    assert c.post("/").data == b"POST"
    assert c.put("/").status_code == 405
    meths = parse_set_header(c.open("/", method="OPTIONS").headers["Allow"])
    assert sorted(meths) == ["GET", "HEAD", "OPTIONS", "POST"]


def test_basic_view(app):

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 14
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  assert c.post("/").data == b"POST"
    assert c.put("/").status_code == 405
    meths = parse_set_header(c.open("/", method="OPTIONS").headers["Allow"])
    assert sorted(meths) == ["GET", "HEAD", "OPTIONS", "POST"]


def test_basic_view(app):
    class Index(flask.views.View):
        methods = ["GET", "POST"]

            

Reported by Bandit.