Skip to content

Commit

Permalink
Merge pull request #92 from uclahs-cds/dependabot/pip/pyright-1.1.374
Browse files Browse the repository at this point in the history
Bump pyright from 1.1.370 to 1.1.374
  • Loading branch information
aholmes authored Aug 6, 2024
2 parents 6de89f1 + 6f3675b commit cfd0c1a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion src/AWS/BL_Python/AWS/ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions src/web/BL_Python/web/middleware/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand All @@ -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]]
)
Expand Down
14 changes: 6 additions & 8 deletions src/web/BL_Python/web/middleware/flask/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]]
)
Expand Down
14 changes: 6 additions & 8 deletions src/web/BL_Python/web/middleware/openapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]]
)
Expand Down
12 changes: 4 additions & 8 deletions src/web/BL_Python/web/scaffolding/scaffolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
),
)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit cfd0c1a

Please sign in to comment.