The following issues were found
tests/test_tutorial/test_request_forms_and_files/test_tutorial001.py
21 issues
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
Line: 10
Column: 1
app = FastAPI()
class APIRouteA(APIRoute):
x_type = "A"
class APIRouteB(APIRoute):
x_type = "B"
Reported by Pylint.
Line: 10
Column: 1
app = FastAPI()
class APIRouteA(APIRoute):
x_type = "A"
class APIRouteB(APIRoute):
x_type = "B"
Reported by Pylint.
Line: 14
Column: 1
x_type = "A"
class APIRouteB(APIRoute):
x_type = "B"
class APIRouteC(APIRoute):
x_type = "C"
Reported by Pylint.
Line: 14
Column: 1
x_type = "A"
class APIRouteB(APIRoute):
x_type = "B"
class APIRouteC(APIRoute):
x_type = "C"
Reported by Pylint.
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.
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.
Line: 28
Column: 1
@router_a.get("/")
def get_a():
return {"msg": "A"}
@router_b.get("/")
def get_b():
Reported by Pylint.