diff --git a/pyproject.toml b/pyproject.toml index 867f923f..1102ea66 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,7 +90,7 @@ dev-dependencies = [ "junit2html >= 30.1,< 32.0", # Pyright >= 1.1.367 breaks the build. # Waiting for new pyright release to fix it. https://github.com/uclahs-cds/BL_Python/issues/79 - "pyright == 1.1.370", + "pyright == 1.1.374", "isort ~= 5.13", "ruff ~= 0.3", "bandit[sarif,toml] ~= 1.7" diff --git a/src/AWS/BL_Python/AWS/ssm.py b/src/AWS/BL_Python/AWS/ssm.py index 13c5438c..900e7ceb 100644 --- a/src/AWS/BL_Python/AWS/ssm.py +++ b/src/AWS/BL_Python/AWS/ssm.py @@ -124,7 +124,11 @@ def load_ssm_application_parameters( def load_config(self, config_type: type[TConfig]) -> TConfig | None: config: TConfig | None = None try: - ssm_parameters: AnyDict | None = self.load_ssm_application_parameters() + ssm_parameters = self.load_ssm_application_parameters() + + if ssm_parameters is None: + raise Exception("SSM parameters were not loaded.") + config = config_type(**ssm_parameters) except: if not self._continue_on_ssm_failure: diff --git a/src/database/BL_Python/database/migrations/alembic/bl_alembic.py b/src/database/BL_Python/database/migrations/alembic/bl_alembic.py index 4b3878eb..7bb7ffba 100644 --- a/src/database/BL_Python/database/migrations/alembic/bl_alembic.py +++ b/src/database/BL_Python/database/migrations/alembic/bl_alembic.py @@ -2,7 +2,7 @@ from logging import Logger from pathlib import Path from types import TracebackType -from typing import Callable +from typing import BinaryIO, Callable, cast import alembic.util.messaging @@ -228,7 +228,7 @@ def _copy_files(self, files: list[FileCopy], force_overwrite: bool = False): open(file.source, "r") as source, open(file.destination, write_mode) as destination, ): - destination.writelines(source.buffer) + destination.writelines(cast(BinaryIO, source.buffer)) # pyright: ignore[reportUnnecessaryCast] Disagreement between pyright and pylance. Pyright things this is a different type, and pylance doesn't like the cast. except FileExistsError as e: if e.filename != str(file.destination): raise diff --git a/src/web/BL_Python/web/middleware/__init__.py b/src/web/BL_Python/web/middleware/__init__.py index 09cde079..828c151f 100644 --- a/src/web/BL_Python/web/middleware/__init__.py +++ b/src/web/BL_Python/web/middleware/__init__.py @@ -1,6 +1,6 @@ import json from logging import Logger -from typing import Awaitable, Callable, TypeVar +from typing import Awaitable, Callable, TypeAlias, TypeVar from BL_Python.web.middleware.flask import ( register_flask_api_request_handlers, @@ -13,11 +13,7 @@ ) from connexion import FlaskApp from flask import Flask, Response -from flask.typing import ( - AfterRequestCallable, - BeforeRequestCallable, - ResponseReturnValue, -) +from flask.typing import ResponseReturnValue from werkzeug.exceptions import HTTPException, Unauthorized # pyright: reportUnusedFunction=false @@ -26,8 +22,10 @@ # Fixes type problems when using @inject with @app.before_request and @app.after_request. # The main difference with these types as opposed to the Flask-defined types is that # these types allow the handler to take any arguments, versus no arguments or just Response. -AfterRequestCallable = Callable[..., Response] | Callable[..., Awaitable[Response]] -BeforeRequestCallable = ( +AfterRequestCallable: TypeAlias = ( + Callable[..., Response] | Callable[..., Awaitable[Response]] +) +BeforeRequestCallable: TypeAlias = ( Callable[..., ResponseReturnValue | None] | Callable[..., Awaitable[ResponseReturnValue | None]] ) diff --git a/src/web/BL_Python/web/middleware/flask/__init__.py b/src/web/BL_Python/web/middleware/flask/__init__.py index d0ba38bd..515ee2af 100644 --- a/src/web/BL_Python/web/middleware/flask/__init__.py +++ b/src/web/BL_Python/web/middleware/flask/__init__.py @@ -1,17 +1,13 @@ import re import uuid from logging import Logger -from typing import Awaitable, Callable, Dict, TypeVar +from typing import Awaitable, Callable, Dict, TypeAlias, TypeVar from uuid import uuid4 import json_logging from connexion import FlaskApp from flask import Flask, Request, Response, request -from flask.typing import ( - AfterRequestCallable, - BeforeRequestCallable, - ResponseReturnValue, -) +from flask.typing import ResponseReturnValue from injector import inject from ...config import Config @@ -35,8 +31,10 @@ # Fixes type problems when using @inject with @app.before_request and @app.after_request. # The main difference with these types as opposed to the Flask-defined types is that # these types allow the handler to take any arguments, versus no arguments or just Response. -AfterRequestCallable = Callable[..., Response] | Callable[..., Awaitable[Response]] -BeforeRequestCallable = ( +AfterRequestCallable: TypeAlias = ( + Callable[..., Response] | Callable[..., Awaitable[Response]] +) +BeforeRequestCallable: TypeAlias = ( Callable[..., ResponseReturnValue | None] | Callable[..., Awaitable[ResponseReturnValue | None]] ) diff --git a/src/web/BL_Python/web/middleware/openapi/__init__.py b/src/web/BL_Python/web/middleware/openapi/__init__.py index c4b8d6b7..c790ef9d 100644 --- a/src/web/BL_Python/web/middleware/openapi/__init__.py +++ b/src/web/BL_Python/web/middleware/openapi/__init__.py @@ -4,7 +4,7 @@ from contextlib import ExitStack from contextvars import Token from logging import Logger -from typing import Any, Awaitable, Callable, Literal, TypeVar, cast +from typing import Any, Awaitable, Callable, Literal, TypeAlias, TypeVar, cast from uuid import uuid4 import json_logging @@ -18,11 +18,7 @@ from flask.ctx import AppContext from flask.globals import _cv_app # pyright: ignore[reportPrivateUsage] from flask.globals import current_app -from flask.typing import ( - AfterRequestCallable, - BeforeRequestCallable, - ResponseReturnValue, -) +from flask.typing import ResponseReturnValue from flask_login import AnonymousUserMixin, current_user from injector import inject from starlette.datastructures import Address @@ -46,8 +42,10 @@ # Fixes type problems when using @inject with @app.before_request and @app.after_request. # The main difference with these types as opposed to the Flask-defined types is that # these types allow the handler to take any arguments, versus no arguments or just Response. -AfterRequestCallable = Callable[..., Response] | Callable[..., Awaitable[Response]] -BeforeRequestCallable = ( +AfterRequestCallable: TypeAlias = ( + Callable[..., Response] | Callable[..., Awaitable[Response]] +) +BeforeRequestCallable: TypeAlias = ( Callable[..., ResponseReturnValue | None] | Callable[..., Awaitable[ResponseReturnValue | None]] ) diff --git a/src/web/BL_Python/web/scaffolding/scaffolder.py b/src/web/BL_Python/web/scaffolding/scaffolder.py index 0afab516..0cbaaf50 100644 --- a/src/web/BL_Python/web/scaffolding/scaffolder.py +++ b/src/web/BL_Python/web/scaffolding/scaffolder.py @@ -196,9 +196,7 @@ def _render_template( template = template_environment.get_template(template_name) if write_rendered_template: - template.stream( # pyright: ignore[reportUnknownMemberType] - **template_config - ).dump(str(template_output_path)) + template.stream(**template_config).dump(str(template_output_path)) else: template_stream = template.stream(**template_config) while next(template_stream, None): @@ -252,14 +250,12 @@ def _execute_module_hooks(self, module_template_directory: str): `on_create(config: dict[str, Any], log: Logger) -> None` """ module_hook_path = Path(module_template_directory, "__hook__.py") - if self._provider.has_resource( # pyright: ignore[reportUnknownMemberType] - str(module_hook_path) - ): + if self._provider.has_resource(str(module_hook_path)): # load the module from its path # and execute it spec = spec_from_file_location( "__hook__", - self._provider.get_resource_filename( # pyright: ignore[reportUnknownArgumentType,reportUnknownMemberType] + self._provider.get_resource_filename( self._manager, str(module_hook_path) ), ) @@ -338,7 +334,7 @@ def _scaffold_modules(self, overwrite_existing_files: bool = True): # all modules contain templates under templates/ # but only modules with __meta__.j2 control how # their own templates are rendered. - if self._provider.has_resource( # pyright: ignore[reportUnknownMemberType] + if self._provider.has_resource( str(Path(module_template_directory, "__meta__.j2")) ): module_env = Environment(