The following issues were found

tests/test_tutorial/test_background_tasks/test_tutorial002.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              import os
from pathlib import Path

from fastapi.testclient import TestClient

from docs_src.background_tasks.tutorial002 import app

client = TestClient(app)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 1

              client = TestClient(app)


def test():
    log = Path("log.txt")
    if log.is_file():
        os.remove(log)  # pragma: no cover
    response = client.post("/send-notification/foo@example.com?q=some-query")
    assert response.status_code == 200, response.text

            

Reported by Pylint.

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

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

                  if log.is_file():
        os.remove(log)  # pragma: no cover
    response = client.post("/send-notification/foo@example.com?q=some-query")
    assert response.status_code == 200, response.text
    assert response.json() == {"message": "Message sent"}
    with open("./log.txt") as f:
        assert "found query: some-query\nmessage to foo@example.com" in f.read()

            

Reported by Bandit.

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

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

                      os.remove(log)  # pragma: no cover
    response = client.post("/send-notification/foo@example.com?q=some-query")
    assert response.status_code == 200, response.text
    assert response.json() == {"message": "Message sent"}
    with open("./log.txt") as f:
        assert "found query: some-query\nmessage to foo@example.com" in f.read()

            

Reported by Bandit.

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

Line: 18 Column: 31

                  response = client.post("/send-notification/foo@example.com?q=some-query")
    assert response.status_code == 200, response.text
    assert response.json() == {"message": "Message sent"}
    with open("./log.txt") as f:
        assert "found query: some-query\nmessage to foo@example.com" in f.read()

            

Reported by Pylint.

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

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

                  assert response.status_code == 200, response.text
    assert response.json() == {"message": "Message sent"}
    with open("./log.txt") as f:
        assert "found query: some-query\nmessage to foo@example.com" in f.read()

            

Reported by Bandit.

docs_src/app_testing/test_main.py
6 issues
Unable to import 'fastapi.testclient'
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from .main import app

client = TestClient(app)


def test_read_main():
    response = client.get("/")

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 3 Column: 1

              from fastapi.testclient import TestClient

from .main import app

client = TestClient(app)


def test_read_main():
    response = client.get("/")

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from .main import app

client = TestClient(app)


def test_read_main():
    response = client.get("/")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              client = TestClient(app)


def test_read_main():
    response = client.get("/")
    assert response.status_code == 200
    assert response.json() == {"msg": "Hello World"}

            

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 test_read_main():
    response = client.get("/")
    assert response.status_code == 200
    assert response.json() == {"msg": "Hello World"}

            

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

              def test_read_main():
    response = client.get("/")
    assert response.status_code == 200
    assert response.json() == {"msg": "Hello World"}

            

Reported by Bandit.

docs_src/websockets/tutorial001.py
6 issues
Unable to import 'fastapi'
Error

Line: 1 Column: 1

              from fastapi import FastAPI, WebSocket
from fastapi.responses import HTMLResponse

app = FastAPI()

html = """
<!DOCTYPE html>
<html>
    <head>

            

Reported by Pylint.

Unable to import 'fastapi.responses'
Error

Line: 2 Column: 1

              from fastapi import FastAPI, WebSocket
from fastapi.responses import HTMLResponse

app = FastAPI()

html = """
<!DOCTYPE html>
<html>
    <head>

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi import FastAPI, WebSocket
from fastapi.responses import HTMLResponse

app = FastAPI()

html = """
<!DOCTYPE html>
<html>
    <head>

            

Reported by Pylint.

Constant name "html" doesn't conform to UPPER_CASE naming style
Error

Line: 6 Column: 1

              
app = FastAPI()

html = """
<!DOCTYPE html>
<html>
    <head>
        <title>Chat</title>
    </head>

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 42 Column: 1

              

@app.get("/")
async def get():
    return HTMLResponse(html)


@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 47 Column: 1

              

@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
    await websocket.accept()
    while True:
        data = await websocket.receive_text()
        await websocket.send_text(f"Message text was: {data}")

            

Reported by Pylint.

docs_src/bigger_applications/app/routers/items.py
6 issues
Unable to import 'fastapi'
Error

Line: 1 Column: 1

              from fastapi import APIRouter, Depends, HTTPException

from ..dependencies import get_token_header

router = APIRouter(
    prefix="/items",
    tags=["items"],
    dependencies=[Depends(get_token_header)],
    responses={404: {"description": "Not found"}},

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 3 Column: 1

              from fastapi import APIRouter, Depends, HTTPException

from ..dependencies import get_token_header

router = APIRouter(
    prefix="/items",
    tags=["items"],
    dependencies=[Depends(get_token_header)],
    responses={404: {"description": "Not found"}},

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi import APIRouter, Depends, HTTPException

from ..dependencies import get_token_header

router = APIRouter(
    prefix="/items",
    tags=["items"],
    dependencies=[Depends(get_token_header)],
    responses={404: {"description": "Not found"}},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 1

              

@router.get("/")
async def read_items():
    return fake_items_db


@router.get("/{item_id}")
async def read_item(item_id: str):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 1

              

@router.get("/{item_id}")
async def read_item(item_id: str):
    if item_id not in fake_items_db:
        raise HTTPException(status_code=404, detail="Item not found")
    return {"name": fake_items_db[item_id]["name"], "item_id": item_id}



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 1

                  "/{item_id}",
    tags=["custom"],
    responses={403: {"description": "Operation forbidden"}},
)
async def update_item(item_id: str):
    if item_id != "plumbus":
        raise HTTPException(
            status_code=403, detail="You can only update the item: plumbus"
        )

            

Reported by Pylint.

docs_src/path_operation_configuration/tutorial005.py
5 issues
Unable to import 'fastapi'
Error

Line: 3 Column: 1

              from typing import Optional, Set

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):

            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 4 Column: 1

              from typing import Optional, Set

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Optional, Set

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              app = FastAPI()


class Item(BaseModel):
    name: str
    description: Optional[str] = None
    price: float
    tax: Optional[float] = None
    tags: Set[str] = []

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 9 Column: 1

              app = FastAPI()


class Item(BaseModel):
    name: str
    description: Optional[str] = None
    price: float
    tax: Optional[float] = None
    tags: Set[str] = []

            

Reported by Pylint.

tests/test_tutorial/test_query_params/test_tutorial006.py
5 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest
from fastapi.testclient import TestClient

from docs_src.query_params.tutorial006 import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest
from fastapi.testclient import TestClient

from docs_src.query_params.tutorial006 import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 132 Column: 1

                                      "loc": ["query", "limit"],
                        "msg": "value is not a valid integer",
                        "type": "type_error.integer",
                    },
                ]
            },
        ),
    ],
)

            

Reported by Pylint.

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

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

              )
def test(path, expected_status, expected_response):
    response = client.get(path)
    assert response.status_code == expected_status
    assert response.json() == expected_response

            

Reported by Bandit.

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

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

              def test(path, expected_status, expected_response):
    response = client.get(path)
    assert response.status_code == expected_status
    assert response.json() == expected_response

            

Reported by Bandit.

docs_src/path_operation_advanced_configuration/tutorial004.py
5 issues
Unable to import 'fastapi'
Error

Line: 3 Column: 1

              from typing import Optional, Set

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):

            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 4 Column: 1

              from typing import Optional, Set

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Optional, Set

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              app = FastAPI()


class Item(BaseModel):
    name: str
    description: Optional[str] = None
    price: float
    tax: Optional[float] = None
    tags: Set[str] = []

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 9 Column: 1

              app = FastAPI()


class Item(BaseModel):
    name: str
    description: Optional[str] = None
    price: float
    tax: Optional[float] = None
    tags: Set[str] = []

            

Reported by Pylint.

tests/test_tutorial/test_query_params/test_tutorial005.py
5 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest
from fastapi.testclient import TestClient

from docs_src.query_params.tutorial005 import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest
from fastapi.testclient import TestClient

from docs_src.query_params.tutorial005 import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 99 Column: 1

                      ("/items/foo?needy=very", 200, {"item_id": "foo", "needy": "very"}),
        ("/items/foo", 422, query_required),
        ("/items/foo", 422, query_required),
    ],
)
def test(path, expected_status, expected_response):
    response = client.get(path)
    assert response.status_code == expected_status
    assert response.json() == expected_response

            

Reported by Pylint.

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

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

              )
def test(path, expected_status, expected_response):
    response = client.get(path)
    assert response.status_code == expected_status
    assert response.json() == expected_response

            

Reported by Bandit.

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

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

              def test(path, expected_status, expected_response):
    response = client.get(path)
    assert response.status_code == expected_status
    assert response.json() == expected_response

            

Reported by Bandit.

docs_src/path_operation_advanced_configuration/tutorial002.py
5 issues
Unable to import 'fastapi'
Error

Line: 1 Column: 1

              from fastapi import FastAPI
from fastapi.routing import APIRoute

app = FastAPI()


@app.get("/items/")
async def read_items():
    return [{"item_id": "Foo"}]

            

Reported by Pylint.

Unable to import 'fastapi.routing'
Error

Line: 2 Column: 1

              from fastapi import FastAPI
from fastapi.routing import APIRoute

app = FastAPI()


@app.get("/items/")
async def read_items():
    return [{"item_id": "Foo"}]

            

Reported by Pylint.

Redefining name 'app' from outer scope (line 4)
Error

Line: 12 Column: 38

                  return [{"item_id": "Foo"}]


def use_route_names_as_operation_ids(app: FastAPI) -> None:
    """
    Simplify operation IDs so that generated API clients have simpler function
    names.

    Should be called only after all routes have been added.

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi import FastAPI
from fastapi.routing import APIRoute

app = FastAPI()


@app.get("/items/")
async def read_items():
    return [{"item_id": "Foo"}]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              

@app.get("/items/")
async def read_items():
    return [{"item_id": "Foo"}]


def use_route_names_as_operation_ids(app: FastAPI) -> None:
    """

            

Reported by Pylint.

docs_src/settings/app03/main.py
5 issues
Unable to import 'fastapi'
Error

Line: 3 Column: 1

              from functools import lru_cache

from fastapi import Depends, FastAPI

from . import config

app = FastAPI()



            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 5 Column: 1

              
from fastapi import Depends, FastAPI

from . import config

app = FastAPI()


@lru_cache()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from functools import lru_cache

from fastapi import Depends, FastAPI

from . import config

app = FastAPI()



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 1

              

@lru_cache()
def get_settings():
    return config.Settings()


@app.get("/info")
async def info(settings: config.Settings = Depends(get_settings)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 1

              

@app.get("/info")
async def info(settings: config.Settings = Depends(get_settings)):
    return {
        "app_name": settings.app_name,
        "admin_email": settings.admin_email,
        "items_per_user": settings.items_per_user,
    }

            

Reported by Pylint.