Skip to content

Commit

Permalink
Add extra quotes so PEP604-style type hinting works with py3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsca committed Apr 22, 2024
1 parent 7ec71c5 commit c8ecf86
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/jinjax/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -164,7 +164,7 @@ def render(
self,
__name: str,
*,
caller: t.Callable | None = None,
caller: "t.Callable | None" = None,
**kw,
) -> str:
self.collected_css = []
Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions src/jinjax/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/jinjax/html_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion src/jinjax/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8ecf86

Please sign in to comment.