Skip to content

Commit

Permalink
chore(typing): Ignore some pyright errors (#2946)
Browse files Browse the repository at this point in the history
Ignore some pyright errors

Signed-off-by: Janek Nouvertné <[email protected]>
  • Loading branch information
provinzkraut authored Jan 5, 2024
1 parent 9e99ca5 commit 2b89145
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 37 deletions.
2 changes: 1 addition & 1 deletion litestar/connection/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Request(Generic[UserT, AuthT, StateT], ASGIConnection["HTTPRouteHandler",
"supports_push_promise",
)

scope: HTTPScope
scope: HTTPScope # pyright: ignore
"""The ASGI scope attached to the connection."""
receive: Receive
"""The ASGI receive function."""
Expand Down
2 changes: 1 addition & 1 deletion litestar/connection/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WebSocket(Generic[UserT, AuthT, StateT], ASGIConnection["WebsocketRouteHan

__slots__ = ("connection_state",)

scope: WebSocketScope
scope: WebSocketScope # pyright: ignore
"""The ASGI scope attached to the connection."""
receive: Receive
"""The ASGI receive function."""
Expand Down
2 changes: 1 addition & 1 deletion litestar/contrib/mako.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def register_template_callable(
self._template_callables.append((key, template_callable))

@staticmethod
def render_string(template_string: str, context: Mapping[str, Any]) -> str:
def render_string(template_string: str, context: Mapping[str, Any]) -> str: # pyright: ignore
"""Render a template from a string with the given context.
Args:
Expand Down
2 changes: 1 addition & 1 deletion litestar/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def info(self, path: PathType, **kwargs: Any) -> FileInfo:
result = await Path(path).stat()
return await FileSystemAdapter.parse_stat_result(path=path, result=result)

async def open(self, file: PathType, mode: str, buffering: int = -1) -> AsyncFile[AnyStr]:
async def open(self, file: PathType, mode: str, buffering: int = -1) -> AsyncFile[AnyStr]: # pyright: ignore
"""Return a file-like object from the filesystem.
Notes:
Expand Down
2 changes: 1 addition & 1 deletion litestar/handlers/http_handlers/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def handler(
if after_request:
response = await after_request(response) # type: ignore[arg-type,misc]

return response.to_asgi_response(app=None, request=request, headers=normalize_headers(headers), cookies=cookies)
return response.to_asgi_response(app=None, request=request, headers=normalize_headers(headers), cookies=cookies) # pyright: ignore

return handler

Expand Down
4 changes: 2 additions & 2 deletions litestar/middleware/session/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
BaseSessionBackendT = TypeVar("BaseSessionBackendT", bound="BaseSessionBackend")


class BaseBackendConfig(ABC, Generic[BaseSessionBackendT]):
class BaseBackendConfig(ABC, Generic[BaseSessionBackendT]): # pyright: ignore
"""Configuration for Session middleware backends."""

_backend_class: type[BaseSessionBackendT]
_backend_class: type[BaseSessionBackendT] # pyright: ignore

key: str
"""Key to use for the cookie inside the header, e.g. ``session=<data>`` where ``session`` is the cookie key and
Expand Down
2 changes: 1 addition & 1 deletion litestar/middleware/session/client_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ async def load_from_connection(self, connection: ASGIConnection) -> dict[str, An


@dataclass
class CookieBackendConfig(BaseBackendConfig[ClientSideSessionBackend]):
class CookieBackendConfig(BaseBackendConfig[ClientSideSessionBackend]): # pyright: ignore
"""Configuration for [SessionMiddleware] middleware."""

_backend_class = ClientSideSessionBackend
Expand Down
2 changes: 1 addition & 1 deletion litestar/middleware/session/server_side.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def load_from_connection(self, connection: ASGIConnection) -> dict[str, An


@dataclass
class ServerSideSessionConfig(BaseBackendConfig[ServerSideSessionBackend]):
class ServerSideSessionConfig(BaseBackendConfig[ServerSideSessionBackend]): # pyright: ignore
"""Base configuration for server side backends."""

_backend_class = ServerSideSessionBackend
Expand Down
6 changes: 3 additions & 3 deletions litestar/security/jwt/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BaseJWTAuth(Generic[UserType], AbstractSecurityConfig[UserType, Token]):
"""The value to use for the OpenAPI security scheme and security requirements."""
description: str
"""Description for the OpenAPI security scheme."""
authentication_middleware_class: type[JWTAuthenticationMiddleware]
authentication_middleware_class: type[JWTAuthenticationMiddleware] # pyright: ignore
"""The authentication middleware class to use.
Must inherit from :class:`JWTAuthenticationMiddleware`
Expand Down Expand Up @@ -352,7 +352,7 @@ class and adds support for passing JWT tokens ``HttpOnly`` cookies.
"""Controls whether or not a cookie is sent with cross-site requests. Defaults to ``lax``. """
description: str = field(default="JWT cookie-based authentication and authorization.")
"""Description for the OpenAPI security scheme."""
authentication_middleware_class: type[JWTCookieAuthenticationMiddleware] = field(
authentication_middleware_class: type[JWTCookieAuthenticationMiddleware] = field( # pyright: ignore
default=JWTCookieAuthenticationMiddleware
)
"""The authentication middleware class to use. Must inherit from :class:`JWTCookieAuthenticationMiddleware`
Expand Down Expand Up @@ -556,7 +556,7 @@ class OAuth2PasswordBearerAuth(Generic[UserType], BaseJWTAuth[UserType]):
"""Controls whether or not a cookie is sent with cross-site requests. Defaults to ``lax``. """
description: str = field(default="OAUTH2 password bearer authentication and authorization.")
"""Description for the OpenAPI security scheme."""
authentication_middleware_class: type[JWTCookieAuthenticationMiddleware] = field(
authentication_middleware_class: type[JWTCookieAuthenticationMiddleware] = field( # pyright: ignore
default=JWTCookieAuthenticationMiddleware
)
"""The authentication middleware class to use.
Expand Down
6 changes: 3 additions & 3 deletions litestar/security/session_auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class SessionAuth(Generic[UserType, BaseSessionBackendT], AbstractSecurityConfig[UserType, Dict[str, Any]]):
"""Session Based Security Backend."""

session_backend_config: BaseBackendConfig[BaseSessionBackendT]
session_backend_config: BaseBackendConfig[BaseSessionBackendT] # pyright: ignore
"""A session backend config."""
retrieve_user_handler: Callable[[Any, ASGIConnection], SyncOrAsyncUnion[Any | None]]
"""Callable that receives the ``auth`` value from the authentication middleware and returns a ``user`` value.
Expand All @@ -34,7 +34,7 @@ class SessionAuth(Generic[UserType, BaseSessionBackendT], AbstractSecurityConfig
"""

authentication_middleware_class: type[SessionAuthMiddleware] = field(default=SessionAuthMiddleware)
authentication_middleware_class: type[SessionAuthMiddleware] = field(default=SessionAuthMiddleware) # pyright: ignore
"""The authentication middleware class to use.
Must inherit from :class:`SessionAuthMiddleware <litestar.security.session_auth.middleware.SessionAuthMiddleware>`
Expand Down Expand Up @@ -105,7 +105,7 @@ def session_backend(self) -> BaseSessionBackendT:
Returns:
A subclass of :class:`BaseSessionBackend <litestar.middleware.session.base.BaseSessionBackend>`
"""
return self.session_backend_config._backend_class(config=self.session_backend_config)
return self.session_backend_config._backend_class(config=self.session_backend_config) # pyright: ignore

@property
def openapi_components(self) -> Components:
Expand Down
30 changes: 12 additions & 18 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ linting = [
"mypy",
"pre-commit",
"slotscheck",
"pyright",
"pyright==1.1.344",
"blacken-docs",
"asyncpg-stubs",
"types-beautifulsoup4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@pytest.fixture
def listener_class(mock: MagicMock) -> Type[WebsocketListener]:
class Listener(WebsocketListener):
def on_receive(self, data: str) -> str:
def on_receive(self, data: str) -> str: # pyright: ignore
mock(data)
return data

Expand Down Expand Up @@ -403,7 +403,7 @@ def on_accept(self, name: str, state: State, query: dict, some: str) -> None: #
def on_disconnect(self, name: str, state: State, query: dict, some: str) -> None: # type: ignore[override]
on_disconnect_mock(name=name, state=state, query=query, some=some)

def on_receive(self, data: bytes) -> None:
def on_receive(self, data: bytes) -> None: # pyright: ignore
pass

with create_test_client([Listener], dependencies={"some": some_dependency}) as client, client.websocket_connect(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_openapi/test_security_schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_schema_with_route_security_overridden(protected_route: "HTTPRouteHandle
def test_layered_security_declaration() -> None:
class MyController(Controller):
path = "/controller"
security: List[SecurityRequirement] = [{"controllerToken": []}]
security: List[SecurityRequirement] = [{"controllerToken": []}] # pyright: ignore

@get("", security=[{"handlerToken": []}])
def my_handler(self) -> None:
Expand Down

0 comments on commit 2b89145

Please sign in to comment.