From 2b8914525ee1e789621959a2475ab53251b1ec0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janek=20Nouvertn=C3=A9?= Date: Fri, 5 Jan 2024 15:50:38 +0100 Subject: [PATCH] chore(typing): Ignore some pyright errors (#2946) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore some pyright errors Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com> --- litestar/connection/request.py | 2 +- litestar/connection/websocket.py | 2 +- litestar/contrib/mako.py | 2 +- litestar/file_system.py | 2 +- litestar/handlers/http_handlers/_utils.py | 2 +- litestar/middleware/session/base.py | 4 +-- litestar/middleware/session/client_side.py | 2 +- litestar/middleware/session/server_side.py | 2 +- litestar/security/jwt/auth.py | 6 ++-- litestar/security/session_auth/auth.py | 6 ++-- pdm.lock | 30 ++++++++----------- pyproject.toml | 2 +- .../test_websocket_handlers/test_listeners.py | 4 +-- .../test_openapi/test_security_schemes.py | 2 +- 14 files changed, 31 insertions(+), 37 deletions(-) diff --git a/litestar/connection/request.py b/litestar/connection/request.py index 8006d8a43d..254c31561f 100644 --- a/litestar/connection/request.py +++ b/litestar/connection/request.py @@ -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.""" diff --git a/litestar/connection/websocket.py b/litestar/connection/websocket.py index 3935c4b675..c61a817a0f 100644 --- a/litestar/connection/websocket.py +++ b/litestar/connection/websocket.py @@ -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.""" diff --git a/litestar/contrib/mako.py b/litestar/contrib/mako.py index eb6cd28bbe..b875a1c2fd 100644 --- a/litestar/contrib/mako.py +++ b/litestar/contrib/mako.py @@ -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: diff --git a/litestar/file_system.py b/litestar/file_system.py index 1dc8c44458..b86bf2cdd8 100644 --- a/litestar/file_system.py +++ b/litestar/file_system.py @@ -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: diff --git a/litestar/handlers/http_handlers/_utils.py b/litestar/handlers/http_handlers/_utils.py index 92fe78d40f..e840383cba 100644 --- a/litestar/handlers/http_handlers/_utils.py +++ b/litestar/handlers/http_handlers/_utils.py @@ -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 diff --git a/litestar/middleware/session/base.py b/litestar/middleware/session/base.py index 91e3c30b5f..b7e2e1586a 100644 --- a/litestar/middleware/session/base.py +++ b/litestar/middleware/session/base.py @@ -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=`` where ``session`` is the cookie key and diff --git a/litestar/middleware/session/client_side.py b/litestar/middleware/session/client_side.py index a4b65ac9b0..f8f230edb0 100644 --- a/litestar/middleware/session/client_side.py +++ b/litestar/middleware/session/client_side.py @@ -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 diff --git a/litestar/middleware/session/server_side.py b/litestar/middleware/session/server_side.py index e19934c379..cec0011d80 100644 --- a/litestar/middleware/session/server_side.py +++ b/litestar/middleware/session/server_side.py @@ -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 diff --git a/litestar/security/jwt/auth.py b/litestar/security/jwt/auth.py index a23ec92347..c819ed0b61 100644 --- a/litestar/security/jwt/auth.py +++ b/litestar/security/jwt/auth.py @@ -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` @@ -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` @@ -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. diff --git a/litestar/security/session_auth/auth.py b/litestar/security/session_auth/auth.py index f62dc00540..3bdf78a9ba 100644 --- a/litestar/security/session_auth/auth.py +++ b/litestar/security/session_auth/auth.py @@ -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. @@ -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 ` @@ -105,7 +105,7 @@ def session_backend(self) -> BaseSessionBackendT: Returns: A subclass of :class:`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: diff --git a/pdm.lock b/pdm.lock index 036a51bae2..6c5979aba8 100644 --- a/pdm.lock +++ b/pdm.lock @@ -4,8 +4,8 @@ [metadata] groups = ["default", "standard", "jwt", "pydantic", "cli", "picologging", "dev-contrib", "piccolo", "prometheus", "dev", "mako", "test", "brotli", "cryptography", "linting", "attrs", "opentelemetry", "docs", "redis", "sqlalchemy", "full", "annotated-types", "jinja", "structlog", "minijinja"] strategy = ["cross_platform"] -lock_version = "4.4" -content_hash = "sha256:621796e9ccd87bf1be1aa40fd5e3ec170a89be761aae62fed47879256848d88f" +lock_version = "4.4.1" +content_hash = "sha256:8d1f58bfc4ff70c92de422ef99f3c005e9360a00147adf245ce9c5578cec162d" [[package]] name = "accessible-pygments" @@ -237,6 +237,10 @@ summary = "Automatically generate code examples for different Python versions in dependencies = [ "ruff>=0.0.260", ] +files = [ + {file = "auto_pytabs-0.4.0-py3-none-any.whl", hash = "sha256:941ca4f21b218249ee4d026ebaf4a8a7788a066fdb223571f1f7b93d44ac6a74"}, + {file = "auto_pytabs-0.4.0.tar.gz", hash = "sha256:4c596aa02ea20c6c85809e5f60a22aa60499dcaa637e52d6313d07c58c5bb61e"}, +] [[package]] name = "auto-pytabs" @@ -1405,7 +1409,7 @@ files = [ [[package]] name = "litestar-sphinx-theme" version = "0.2.0" -requires_python = ">=3.8,<4.0" +requires_python = "<4.0,>=3.8" git = "https://github.com/litestar-org/litestar-sphinx-theme.git" revision = "c5ce66aadc8f910c24f54bf0d172798c237a67eb" summary = "A Sphinx theme for the Litestar organization" @@ -2314,15 +2318,15 @@ files = [ [[package]] name = "pyright" -version = "1.1.338" +version = "1.1.344" requires_python = ">=3.7" summary = "Command line wrapper for pyright" dependencies = [ "nodeenv>=1.6.0", ] files = [ - {file = "pyright-1.1.338-py3-none-any.whl", hash = "sha256:28231a3c81ec738b3e1b02489eea5b67fb425a9be0717a32b2e075984623b3ff"}, - {file = "pyright-1.1.338.tar.gz", hash = "sha256:132aa74d2d58d4d27a5b922672b5b4d2be7f3931e7276a2b231d15af6e45daad"}, + {file = "pyright-1.1.344-py3-none-any.whl", hash = "sha256:ab7117a911ce25fcd317f42272579f9ae53a6abc8b8a15f6aa069a11281953ee"}, + {file = "pyright-1.1.344.tar.gz", hash = "sha256:ab7c962f00dd8141a5a0192c1060fb34b92d1f9047ad70dda45229938051922b"}, ] [[package]] @@ -2775,16 +2779,6 @@ files = [ {file = "soupsieve-2.5.tar.gz", hash = "sha256:5663d5a7b3bfaeee0bc4372e7fc48f9cff4940b3eec54a6451cc5299f1097690"}, ] -[[package]] -name = "sourcery" -version = "1.14.0" -summary = "Magically refactor Python" -files = [ - {file = "sourcery-1.14.0-py2.py3-none-macosx_10_9_universal2.whl", hash = "sha256:208dbf69e0c3b145bbb18a3f7d082a849cc61ac7b51df323291ccddc92025433"}, - {file = "sourcery-1.14.0-py2.py3-none-manylinux1_x86_64.whl", hash = "sha256:12a79c93f8f7baddde77678d7a69b81cdea51e4ceafa8d6be5caf21b66eb71f8"}, - {file = "sourcery-1.14.0-py2.py3-none-win_amd64.whl", hash = "sha256:15b056baae7440319e3866ff0e524484d4899665c0669c7b20044e4d7869204a"}, -] - [[package]] name = "sphinx" version = "7.1.2" @@ -3029,7 +3023,7 @@ version = "2.0.23" requires_python = ">=3.7" summary = "Database Abstraction Library" dependencies = [ - "greenlet!=0.4.17; platform_machine == \"aarch64\" or (platform_machine == \"ppc64le\" or (platform_machine == \"x86_64\" or (platform_machine == \"amd64\" or (platform_machine == \"AMD64\" or (platform_machine == \"win32\" or platform_machine == \"WIN32\")))))", + "greenlet!=0.4.17; platform_machine == \"win32\" or platform_machine == \"WIN32\" or platform_machine == \"AMD64\" or platform_machine == \"amd64\" or platform_machine == \"x86_64\" or platform_machine == \"ppc64le\" or platform_machine == \"aarch64\"", "typing-extensions>=4.2.0", ] files = [ @@ -3386,7 +3380,7 @@ dependencies = [ "python-dotenv>=0.13", "pyyaml>=5.1", "uvicorn==0.24.0.post1", - "uvloop!=0.15.0,!=0.15.1,>=0.14.0; sys_platform != \"win32\" and (sys_platform != \"cygwin\" and platform_python_implementation != \"PyPy\")", + "uvloop!=0.15.0,!=0.15.1,>=0.14.0; (sys_platform != \"cygwin\" and sys_platform != \"win32\") and platform_python_implementation != \"PyPy\"", "watchfiles>=0.13", "websockets>=10.4", ] diff --git a/pyproject.toml b/pyproject.toml index 02d9cd1aa6..1421cafefe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -126,7 +126,7 @@ linting = [ "mypy", "pre-commit", "slotscheck", - "pyright", + "pyright==1.1.344", "blacken-docs", "asyncpg-stubs", "types-beautifulsoup4", diff --git a/tests/unit/test_handlers/test_websocket_handlers/test_listeners.py b/tests/unit/test_handlers/test_websocket_handlers/test_listeners.py index 461864b17b..4d25a7b82a 100644 --- a/tests/unit/test_handlers/test_websocket_handlers/test_listeners.py +++ b/tests/unit/test_handlers/test_websocket_handlers/test_listeners.py @@ -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 @@ -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( diff --git a/tests/unit/test_openapi/test_security_schemes.py b/tests/unit/test_openapi/test_security_schemes.py index 60fd39d6f4..6bdf62db57 100644 --- a/tests/unit/test_openapi/test_security_schemes.py +++ b/tests/unit/test_openapi/test_security_schemes.py @@ -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: