Browse Source

ignore unused ignore's

pull/15091/head
svlandeg 4 months ago
parent
commit
b0c717b797
  1. 4
      fastapi/_compat/v2.py
  2. 2
      fastapi/applications.py
  3. 2
      fastapi/cli.py
  4. 6
      fastapi/dependencies/utils.py
  5. 4
      fastapi/encoders.py
  6. 2
      fastapi/openapi/models.py
  7. 2
      fastapi/openapi/utils.py
  8. 12
      fastapi/params.py
  9. 4
      fastapi/routing.py

4
fastapi/_compat/v2.py

@ -22,7 +22,7 @@ from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, create_model
from pydantic import PydanticSchemaGenerationError as PydanticSchemaGenerationError
from pydantic import PydanticUndefinedAnnotation as PydanticUndefinedAnnotation
from pydantic import ValidationError as ValidationError
from pydantic._internal._schema_generation_shared import ( # type: ignore[attr-defined]
from pydantic._internal._schema_generation_shared import ( # type: ignore[attr-defined] # ty: ignore[unused-ignore-comment]
GetJsonSchemaHandler as GetJsonSchemaHandler,
)
from pydantic._internal._typing_extra import eval_type_lenient # ty: ignore[deprecated]
@ -438,7 +438,7 @@ def get_flat_models_from_annotation(
for arg in get_args(annotation):
if lenient_issubclass(arg, (BaseModel, Enum)):
if arg not in known_models:
known_models.add(arg) # type: ignore[arg-type]
known_models.add(arg) # type: ignore[arg-type] # ty: ignore[unused-ignore-comment]
if lenient_issubclass(arg, BaseModel):
get_flat_models_from_model(arg, known_models=known_models)
else:

2
fastapi/applications.py

@ -1009,7 +1009,7 @@ class FastAPI(Starlette):
self.exception_handlers.setdefault(
WebSocketRequestValidationError,
# Starlette still has incorrect type specification for the handlers
websocket_request_validation_exception_handler, # type: ignore
websocket_request_validation_exception_handler, # type: ignore # ty: ignore[unused-ignore-comment]
)
self.user_middleware: list[Middleware] = (

2
fastapi/cli.py

@ -6,7 +6,7 @@ except ImportError: # pragma: no cover
def main() -> None:
if not cli_main: # type: ignore[truthy-function]
if not cli_main: # type: ignore[truthy-function] # ty: ignore[unused-ignore-comment]
message = 'To use the fastapi command, please install "fastapi[standard]":\n\n\tpip install "fastapi[standard]"\n'
print(message)
raise RuntimeError(message) # noqa: B904

6
fastapi/dependencies/utils.py

@ -100,12 +100,12 @@ def ensure_multipart_is_installed() -> None:
except (ImportError, AssertionError):
try:
# __version__ is available in both multiparts, and can be mocked
from multipart import __version__ # type: ignore[no-redef,import-untyped]
from multipart import __version__ # type: ignore[no-redef,import-untyped] # ty: ignore[unused-ignore-comment]
assert __version__
try:
# parse_options_header is only available in the right multipart
from multipart.multipart import ( # type: ignore[import-untyped]
from multipart.multipart import ( # type: ignore[import-untyped] # ty: ignore[unused-ignore-comment]
parse_options_header,
)
@ -619,7 +619,7 @@ async def solve_dependencies(
if response is None:
response = Response()
del response.headers["content-length"]
response.status_code = None # type: ignore
response.status_code = None # type: ignore # ty: ignore[unused-ignore-comment]
if dependency_cache is None:
dependency_cache = {}
for sub_dependant in dependant.dependencies:

4
fastapi/encoders.py

@ -220,9 +220,9 @@ def jsonable_encoder(
if isinstance(obj, encoder_type):
return encoder_instance(obj)
if include is not None and not isinstance(include, (set, dict)):
include = set(include) # type: ignore[assignment]
include = set(include) # type: ignore[assignment] # ty: ignore[unused-ignore-comment]
if exclude is not None and not isinstance(exclude, (set, dict)):
exclude = set(exclude) # type: ignore[assignment]
exclude = set(exclude) # type: ignore[assignment] # ty: ignore[unused-ignore-comment]
if isinstance(obj, BaseModel):
obj_dict = obj.model_dump(
mode="json",

2
fastapi/openapi/models.py

@ -20,7 +20,7 @@ try:
from pydantic import EmailStr
except ImportError: # pragma: no cover
class EmailStr(str): # type: ignore
class EmailStr(str): # type: ignore # ty: ignore[unused-ignore-comment]
@classmethod
def __get_validators__(cls) -> Iterable[Callable[..., Any]]:
yield cls.validate

2
fastapi/openapi/utils.py

@ -606,4 +606,4 @@ def get_openapi(
output["tags"] = tags
if external_docs:
output["externalDocs"] = external_docs
return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True) # type: ignore
return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True) # type: ignore # ty: ignore[unused-ignore-comment]

12
fastapi/params.py

@ -135,7 +135,7 @@ class Param(FieldInfo): # type: ignore[misc]
return f"{self.__class__.__name__}({self.default})"
class Path(Param): # type: ignore[misc]
class Path(Param): # type: ignore[misc] # ty: ignore[unused-ignore-comment]
in_ = ParamTypes.path
def __init__(
@ -219,7 +219,7 @@ class Path(Param): # type: ignore[misc]
)
class Query(Param): # type: ignore[misc]
class Query(Param): # type: ignore[misc] # ty: ignore[unused-ignore-comment]
in_ = ParamTypes.query
def __init__(
@ -301,7 +301,7 @@ class Query(Param): # type: ignore[misc]
)
class Header(Param): # type: ignore[misc]
class Header(Param): # type: ignore[misc] # ty: ignore[unused-ignore-comment]
in_ = ParamTypes.header
def __init__(
@ -385,7 +385,7 @@ class Header(Param): # type: ignore[misc]
)
class Cookie(Param): # type: ignore[misc]
class Cookie(Param): # type: ignore[misc] # ty: ignore[unused-ignore-comment]
in_ = ParamTypes.cookie
def __init__(
@ -579,7 +579,7 @@ class Body(FieldInfo): # type: ignore[misc]
return f"{self.__class__.__name__}({self.default})"
class Form(Body): # type: ignore[misc]
class Form(Body): # type: ignore[misc] # ty: ignore[unused-ignore-comment]
def __init__(
self,
default: Any = Undefined,
@ -661,7 +661,7 @@ class Form(Body): # type: ignore[misc]
)
class File(Form): # type: ignore[misc]
class File(Form): # type: ignore[misc] # ty: ignore[unused-ignore-comment]
def __init__(
self,
default: Any = Undefined,

4
fastapi/routing.py

@ -100,7 +100,7 @@ def request_response(
and returns an ASGI application.
"""
f: Callable[[Request], Awaitable[Response]] = (
func if is_async_callable(func) else functools.partial(run_in_threadpool, func) # type:ignore
func if is_async_callable(func) else functools.partial(run_in_threadpool, func) # type:ignore # ty: ignore[unused-ignore-comment]
)
async def app(scope: Scope, receive: Receive, send: Send) -> None:
@ -908,7 +908,7 @@ class APIRoute(routing.Route):
mode="serialization",
)
else:
self.response_field = None # type: ignore
self.response_field = None # type: ignore # ty: ignore[unused-ignore-comment]
if self.stream_item_type:
stream_item_name = "StreamItem_" + self.unique_id
self.stream_item_field: ModelField | None = create_model_field(

Loading…
Cancel
Save