The following issues were found

tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py
21 issues
Redefining name 'client' from outer scope (line 5)
Error

Line: 167 Column: 5

                  path = tmp_path / "test.txt"
    path.write_bytes(b"<file content>")

    client = TestClient(app)
    with path.open("rb") as file:
        response = client.post("/files/", files={"file": file})
    assert response.status_code == 422, response.text
    assert response.json() == token_required


            

Reported by Pylint.

Redefining name 'client' from outer scope (line 5)
Error

Line: 180 Column: 5

                  patha.write_text("<file content>")
    pathb.write_text("<file b content>")

    client = TestClient(app)
    with patha.open("rb") as filea, pathb.open("rb") as fileb:
        response = client.post(
            "/files/",
            data={"token": "foo"},
            files={"file": filea, "fileb": ("testb.txt", fileb, "text/plain")},

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi.testclient import TestClient

from docs_src.request_forms_and_files.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: 86 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: 88
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


file_required = {
    "detail": [

            

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

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


file_required = {
    "detail": [
        {

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 145 Column: 1

              }


def test_post_form_no_body():
    response = client.post("/files/")
    assert response.status_code == 422, response.text
    assert response.json() == file_and_token_required



            

Reported by Pylint.

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

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

              
def test_post_form_no_body():
    response = client.post("/files/")
    assert response.status_code == 422, response.text
    assert response.json() == file_and_token_required


def test_post_form_no_file():
    response = client.post("/files/", data={"token": "foo"})

            

Reported by Bandit.

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

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

              def test_post_form_no_body():
    response = client.post("/files/")
    assert response.status_code == 422, response.text
    assert response.json() == file_and_token_required


def test_post_form_no_file():
    response = client.post("/files/", data={"token": "foo"})
    assert response.status_code == 422, response.text

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 151 Column: 1

                  assert response.json() == file_and_token_required


def test_post_form_no_file():
    response = client.post("/files/", data={"token": "foo"})
    assert response.status_code == 422, response.text
    assert response.json() == file_required



            

Reported by Pylint.

tests/test_security_http_basic_realm_description.py
21 issues
Missing module docstring
Error

Line: 1 Column: 1

              from base64 import b64encode

from fastapi import FastAPI, Security
from fastapi.security import HTTPBasic, HTTPBasicCredentials
from fastapi.testclient import TestClient
from requests.auth import HTTPBasicAuth

app = FastAPI()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 14 Column: 1

              

@app.get("/users/me")
def read_current_user(credentials: HTTPBasicCredentials = Security(security)):
    return {"username": credentials.username, "password": credentials.password}


client = TestClient(app)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 50 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: 52
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_security_http_basic():
    auth = HTTPBasicAuth(username="john", password="secret")

            

Reported by Bandit.

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

Line: 53
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_security_http_basic():
    auth = HTTPBasicAuth(username="john", password="secret")
    response = client.get("/users/me", auth=auth)

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 56 Column: 1

                  assert response.json() == openapi_schema


def test_security_http_basic():
    auth = HTTPBasicAuth(username="john", password="secret")
    response = client.get("/users/me", auth=auth)
    assert response.status_code == 200, response.text
    assert response.json() == {"username": "john", "password": "secret"}


            

Reported by Pylint.

Possible hardcoded password: 'secret'
Security

Line: 57
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b106_hardcoded_password_funcarg.html

              

def test_security_http_basic():
    auth = HTTPBasicAuth(username="john", password="secret")
    response = client.get("/users/me", auth=auth)
    assert response.status_code == 200, response.text
    assert response.json() == {"username": "john", "password": "secret"}



            

Reported by Bandit.

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

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

              def test_security_http_basic():
    auth = HTTPBasicAuth(username="john", password="secret")
    response = client.get("/users/me", auth=auth)
    assert response.status_code == 200, response.text
    assert response.json() == {"username": "john", "password": "secret"}


def test_security_http_basic_no_credentials():
    response = client.get("/users/me")

            

Reported by Bandit.

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

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

                  auth = HTTPBasicAuth(username="john", password="secret")
    response = client.get("/users/me", auth=auth)
    assert response.status_code == 200, response.text
    assert response.json() == {"username": "john", "password": "secret"}


def test_security_http_basic_no_credentials():
    response = client.get("/users/me")
    assert response.json() == {"detail": "Not authenticated"}

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 63 Column: 1

                  assert response.json() == {"username": "john", "password": "secret"}


def test_security_http_basic_no_credentials():
    response = client.get("/users/me")
    assert response.json() == {"detail": "Not authenticated"}
    assert response.status_code == 401, response.text
    assert response.headers["WWW-Authenticate"] == 'Basic realm="simple"'


            

Reported by Pylint.

tests/test_dependency_overrides.py
21 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              from typing import Optional

import pytest
from fastapi import APIRouter, Depends, FastAPI
from fastapi.testclient import TestClient

app = FastAPI()

router = APIRouter()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Optional

import pytest
from fastapi import APIRouter, Depends, FastAPI
from fastapi.testclient import TestClient

app = FastAPI()

router = APIRouter()

            

Reported by Pylint.

Argument name "q" doesn't conform to snake_case naming style
Error

Line: 12 Column: 1

              router = APIRouter()


async def common_parameters(q: str, skip: int = 0, limit: int = 100):
    return {"q": q, "skip": skip, "limit": limit}


@app.get("/main-depends/")
async def main_depends(commons: dict = Depends(common_parameters)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 1

              router = APIRouter()


async def common_parameters(q: str, skip: int = 0, limit: int = 100):
    return {"q": q, "skip": skip, "limit": limit}


@app.get("/main-depends/")
async def main_depends(commons: dict = Depends(common_parameters)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 1

              

@app.get("/main-depends/")
async def main_depends(commons: dict = Depends(common_parameters)):
    return {"in": "main-depends", "params": commons}


@app.get("/decorator-depends/", dependencies=[Depends(common_parameters)])
async def decorator_depends():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 1

              

@app.get("/decorator-depends/", dependencies=[Depends(common_parameters)])
async def decorator_depends():
    return {"in": "decorator-depends"}


@router.get("/router-depends/")
async def router_depends(commons: dict = Depends(common_parameters)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 1

              

@router.get("/router-depends/")
async def router_depends(commons: dict = Depends(common_parameters)):
    return {"in": "router-depends", "params": commons}


@router.get("/router-decorator-depends/", dependencies=[Depends(common_parameters)])
async def router_decorator_depends():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 1

              

@router.get("/router-decorator-depends/", dependencies=[Depends(common_parameters)])
async def router_decorator_depends():
    return {"in": "router-decorator-depends"}


app.include_router(router)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 41 Column: 1

              client = TestClient(app)


async def overrider_dependency_simple(q: Optional[str] = None):
    return {"q": q, "skip": 5, "limit": 10}


async def overrider_sub_dependency(k: str):
    return {"k": k}

            

Reported by Pylint.

Argument name "q" doesn't conform to snake_case naming style
Error

Line: 41 Column: 1

              client = TestClient(app)


async def overrider_dependency_simple(q: Optional[str] = None):
    return {"q": q, "skip": 5, "limit": 10}


async def overrider_sub_dependency(k: str):
    return {"k": k}

            

Reported by Pylint.

tests/test_starlette_exception.py
21 issues
Unable to import 'starlette.exceptions'
Error

Line: 3 Column: 1

              from fastapi import FastAPI, HTTPException
from fastapi.testclient import TestClient
from starlette.exceptions import HTTPException as StarletteHTTPException

app = FastAPI()

items = {"foo": "The Foo Wrestlers"}



            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from fastapi import FastAPI, HTTPException
from fastapi.testclient import TestClient
from starlette.exceptions import HTTPException as StarletteHTTPException

app = FastAPI()

items = {"foo": "The Foo Wrestlers"}



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 1

              

@app.get("/items/{item_id}")
async def read_item(item_id: str):
    if item_id not in items:
        raise HTTPException(
            status_code=404,
            detail="Item not found",
            headers={"X-Error": "Some custom header"},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 1

              

@app.get("/starlette-items/{item_id}")
async def read_starlette_item(item_id: str):
    if item_id not in items:
        raise StarletteHTTPException(status_code=404, detail="Item not found")
    return {"item": items[item_id]}



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 127 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: 129
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_item():
    response = client.get("/items/foo")

            

Reported by Bandit.

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

Line: 130
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_item():
    response = client.get("/items/foo")
    assert response.status_code == 200, response.text

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 133 Column: 1

                  assert response.json() == openapi_schema


def test_get_item():
    response = client.get("/items/foo")
    assert response.status_code == 200, response.text
    assert response.json() == {"item": "The Foo Wrestlers"}



            

Reported by Pylint.

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

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

              
def test_get_item():
    response = client.get("/items/foo")
    assert response.status_code == 200, response.text
    assert response.json() == {"item": "The Foo Wrestlers"}


def test_get_item_not_found():
    response = client.get("/items/bar")

            

Reported by Bandit.

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_get_item():
    response = client.get("/items/foo")
    assert response.status_code == 200, response.text
    assert response.json() == {"item": "The Foo Wrestlers"}


def test_get_item_not_found():
    response = client.get("/items/bar")
    assert response.status_code == 404, response.text

            

Reported by Bandit.

tests/test_dependency_cache.py
21 issues
Missing module docstring
Error

Line: 1 Column: 1

              from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient

app = FastAPI()

counter_holder = {"counter": 0}


async def dep_counter():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

              counter_holder = {"counter": 0}


async def dep_counter():
    counter_holder["counter"] += 1
    return counter_holder["counter"]


async def super_dep(count: int = Depends(dep_counter)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 14 Column: 1

                  return counter_holder["counter"]


async def super_dep(count: int = Depends(dep_counter)):
    return count


@app.get("/counter/")
async def get_counter(count: int = Depends(dep_counter)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

              

@app.get("/counter/")
async def get_counter(count: int = Depends(dep_counter)):
    return {"counter": count}


@app.get("/sub-counter/")
async def get_sub_counter(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 1

              

@app.get("/sub-counter/")
async def get_sub_counter(
    subcount: int = Depends(super_dep), count: int = Depends(dep_counter)
):
    return {"counter": count, "subcounter": subcount}



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 31 Column: 1

              

@app.get("/sub-counter-no-cache/")
async def get_sub_counter_no_cache(
    subcount: int = Depends(super_dep),
    count: int = Depends(dep_counter, use_cache=False),
):
    return {"counter": count, "subcounter": subcount}


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 41 Column: 1

              client = TestClient(app)


def test_normal_counter():
    counter_holder["counter"] = 0
    response = client.get("/counter/")
    assert response.status_code == 200, response.text
    assert response.json() == {"counter": 1}
    response = client.get("/counter/")

            

Reported by Pylint.

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

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

              def test_normal_counter():
    counter_holder["counter"] = 0
    response = client.get("/counter/")
    assert response.status_code == 200, response.text
    assert response.json() == {"counter": 1}
    response = client.get("/counter/")
    assert response.status_code == 200, response.text
    assert response.json() == {"counter": 2}


            

Reported by Bandit.

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

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

                  counter_holder["counter"] = 0
    response = client.get("/counter/")
    assert response.status_code == 200, response.text
    assert response.json() == {"counter": 1}
    response = client.get("/counter/")
    assert response.status_code == 200, response.text
    assert response.json() == {"counter": 2}



            

Reported by Bandit.

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

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

                  assert response.status_code == 200, response.text
    assert response.json() == {"counter": 1}
    response = client.get("/counter/")
    assert response.status_code == 200, response.text
    assert response.json() == {"counter": 2}


def test_sub_counter():
    counter_holder["counter"] = 0

            

Reported by Bandit.

tests/test_security_http_basic_realm.py
21 issues
Missing module docstring
Error

Line: 1 Column: 1

              from base64 import b64encode

from fastapi import FastAPI, Security
from fastapi.security import HTTPBasic, HTTPBasicCredentials
from fastapi.testclient import TestClient
from requests.auth import HTTPBasicAuth

app = FastAPI()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 14 Column: 1

              

@app.get("/users/me")
def read_current_user(credentials: HTTPBasicCredentials = Security(security)):
    return {"username": credentials.username, "password": credentials.password}


client = TestClient(app)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 44 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: 46
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_security_http_basic():
    auth = HTTPBasicAuth(username="john", password="secret")

            

Reported by Bandit.

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

Line: 47
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_security_http_basic():
    auth = HTTPBasicAuth(username="john", password="secret")
    response = client.get("/users/me", auth=auth)

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 50 Column: 1

                  assert response.json() == openapi_schema


def test_security_http_basic():
    auth = HTTPBasicAuth(username="john", password="secret")
    response = client.get("/users/me", auth=auth)
    assert response.status_code == 200, response.text
    assert response.json() == {"username": "john", "password": "secret"}


            

Reported by Pylint.

Possible hardcoded password: 'secret'
Security

Line: 51
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b106_hardcoded_password_funcarg.html

              

def test_security_http_basic():
    auth = HTTPBasicAuth(username="john", password="secret")
    response = client.get("/users/me", auth=auth)
    assert response.status_code == 200, response.text
    assert response.json() == {"username": "john", "password": "secret"}



            

Reported by Bandit.

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

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

              def test_security_http_basic():
    auth = HTTPBasicAuth(username="john", password="secret")
    response = client.get("/users/me", auth=auth)
    assert response.status_code == 200, response.text
    assert response.json() == {"username": "john", "password": "secret"}


def test_security_http_basic_no_credentials():
    response = client.get("/users/me")

            

Reported by Bandit.

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

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

                  auth = HTTPBasicAuth(username="john", password="secret")
    response = client.get("/users/me", auth=auth)
    assert response.status_code == 200, response.text
    assert response.json() == {"username": "john", "password": "secret"}


def test_security_http_basic_no_credentials():
    response = client.get("/users/me")
    assert response.json() == {"detail": "Not authenticated"}

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 57 Column: 1

                  assert response.json() == {"username": "john", "password": "secret"}


def test_security_http_basic_no_credentials():
    response = client.get("/users/me")
    assert response.json() == {"detail": "Not authenticated"}
    assert response.status_code == 401, response.text
    assert response.headers["WWW-Authenticate"] == 'Basic realm="simple"'


            

Reported by Pylint.

fastapi/utils.py
21 issues
Unable to import 'pydantic'
Error

Line: 10 Column: 1

              import fastapi
from fastapi.datastructures import DefaultPlaceholder, DefaultType
from fastapi.openapi.constants import REF_PREFIX
from pydantic import BaseConfig, BaseModel, create_model
from pydantic.class_validators import Validator
from pydantic.fields import FieldInfo, ModelField, UndefinedType
from pydantic.schema import model_process_schema
from pydantic.utils import lenient_issubclass


            

Reported by Pylint.

Unable to import 'pydantic.class_validators'
Error

Line: 11 Column: 1

              from fastapi.datastructures import DefaultPlaceholder, DefaultType
from fastapi.openapi.constants import REF_PREFIX
from pydantic import BaseConfig, BaseModel, create_model
from pydantic.class_validators import Validator
from pydantic.fields import FieldInfo, ModelField, UndefinedType
from pydantic.schema import model_process_schema
from pydantic.utils import lenient_issubclass



            

Reported by Pylint.

Unable to import 'pydantic.fields'
Error

Line: 12 Column: 1

              from fastapi.openapi.constants import REF_PREFIX
from pydantic import BaseConfig, BaseModel, create_model
from pydantic.class_validators import Validator
from pydantic.fields import FieldInfo, ModelField, UndefinedType
from pydantic.schema import model_process_schema
from pydantic.utils import lenient_issubclass


def get_model_definitions(

            

Reported by Pylint.

Unable to import 'pydantic.schema'
Error

Line: 13 Column: 1

              from pydantic import BaseConfig, BaseModel, create_model
from pydantic.class_validators import Validator
from pydantic.fields import FieldInfo, ModelField, UndefinedType
from pydantic.schema import model_process_schema
from pydantic.utils import lenient_issubclass


def get_model_definitions(
    *,

            

Reported by Pylint.

Unable to import 'pydantic.utils'
Error

Line: 14 Column: 1

              from pydantic.class_validators import Validator
from pydantic.fields import FieldInfo, ModelField, UndefinedType
from pydantic.schema import model_process_schema
from pydantic.utils import lenient_issubclass


def get_model_definitions(
    *,
    flat_models: Set[Union[Type[BaseModel], Type[Enum]]],

            

Reported by Pylint.

Unused variable 'm_nested_models'
Error

Line: 24 Column: 34

              ) -> Dict[str, Any]:
    definitions: Dict[str, Dict[str, Any]] = {}
    for model in flat_models:
        m_schema, m_definitions, m_nested_models = model_process_schema(
            model, model_name_map=model_name_map, ref_prefix=REF_PREFIX
        )
        definitions.update(m_definitions)
        model_name = model_name_map[model]
        definitions[model_name] = m_schema

            

Reported by Pylint.

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

Line: 67 Column: 9

                  try:
        return response_field(field_info=field_info)
    except RuntimeError:
        raise fastapi.exceptions.FastAPIError(
            f"Invalid args for response field! Hint: check that {type_} is a valid pydantic field type"
        )


def create_cloned_field(

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import functools
import re
from dataclasses import is_dataclass
from enum import Enum
from typing import Any, Dict, Optional, Set, Type, Union, cast

import fastapi
from fastapi.datastructures import DefaultPlaceholder, DefaultType
from fastapi.openapi.constants import REF_PREFIX

            

Reported by Pylint.

third party import "from pydantic import BaseConfig, BaseModel, create_model" should be placed before "import fastapi"
Error

Line: 10 Column: 1

              import fastapi
from fastapi.datastructures import DefaultPlaceholder, DefaultType
from fastapi.openapi.constants import REF_PREFIX
from pydantic import BaseConfig, BaseModel, create_model
from pydantic.class_validators import Validator
from pydantic.fields import FieldInfo, ModelField, UndefinedType
from pydantic.schema import model_process_schema
from pydantic.utils import lenient_issubclass


            

Reported by Pylint.

third party import "from pydantic.class_validators import Validator" should be placed before "import fastapi"
Error

Line: 11 Column: 1

              from fastapi.datastructures import DefaultPlaceholder, DefaultType
from fastapi.openapi.constants import REF_PREFIX
from pydantic import BaseConfig, BaseModel, create_model
from pydantic.class_validators import Validator
from pydantic.fields import FieldInfo, ModelField, UndefinedType
from pydantic.schema import model_process_schema
from pydantic.utils import lenient_issubclass



            

Reported by Pylint.

.github/actions/comment-docs-preview-in-pr/app/main.py
21 issues
Unable to import 'httpx'
Error

Line: 6 Column: 1

              from pathlib import Path
from typing import Optional

import httpx
from github import Github
from github.PullRequest import PullRequest
from pydantic import BaseModel, BaseSettings, SecretStr, ValidationError

github_api = "https://api.github.com"

            

Reported by Pylint.

Unable to import 'github'
Error

Line: 7 Column: 1

              from typing import Optional

import httpx
from github import Github
from github.PullRequest import PullRequest
from pydantic import BaseModel, BaseSettings, SecretStr, ValidationError

github_api = "https://api.github.com"


            

Reported by Pylint.

Unable to import 'github.PullRequest'
Error

Line: 8 Column: 1

              
import httpx
from github import Github
from github.PullRequest import PullRequest
from pydantic import BaseModel, BaseSettings, SecretStr, ValidationError

github_api = "https://api.github.com"



            

Reported by Pylint.

Unable to import 'pydantic'
Error

Line: 9 Column: 1

              import httpx
from github import Github
from github.PullRequest import PullRequest
from pydantic import BaseModel, BaseSettings, SecretStr, ValidationError

github_api = "https://api.github.com"


class Settings(BaseSettings):

            

Reported by Pylint.

Use lazy % formatting in logging functions
Error

Line: 37 Column: 5

              if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    settings = Settings()
    logging.info(f"Using config: {settings.json()}")
    g = Github(settings.input_token.get_secret_value())
    repo = g.get_repo(settings.github_repository)
    try:
        event = PartialGithubEvent.parse_file(settings.github_event_path)
    except ValidationError as e:

            

Reported by Pylint.

Use lazy % formatting in logging functions
Error

Line: 43 Column: 9

                  try:
        event = PartialGithubEvent.parse_file(settings.github_event_path)
    except ValidationError as e:
        logging.error(f"Error parsing event file: {e.errors()}")
        sys.exit(0)
    use_pr: Optional[PullRequest] = None
    for pr in repo.get_pulls():
        if pr.head.sha == event.workflow_run.head_commit.id:
            use_pr = pr

            

Reported by Pylint.

Use lazy % formatting in logging functions
Error

Line: 51 Column: 9

                          use_pr = pr
            break
    if not use_pr:
        logging.error(
            f"No PR found for hash: {event.workflow_run.head_commit.id}"
        )
        sys.exit(0)
    github_headers = {
        "Authorization": f"token {settings.input_token.get_secret_value()}"

            

Reported by Pylint.

Use lazy % formatting in logging functions
Error

Line: 59 Column: 5

                      "Authorization": f"token {settings.input_token.get_secret_value()}"
    }
    url = f"{github_api}/repos/{settings.github_repository}/issues/{use_pr.number}/comments"
    logging.info(f"Using comments URL: {url}")
    response = httpx.post(
        url,
        headers=github_headers,
        json={
            "body": f"📝 Docs preview for commit {use_pr.head.sha} at: {settings.input_deploy_url}"

            

Reported by Pylint.

Use lazy % formatting in logging functions
Error

Line: 68 Column: 9

                      },
    )
    if not (200 <= response.status_code <= 300):
        logging.error(f"Error posting comment: {response.text}")
        sys.exit(1)
    logging.info("Finished")

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import logging
import sys
from pathlib import Path
from typing import Optional

import httpx
from github import Github
from github.PullRequest import PullRequest
from pydantic import BaseModel, BaseSettings, SecretStr, ValidationError

            

Reported by Pylint.

fastapi/concurrency.py
21 issues
Unable to import 'starlette.concurrency'
Error

Line: 3 Column: 1

              from typing import Any, Callable

from starlette.concurrency import iterate_in_threadpool as iterate_in_threadpool  # noqa
from starlette.concurrency import run_in_threadpool as run_in_threadpool  # noqa
from starlette.concurrency import (  # noqa
    run_until_first_complete as run_until_first_complete,
)

asynccontextmanager_error_message = """

            

Reported by Pylint.

Unable to import 'starlette.concurrency'
Error

Line: 4 Column: 1

              from typing import Any, Callable

from starlette.concurrency import iterate_in_threadpool as iterate_in_threadpool  # noqa
from starlette.concurrency import run_in_threadpool as run_in_threadpool  # noqa
from starlette.concurrency import (  # noqa
    run_until_first_complete as run_until_first_complete,
)

asynccontextmanager_error_message = """

            

Reported by Pylint.

Unable to import 'starlette.concurrency'
Error

Line: 5 Column: 1

              
from starlette.concurrency import iterate_in_threadpool as iterate_in_threadpool  # noqa
from starlette.concurrency import run_in_threadpool as run_in_threadpool  # noqa
from starlette.concurrency import (  # noqa
    run_until_first_complete as run_until_first_complete,
)

asynccontextmanager_error_message = """
FastAPI's contextmanager_in_threadpool require Python 3.7 or above,

            

Reported by Pylint.

Unused iterate_in_threadpool imported from starlette.concurrency as iterate_in_threadpool
Error

Line: 3 Column: 1

              from typing import Any, Callable

from starlette.concurrency import iterate_in_threadpool as iterate_in_threadpool  # noqa
from starlette.concurrency import run_in_threadpool as run_in_threadpool  # noqa
from starlette.concurrency import (  # noqa
    run_until_first_complete as run_until_first_complete,
)

asynccontextmanager_error_message = """

            

Reported by Pylint.

Unused run_until_first_complete imported from starlette.concurrency as run_until_first_complete
Error

Line: 5 Column: 1

              
from starlette.concurrency import iterate_in_threadpool as iterate_in_threadpool  # noqa
from starlette.concurrency import run_in_threadpool as run_in_threadpool  # noqa
from starlette.concurrency import (  # noqa
    run_until_first_complete as run_until_first_complete,
)

asynccontextmanager_error_message = """
FastAPI's contextmanager_in_threadpool require Python 3.7 or above,

            

Reported by Pylint.

Unused argument 'func'
Error

Line: 16 Column: 31

              """


def _fake_asynccontextmanager(func: Callable[..., Any]) -> Callable[..., Any]:
    def raiser(*args: Any, **kwargs: Any) -> Any:
        raise RuntimeError(asynccontextmanager_error_message)

    return raiser


            

Reported by Pylint.

Unused AsyncExitStack imported from contextlib as AsyncExitStack
Error

Line: 34 Column: 5

                      asynccontextmanager = _fake_asynccontextmanager

try:
    from contextlib import AsyncExitStack as AsyncExitStack  # type: ignore
except ImportError:
    try:
        from async_exit_stack import AsyncExitStack as AsyncExitStack  # type: ignore
    except ImportError:  # pragma: no cover
        AsyncExitStack = None  # type: ignore

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 46 Column: 12

              async def contextmanager_in_threadpool(cm: Any) -> Any:
    try:
        yield await run_in_threadpool(cm.__enter__)
    except Exception as e:
        ok = await run_in_threadpool(cm.__exit__, type(e), e, None)
        if not ok:
            raise e
    else:
        await run_in_threadpool(cm.__exit__, None, None, None)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from typing import Any, Callable

from starlette.concurrency import iterate_in_threadpool as iterate_in_threadpool  # noqa
from starlette.concurrency import run_in_threadpool as run_in_threadpool  # noqa
from starlette.concurrency import (  # noqa
    run_until_first_complete as run_until_first_complete,
)

asynccontextmanager_error_message = """

            

Reported by Pylint.

Import alias does not rename original package
Error

Line: 3 Column: 1

              from typing import Any, Callable

from starlette.concurrency import iterate_in_threadpool as iterate_in_threadpool  # noqa
from starlette.concurrency import run_in_threadpool as run_in_threadpool  # noqa
from starlette.concurrency import (  # noqa
    run_until_first_complete as run_until_first_complete,
)

asynccontextmanager_error_message = """

            

Reported by Pylint.

tests/test_custom_route_class.py
21 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest
from fastapi import APIRouter, FastAPI
from fastapi.routing import APIRoute
from fastapi.testclient import TestClient
from starlette.routing import Route

app = FastAPI()



            

Reported by Pylint.

Unable to import 'starlette.routing'
Error

Line: 5 Column: 1

              from fastapi import APIRouter, FastAPI
from fastapi.routing import APIRoute
from fastapi.testclient import TestClient
from starlette.routing import Route

app = FastAPI()


class APIRouteA(APIRoute):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest
from fastapi import APIRouter, FastAPI
from fastapi.routing import APIRoute
from fastapi.testclient import TestClient
from starlette.routing import Route

app = FastAPI()



            

Reported by Pylint.

Missing class docstring
Error

Line: 10 Column: 1

              app = FastAPI()


class APIRouteA(APIRoute):
    x_type = "A"


class APIRouteB(APIRoute):
    x_type = "B"

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 10 Column: 1

              app = FastAPI()


class APIRouteA(APIRoute):
    x_type = "A"


class APIRouteB(APIRoute):
    x_type = "B"

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 14 Column: 1

                  x_type = "A"


class APIRouteB(APIRoute):
    x_type = "B"


class APIRouteC(APIRoute):
    x_type = "C"

            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

                  x_type = "A"


class APIRouteB(APIRoute):
    x_type = "B"


class APIRouteC(APIRoute):
    x_type = "C"

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 18 Column: 1

                  x_type = "B"


class APIRouteC(APIRoute):
    x_type = "C"


router_a = APIRouter(route_class=APIRouteA)
router_b = APIRouter(route_class=APIRouteB)

            

Reported by Pylint.

Missing class docstring
Error

Line: 18 Column: 1

                  x_type = "B"


class APIRouteC(APIRoute):
    x_type = "C"


router_a = APIRouter(route_class=APIRouteA)
router_b = APIRouter(route_class=APIRouteB)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 28 Column: 1

              

@router_a.get("/")
def get_a():
    return {"msg": "A"}


@router_b.get("/")
def get_b():

            

Reported by Pylint.