The following issues were found

docs_src/additional_responses/tutorial001.py
10 issues
Unable to import 'fastapi'
Error

Line: 1 Column: 1

              from fastapi import FastAPI
from fastapi.responses import JSONResponse
from pydantic import BaseModel


class Item(BaseModel):
    id: str
    value: str


            

Reported by Pylint.

Unable to import 'fastapi.responses'
Error

Line: 2 Column: 1

              from fastapi import FastAPI
from fastapi.responses import JSONResponse
from pydantic import BaseModel


class Item(BaseModel):
    id: str
    value: str


            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 3 Column: 1

              from fastapi import FastAPI
from fastapi.responses import JSONResponse
from pydantic import BaseModel


class Item(BaseModel):
    id: str
    value: str


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi import FastAPI
from fastapi.responses import JSONResponse
from pydantic import BaseModel


class Item(BaseModel):
    id: str
    value: str


            

Reported by Pylint.

Missing class docstring
Error

Line: 6 Column: 1

              from pydantic import BaseModel


class Item(BaseModel):
    id: str
    value: str


class Message(BaseModel):

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 6 Column: 1

              from pydantic import BaseModel


class Item(BaseModel):
    id: str
    value: str


class Message(BaseModel):

            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

                  value: str


class Message(BaseModel):
    message: str


app = FastAPI()


            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 11 Column: 1

                  value: str


class Message(BaseModel):
    message: str


app = FastAPI()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

              

@app.get("/items/{item_id}", response_model=Item, responses={404: {"model": Message}})
async def read_item(item_id: str):
    if item_id == "foo":
        return {"id": "foo", "value": "there goes my hero"}
    else:
        return JSONResponse(status_code=404, content={"message": "Item not found"})

            

Reported by Pylint.

Unnecessary "else" after "return"
Error

Line: 20 Column: 5

              
@app.get("/items/{item_id}", response_model=Item, responses={404: {"model": Message}})
async def read_item(item_id: str):
    if item_id == "foo":
        return {"id": "foo", "value": "there goes my hero"}
    else:
        return JSONResponse(status_code=404, content={"message": "Item not found"})

            

Reported by Pylint.

tests/test_tutorial/test_body_nested_models/test_tutorial009.py
10 issues
Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.body_nested_models.tutorial009 import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",
    "info": {"title": "FastAPI", "version": "0.1.0"},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 78 Column: 1

              }


def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema



            

Reported by Pylint.

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

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

              
def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_post_body():
    data = {"2": 2.2, "3": 3.3}

            

Reported by Bandit.

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

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

              def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_post_body():
    data = {"2": 2.2, "3": 3.3}
    response = client.post("/index-weights/", json=data)

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 84 Column: 1

                  assert response.json() == openapi_schema


def test_post_body():
    data = {"2": 2.2, "3": 3.3}
    response = client.post("/index-weights/", json=data)
    assert response.status_code == 200, response.text
    assert response.json() == data


            

Reported by Pylint.

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

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

              def test_post_body():
    data = {"2": 2.2, "3": 3.3}
    response = client.post("/index-weights/", json=data)
    assert response.status_code == 200, response.text
    assert response.json() == data


def test_post_invalid_body():
    data = {"foo": 2.2, "3": 3.3}

            

Reported by Bandit.

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

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

                  data = {"2": 2.2, "3": 3.3}
    response = client.post("/index-weights/", json=data)
    assert response.status_code == 200, response.text
    assert response.json() == data


def test_post_invalid_body():
    data = {"foo": 2.2, "3": 3.3}
    response = client.post("/index-weights/", json=data)

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 91 Column: 1

                  assert response.json() == data


def test_post_invalid_body():
    data = {"foo": 2.2, "3": 3.3}
    response = client.post("/index-weights/", json=data)
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [

            

Reported by Pylint.

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

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

              def test_post_invalid_body():
    data = {"foo": 2.2, "3": 3.3}
    response = client.post("/index-weights/", json=data)
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
            {
                "loc": ["body", "__key__"],
                "msg": "value is not a valid integer",

            

Reported by Bandit.

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

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

                  data = {"foo": 2.2, "3": 3.3}
    response = client.post("/index-weights/", json=data)
    assert response.status_code == 422, response.text
    assert response.json() == {
        "detail": [
            {
                "loc": ["body", "__key__"],
                "msg": "value is not a valid integer",
                "type": "type_error.integer",

            

Reported by Bandit.

tests/test_tutorial/test_query_params_str_validations/test_tutorial012.py
10 issues
Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.query_params_str_validations.tutorial012 import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",
    "info": {"title": "FastAPI", "version": "0.1.0"},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 79 Column: 1

              }


def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema



            

Reported by Pylint.

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

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

              
def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_default_query_values():
    url = "/items/"

            

Reported by Bandit.

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

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

              def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_default_query_values():
    url = "/items/"
    response = client.get(url)

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 85 Column: 1

                  assert response.json() == openapi_schema


def test_default_query_values():
    url = "/items/"
    response = client.get(url)
    assert response.status_code == 200, response.text
    assert response.json() == {"q": ["foo", "bar"]}


            

Reported by Pylint.

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

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

              def test_default_query_values():
    url = "/items/"
    response = client.get(url)
    assert response.status_code == 200, response.text
    assert response.json() == {"q": ["foo", "bar"]}


def test_multi_query_values():
    url = "/items/?q=baz&q=foobar"

            

Reported by Bandit.

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

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

                  url = "/items/"
    response = client.get(url)
    assert response.status_code == 200, response.text
    assert response.json() == {"q": ["foo", "bar"]}


def test_multi_query_values():
    url = "/items/?q=baz&q=foobar"
    response = client.get(url)

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 92 Column: 1

                  assert response.json() == {"q": ["foo", "bar"]}


def test_multi_query_values():
    url = "/items/?q=baz&q=foobar"
    response = client.get(url)
    assert response.status_code == 200, response.text
    assert response.json() == {"q": ["baz", "foobar"]}

            

Reported by Pylint.

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

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

              def test_multi_query_values():
    url = "/items/?q=baz&q=foobar"
    response = client.get(url)
    assert response.status_code == 200, response.text
    assert response.json() == {"q": ["baz", "foobar"]}

            

Reported by Bandit.

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

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

                  url = "/items/?q=baz&q=foobar"
    response = client.get(url)
    assert response.status_code == 200, response.text
    assert response.json() == {"q": ["baz", "foobar"]}

            

Reported by Bandit.

fastapi/exceptions.py
9 issues
Unable to import 'pydantic'
Error

Line: 3 Column: 1

              from typing import Any, Dict, Optional, Sequence, Type

from pydantic import BaseModel, ValidationError, create_model
from pydantic.error_wrappers import ErrorList
from starlette.exceptions import HTTPException as StarletteHTTPException


class HTTPException(StarletteHTTPException):
    def __init__(

            

Reported by Pylint.

Unable to import 'pydantic.error_wrappers'
Error

Line: 4 Column: 1

              from typing import Any, Dict, Optional, Sequence, Type

from pydantic import BaseModel, ValidationError, create_model
from pydantic.error_wrappers import ErrorList
from starlette.exceptions import HTTPException as StarletteHTTPException


class HTTPException(StarletteHTTPException):
    def __init__(

            

Reported by Pylint.

Unable to import 'starlette.exceptions'
Error

Line: 5 Column: 1

              
from pydantic import BaseModel, ValidationError, create_model
from pydantic.error_wrappers import ErrorList
from starlette.exceptions import HTTPException as StarletteHTTPException


class HTTPException(StarletteHTTPException):
    def __init__(
        self,

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Any, Dict, Optional, Sequence, Type

from pydantic import BaseModel, ValidationError, create_model
from pydantic.error_wrappers import ErrorList
from starlette.exceptions import HTTPException as StarletteHTTPException


class HTTPException(StarletteHTTPException):
    def __init__(

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              from starlette.exceptions import HTTPException as StarletteHTTPException


class HTTPException(StarletteHTTPException):
    def __init__(
        self,
        status_code: int,
        detail: Any = None,
        headers: Optional[Dict[str, Any]] = None,

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 29 Column: 1

                  """


class RequestValidationError(ValidationError):
    def __init__(self, errors: Sequence[ErrorList], *, body: Any = None) -> None:
        self.body = body
        super().__init__(errors, RequestErrorModel)



            

Reported by Pylint.

Missing class docstring
Error

Line: 29 Column: 1

                  """


class RequestValidationError(ValidationError):
    def __init__(self, errors: Sequence[ErrorList], *, body: Any = None) -> None:
        self.body = body
        super().__init__(errors, RequestErrorModel)



            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 35 Column: 1

                      super().__init__(errors, RequestErrorModel)


class WebSocketRequestValidationError(ValidationError):
    def __init__(self, errors: Sequence[ErrorList]) -> None:
        super().__init__(errors, WebSocketErrorModel)

            

Reported by Pylint.

Missing class docstring
Error

Line: 35 Column: 1

                      super().__init__(errors, RequestErrorModel)


class WebSocketRequestValidationError(ValidationError):
    def __init__(self, errors: Sequence[ErrorList]) -> None:
        super().__init__(errors, WebSocketErrorModel)

            

Reported by Pylint.

docs_src/custom_request_and_route/tutorial002.py
9 issues
Unable to import 'fastapi'
Error

Line: 3 Column: 1

              from typing import Callable, List

from fastapi import Body, FastAPI, HTTPException, Request, Response
from fastapi.exceptions import RequestValidationError
from fastapi.routing import APIRoute


class ValidationErrorLoggingRoute(APIRoute):
    def get_route_handler(self) -> Callable:

            

Reported by Pylint.

Unable to import 'fastapi.exceptions'
Error

Line: 4 Column: 1

              from typing import Callable, List

from fastapi import Body, FastAPI, HTTPException, Request, Response
from fastapi.exceptions import RequestValidationError
from fastapi.routing import APIRoute


class ValidationErrorLoggingRoute(APIRoute):
    def get_route_handler(self) -> Callable:

            

Reported by Pylint.

Unable to import 'fastapi.routing'
Error

Line: 5 Column: 1

              
from fastapi import Body, FastAPI, HTTPException, Request, Response
from fastapi.exceptions import RequestValidationError
from fastapi.routing import APIRoute


class ValidationErrorLoggingRoute(APIRoute):
    def get_route_handler(self) -> Callable:
        original_route_handler = super().get_route_handler()

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 18 Column: 17

                          except RequestValidationError as exc:
                body = await request.body()
                detail = {"errors": exc.errors(), "body": body.decode()}
                raise HTTPException(status_code=422, detail=detail)

        return custom_route_handler


app = FastAPI()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Callable, List

from fastapi import Body, FastAPI, HTTPException, Request, Response
from fastapi.exceptions import RequestValidationError
from fastapi.routing import APIRoute


class ValidationErrorLoggingRoute(APIRoute):
    def get_route_handler(self) -> Callable:

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              from fastapi.routing import APIRoute


class ValidationErrorLoggingRoute(APIRoute):
    def get_route_handler(self) -> Callable:
        original_route_handler = super().get_route_handler()

        async def custom_route_handler(request: Request) -> Response:
            try:

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 8 Column: 1

              from fastapi.routing import APIRoute


class ValidationErrorLoggingRoute(APIRoute):
    def get_route_handler(self) -> Callable:
        original_route_handler = super().get_route_handler()

        async def custom_route_handler(request: Request) -> Response:
            try:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 5

              

class ValidationErrorLoggingRoute(APIRoute):
    def get_route_handler(self) -> Callable:
        original_route_handler = super().get_route_handler()

        async def custom_route_handler(request: Request) -> Response:
            try:
                return await original_route_handler(request)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 28 Column: 1

              

@app.post("/")
async def sum_numbers(numbers: List[int] = Body(...)):
    return sum(numbers)

            

Reported by Pylint.

docs_src/graphql/tutorial001.py
9 issues
Unable to import 'graphene'
Error

Line: 1 Column: 1

              import graphene
from fastapi import FastAPI
from starlette.graphql import GraphQLApp


class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="stranger"))

    def resolve_hello(self, info, name):

            

Reported by Pylint.

Unable to import 'fastapi'
Error

Line: 2 Column: 1

              import graphene
from fastapi import FastAPI
from starlette.graphql import GraphQLApp


class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="stranger"))

    def resolve_hello(self, info, name):

            

Reported by Pylint.

Unable to import 'starlette.graphql'
Error

Line: 3 Column: 1

              import graphene
from fastapi import FastAPI
from starlette.graphql import GraphQLApp


class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="stranger"))

    def resolve_hello(self, info, name):

            

Reported by Pylint.

Unused argument 'info'
Error

Line: 9 Column: 29

              class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="stranger"))

    def resolve_hello(self, info, name):
        return "Hello " + name


app = FastAPI()
app.add_route("/", GraphQLApp(schema=graphene.Schema(query=Query)))

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import graphene
from fastapi import FastAPI
from starlette.graphql import GraphQLApp


class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="stranger"))

    def resolve_hello(self, info, name):

            

Reported by Pylint.

Missing class docstring
Error

Line: 6 Column: 1

              from starlette.graphql import GraphQLApp


class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="stranger"))

    def resolve_hello(self, info, name):
        return "Hello " + name


            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 6 Column: 1

              from starlette.graphql import GraphQLApp


class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="stranger"))

    def resolve_hello(self, info, name):
        return "Hello " + name


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 5

              class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="stranger"))

    def resolve_hello(self, info, name):
        return "Hello " + name


app = FastAPI()
app.add_route("/", GraphQLApp(schema=graphene.Schema(query=Query)))

            

Reported by Pylint.

Method could be a function
Error

Line: 9 Column: 5

              class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="stranger"))

    def resolve_hello(self, info, name):
        return "Hello " + name


app = FastAPI()
app.add_route("/", GraphQLApp(schema=graphene.Schema(query=Query)))

            

Reported by Pylint.

docs_src/app_testing/main_b.py
9 issues
Unable to import 'fastapi'
Error

Line: 3 Column: 1

              from typing import Optional

from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel

fake_secret_token = "coneofsilence"

fake_db = {
    "foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"},

            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 4 Column: 1

              from typing import Optional

from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel

fake_secret_token = "coneofsilence"

fake_db = {
    "foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"},

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Optional

from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel

fake_secret_token = "coneofsilence"

fake_db = {
    "foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"},

            

Reported by Pylint.

Possible hardcoded password: 'coneofsilence'
Security

Line: 6
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b105_hardcoded_password_string.html

              from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel

fake_secret_token = "coneofsilence"

fake_db = {
    "foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"},
    "bar": {"id": "bar", "title": "Bar", "description": "The bartenders"},
}

            

Reported by Bandit.

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

Line: 6 Column: 1

              from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel

fake_secret_token = "coneofsilence"

fake_db = {
    "foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"},
    "bar": {"id": "bar", "title": "Bar", "description": "The bartenders"},
}

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 16 Column: 1

              app = FastAPI()


class Item(BaseModel):
    id: str
    title: str
    description: Optional[str] = None



            

Reported by Pylint.

Missing class docstring
Error

Line: 16 Column: 1

              app = FastAPI()


class Item(BaseModel):
    id: str
    title: str
    description: Optional[str] = None



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 1

              

@app.get("/items/{item_id}", response_model=Item)
async def read_main(item_id: str, x_token: str = Header(...)):
    if x_token != fake_secret_token:
        raise HTTPException(status_code=400, detail="Invalid X-Token header")
    if item_id not in fake_db:
        raise HTTPException(status_code=404, detail="Item not found")
    return fake_db[item_id]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 1

              

@app.post("/items/", response_model=Item)
async def create_item(item: Item, x_token: str = Header(...)):
    if x_token != fake_secret_token:
        raise HTTPException(status_code=400, detail="Invalid X-Token header")
    if item.id in fake_db:
        raise HTTPException(status_code=400, detail="Item already exists")
    fake_db[item.id] = item

            

Reported by Pylint.

docs_src/security/tutorial002.py
9 issues
Unable to import 'fastapi'
Error

Line: 3 Column: 1

              from typing import Optional

from fastapi import Depends, FastAPI
from fastapi.security import OAuth2PasswordBearer
from pydantic import BaseModel

app = FastAPI()

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

            

Reported by Pylint.

Unable to import 'fastapi.security'
Error

Line: 4 Column: 1

              from typing import Optional

from fastapi import Depends, FastAPI
from fastapi.security import OAuth2PasswordBearer
from pydantic import BaseModel

app = FastAPI()

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 5 Column: 1

              
from fastapi import Depends, FastAPI
from fastapi.security import OAuth2PasswordBearer
from pydantic import BaseModel

app = FastAPI()

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Optional

from fastapi import Depends, FastAPI
from fastapi.security import OAuth2PasswordBearer
from pydantic import BaseModel

app = FastAPI()

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

            

Reported by Pylint.

Missing class docstring
Error

Line: 12 Column: 1

              oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")


class User(BaseModel):
    username: str
    email: Optional[str] = None
    full_name: Optional[str] = None
    disabled: Optional[bool] = None


            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 12 Column: 1

              oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")


class User(BaseModel):
    username: str
    email: Optional[str] = None
    full_name: Optional[str] = None
    disabled: Optional[bool] = None


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

                  disabled: Optional[bool] = None


def fake_decode_token(token):
    return User(
        username=token + "fakedecoded", email="john@example.com", full_name="John Doe"
    )



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 25 Column: 1

                  )


async def get_current_user(token: str = Depends(oauth2_scheme)):
    user = fake_decode_token(token)
    return user


@app.get("/users/me")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 31 Column: 1

              

@app.get("/users/me")
async def read_users_me(current_user: User = Depends(get_current_user)):
    return current_user

            

Reported by Pylint.

docs_src/additional_responses/tutorial004.py
9 issues
Unable to import 'fastapi'
Error

Line: 3 Column: 1

              from typing import Optional

from fastapi import FastAPI
from fastapi.responses import FileResponse
from pydantic import BaseModel


class Item(BaseModel):
    id: str

            

Reported by Pylint.

Unable to import 'fastapi.responses'
Error

Line: 4 Column: 1

              from typing import Optional

from fastapi import FastAPI
from fastapi.responses import FileResponse
from pydantic import BaseModel


class Item(BaseModel):
    id: str

            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 5 Column: 1

              
from fastapi import FastAPI
from fastapi.responses import FileResponse
from pydantic import BaseModel


class Item(BaseModel):
    id: str
    value: str

            

Reported by Pylint.

Unused argument 'item_id'
Error

Line: 28 Column: 21

                  response_model=Item,
    responses={**responses, 200: {"content": {"image/png": {}}}},
)
async def read_item(item_id: str, img: Optional[bool] = None):
    if img:
        return FileResponse("image.png", media_type="image/png")
    else:
        return {"id": "foo", "value": "there goes my hero"}

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Optional

from fastapi import FastAPI
from fastapi.responses import FileResponse
from pydantic import BaseModel


class Item(BaseModel):
    id: str

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              from pydantic import BaseModel


class Item(BaseModel):
    id: str
    value: str


responses = {

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 8 Column: 1

              from pydantic import BaseModel


class Item(BaseModel):
    id: str
    value: str


responses = {

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 1

                  "/items/{item_id}",
    response_model=Item,
    responses={**responses, 200: {"content": {"image/png": {}}}},
)
async def read_item(item_id: str, img: Optional[bool] = None):
    if img:
        return FileResponse("image.png", media_type="image/png")
    else:
        return {"id": "foo", "value": "there goes my hero"}

            

Reported by Pylint.

Unnecessary "else" after "return"
Error

Line: 29 Column: 5

                  responses={**responses, 200: {"content": {"image/png": {}}}},
)
async def read_item(item_id: str, img: Optional[bool] = None):
    if img:
        return FileResponse("image.png", media_type="image/png")
    else:
        return {"id": "foo", "value": "there goes my hero"}

            

Reported by Pylint.

tests/test_tutorial/test_body_updates/test_tutorial001.py
9 issues
Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.body_updates.tutorial001 import app

client = TestClient(app)

openapi_schema = {
    "openapi": "3.0.2",
    "info": {"title": "FastAPI", "version": "0.1.0"},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 134 Column: 1

              }


def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema



            

Reported by Pylint.

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

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

              
def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_get():
    response = client.get("/items/baz")

            

Reported by Bandit.

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

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

              def test_openapi_schema():
    response = client.get("/openapi.json")
    assert response.status_code == 200, response.text
    assert response.json() == openapi_schema


def test_get():
    response = client.get("/items/baz")
    assert response.status_code == 200, response.text

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 140 Column: 1

                  assert response.json() == openapi_schema


def test_get():
    response = client.get("/items/baz")
    assert response.status_code == 200, response.text
    assert response.json() == {
        "name": "Baz",
        "description": None,

            

Reported by Pylint.

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

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

              
def test_get():
    response = client.get("/items/baz")
    assert response.status_code == 200, response.text
    assert response.json() == {
        "name": "Baz",
        "description": None,
        "price": 50.2,
        "tax": 10.5,

            

Reported by Bandit.

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

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

              def test_get():
    response = client.get("/items/baz")
    assert response.status_code == 200, response.text
    assert response.json() == {
        "name": "Baz",
        "description": None,
        "price": 50.2,
        "tax": 10.5,
        "tags": [],

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 152 Column: 1

                  }


def test_put():
    response = client.put(
        "/items/bar", json={"name": "Barz", "price": 3, "description": None}
    )
    assert response.json() == {
        "name": "Barz",

            

Reported by Pylint.

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

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

                  response = client.put(
        "/items/bar", json={"name": "Barz", "price": 3, "description": None}
    )
    assert response.json() == {
        "name": "Barz",
        "description": None,
        "price": 3,
        "tax": 10.5,
        "tags": [],

            

Reported by Bandit.