From c8ecf86e28ecad39096b457c7ee4b439a0b35e6f Mon Sep 17 00:00:00 2001 From: Juan-Pablo Scaletti Date: Mon, 22 Apr 2024 07:55:12 -0500 Subject: [PATCH] Add extra quotes so PEP604-style type hinting works with py3.9 --- pyproject.toml | 4 ++-- src/jinjax/catalog.py | 22 +++++++++++----------- src/jinjax/component.py | 8 ++++---- src/jinjax/html_attrs.py | 2 +- src/jinjax/middleware.py | 2 +- tests/test_middleware.py | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fdcf831..32ddd06 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "jinjax" -version = "0.32" +version = "0.33" description = "Replace your HTML templates with Python server-Side components" authors = ["Juan-Pablo Scaletti "] license = "MIT" @@ -92,7 +92,7 @@ addopts = "--doctest-modules" legacy_tox_ini = """ [tox] skipsdist = True -envlist = py310,py311,py312,pypy3.10 +envlist = py3.9,py310,py311,py312,pypy3.10 [testenv] skip_install = true diff --git a/src/jinjax/catalog.py b/src/jinjax/catalog.py index 1cbffab..1efad86 100644 --- a/src/jinjax/catalog.py +++ b/src/jinjax/catalog.py @@ -14,7 +14,7 @@ from .utils import logger -TFileExt = tuple[str, ...] | str +TFileExt = t.Union[tuple[str, ...], str] DEFAULT_URL_ROOT = "/static/components/" ALLOWED_EXTENSIONS = (".css", ".js", ".mjs") @@ -73,11 +73,11 @@ class Catalog: def __init__( self, *, - globals: dict[str, t.Any] | None = None, - filters: dict[str, t.Any] | None = None, - tests: dict[str, t.Any] | None = None, - extensions: list | None = None, - jinja_env: jinja2.Environment | None = None, + globals: "dict[str, t.Any] | None" = None, + filters: "dict[str, t.Any] | None" = None, + tests: "dict[str, t.Any] | None" = None, + extensions: "list | None" = None, + jinja_env: "jinja2.Environment | None" = None, root_url: str = DEFAULT_URL_ROOT, file_ext: TFileExt = DEFAULT_EXTENSION, use_cache: bool = True, @@ -122,7 +122,7 @@ def __init__( self.jinja_env = env - self.tmpl_globals: t.MutableMapping[str, t.Any] | None = None + self.tmpl_globals: "t.MutableMapping[str, t.Any] | None" = None self._cache: dict[str, dict] = {} @property @@ -134,7 +134,7 @@ def paths(self) -> list[Path]: def add_folder( self, - root_path: str | Path, + root_path: "str | Path", *, prefix: str = DEFAULT_PREFIX, ) -> None: @@ -164,7 +164,7 @@ def render( self, __name: str, *, - caller: t.Callable | None = None, + caller: "t.Callable | None" = None, **kw, ) -> str: self.collected_css = [] @@ -176,7 +176,7 @@ def irender( self, __name: str, *, - caller: t.Callable | None = None, + caller: "t.Callable | None" = None, **kw, ) -> str: content = (kw.pop("__content", "") or "").strip() @@ -253,7 +253,7 @@ def irender( def get_middleware( self, application: t.Callable, - allowed_ext: t.Iterable[str] | None = ALLOWED_EXTENSIONS, + allowed_ext: "t.Iterable[str] | None" = ALLOWED_EXTENSIONS, **kwargs, ) -> ComponentsMiddleware: logger.debug("Creating middleware") diff --git a/src/jinjax/component.py b/src/jinjax/component.py index b0b3427..f5d9cb2 100644 --- a/src/jinjax/component.py +++ b/src/jinjax/component.py @@ -67,8 +67,8 @@ def __init__( url_prefix: str = "", source: str = "", mtime: float = 0, - tmpl: Template | None = None, - path: Path | None = None, + tmpl: "Template | None" = None, + path: "Path | None" = None, ) -> None: self.name = name self.url_prefix = url_prefix @@ -92,7 +92,7 @@ def from_cache( cls, cache: dict[str, t.Any], auto_reload: bool = True, - globals: t.MutableMapping[str, t.Any] | None = None, + globals: "t.MutableMapping[str, t.Any] | None" = None, ) -> "Self | None": path = cache["path"] mtime = cache["mtime"] @@ -177,7 +177,7 @@ def parse_args_expr(self, expr: str) -> tuple[list[str], dict[str, t.Any]]: args = p.body[0].args # type: ignore arg_names = [arg.arg for arg in args.kwonlyargs] - for name, value in zip(arg_names, args.kw_defaults, strict=True): + for name, value in zip(arg_names, args.kw_defaults): # noqa: B905 if value is None: required.append(name) continue diff --git a/src/jinjax/html_attrs.py b/src/jinjax/html_attrs.py index 2b92597..2f9937b 100644 --- a/src/jinjax/html_attrs.py +++ b/src/jinjax/html_attrs.py @@ -40,7 +40,7 @@ def data(self): # type: ignore class HTMLAttrs: def __init__(self, attrs) -> None: - attributes: dict[str, str|LazyString] = {} + attributes: "dict[str, str | LazyString]" = {} properties: set[str] = set() class_names = split(" ".join([ diff --git a/src/jinjax/middleware.py b/src/jinjax/middleware.py index e4fe8fb..7c8acd8 100644 --- a/src/jinjax/middleware.py +++ b/src/jinjax/middleware.py @@ -17,7 +17,7 @@ def __init__(self, **kwargs) -> None: self.allowed_ext = kwargs.pop("allowed_ext", ()) super().__init__(**kwargs) - def find_file(self, url: str) -> StaticFile|Redirect|None: + def find_file(self, url: str) -> "StaticFile | Redirect | None": if self.allowed_ext and not url.endswith(self.allowed_ext): return None diff --git a/tests/test_middleware.py b/tests/test_middleware.py index 3616693..b1fa9a9 100644 --- a/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -21,7 +21,7 @@ def mock_start_response(status: str, headers: dict[str, t.Any]): pass -def get_catalog(folder: str | Path, **kw) -> jinjax.Catalog: +def get_catalog(folder: "str | Path", **kw) -> jinjax.Catalog: catalog = jinjax.Catalog(**kw) catalog.add_folder(folder) return catalog