Skip to content

Commit 1994980

Browse files
committed
fix type and lint warnings
1 parent 94fd2d4 commit 1994980

4 files changed

Lines changed: 19 additions & 23 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ deploy_develop = ["cd docs && mike deploy --push develop"]
198198
################################
199199

200200
[tool.hatch.envs.python]
201-
extra-dependencies = ["django-stubs", "channels-redis", "pyright"]
201+
extra-dependencies = ["django-stubs", "channels-redis", "pyright", "jinja2"]
202202

203203
[tool.hatch.envs.python.scripts]
204204
type_check = ["pyright src"]

src/reactpy_django/templatetags/jinja.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from jinja2 import Environment
2828
from reactpy_django.templatetags.jinja import ReactPyExtension
2929
30+
3031
def environment(**options):
3132
env = Environment(**options)
3233
env.add_extension(ReactPyExtension)
@@ -35,26 +36,30 @@ def environment(**options):
3536

3637
from __future__ import annotations
3738

38-
import json
3939
from logging import getLogger
4040
from typing import TYPE_CHECKING
4141

4242
from django.template import RequestContext, loader
43-
from django.utils.safestring import mark_safe
4443
from jinja2 import pass_context
4544
from jinja2.ext import Extension
46-
from jinja2.runtime import Context
4745

4846
from reactpy_django.templatetags.reactpy import (
4947
COMPONENT_TEMPLATE,
5048
PYSCRIPT_COMPONENT_TEMPLATE,
5149
PYSCRIPT_SETUP_TEMPLATE,
50+
)
51+
from reactpy_django.templatetags.reactpy import (
5252
component as django_component_tag,
53+
)
54+
from reactpy_django.templatetags.reactpy import (
5355
pyscript_component as django_pyscript_component_tag,
56+
)
57+
from reactpy_django.templatetags.reactpy import (
5458
pyscript_setup as django_pyscript_setup_tag,
5559
)
5660

5761
if TYPE_CHECKING:
62+
from jinja2.runtime import Context
5863
from reactpy.types import Component, VdomDict
5964

6065
_logger = getLogger(__name__)
@@ -75,8 +80,6 @@ class ReactPyExtension(Extension):
7580
function expansions.
7681
"""
7782

78-
tags = {}
79-
8083
def __init__(self, environment):
8184
super().__init__(environment)
8285
environment.globals["component"] = self._component
@@ -111,7 +114,7 @@ def _component(
111114
"""
112115
request = jinja_context.parent.get("request")
113116
if request is None:
114-
_logger.exception(
117+
_logger.error(
115118
"Cannot render a ReactPy component in a Jinja2 template without a "
116119
"request object. Ensure the 'django.template.context_processors.request' "
117120
"context processor is enabled for your Jinja2 backend."
@@ -159,10 +162,7 @@ def _pyscript_component(
159162
"""
160163
request = jinja_context.parent.get("request")
161164
if request is None:
162-
_logger.exception(
163-
"Cannot render a PyScript component in a Jinja2 template without a "
164-
"request object."
165-
)
165+
_logger.error("Cannot render a PyScript component in a Jinja2 template without a request object.")
166166
return ""
167167

168168
django_context = RequestContext(

tests/test_app/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@
1515
cwd=str(js_dir),
1616
check=True,
1717
)
18-
else:
19-
# Verify that JS artifacts already exist so we don't silently skip a needed build
20-
if not (static_dir / "index.js").exists():
21-
raise RuntimeError(
22-
"bun is not installed and JS artifacts are missing. "
23-
f"Run 'bun install && bun build' in {js_dir} first."
24-
)
18+
# Verify that JS artifacts already exist so we don't silently skip a needed build
19+
elif not (static_dir / "index.js").exists():
20+
msg = f"bun is not installed and JS artifacts are missing. Run 'bun install && bun build' in {js_dir} first."
21+
raise RuntimeError(msg)
2522

2623

2724
# Make sure the test environment is always using the latest JS

tests/test_app/tests/test_jinja.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Jinja2ComponentTests(TestCase):
4040
def test_component_function_available(self):
4141
"""The component function should be available in Jinja2 templates."""
4242
from jinja2 import Environment
43+
4344
from reactpy_django.templatetags.jinja import ReactPyExtension
4445

4546
env = Environment()
@@ -52,6 +53,7 @@ def test_component_function_available(self):
5253
def test_pyscript_component_function_available(self):
5354
"""The pyscript_component function should be available in Jinja2 templates."""
5455
from jinja2 import Environment
56+
5557
from reactpy_django.templatetags.jinja import ReactPyExtension
5658

5759
env = Environment()
@@ -64,6 +66,7 @@ def test_pyscript_component_function_available(self):
6466
def test_pyscript_setup_function_available(self):
6567
"""The pyscript_setup function should be available in Jinja2 templates."""
6668
from jinja2 import Environment
69+
6770
from reactpy_django.templatetags.jinja import ReactPyExtension
6871

6972
env = Environment()
@@ -78,9 +81,7 @@ def test_jinja_component_renders_without_error(self):
7881
from django.template import engines
7982

8083
jinja2_engine = engines["jinja2"]
81-
template = jinja2_engine.from_string(
82-
"{{ component('test_app.components.hello_world') }}"
83-
)
84+
template = jinja2_engine.from_string("{{ component('test_app.components.hello_world') }}")
8485
rendered = template.render({})
8586
# The rendered output should be a string of some sort
8687
assert isinstance(rendered, str)
@@ -105,8 +106,6 @@ class Jinja2ViewTests(TestCase):
105106
def test_jinja_base_template_view_status(self):
106107
"""The Jinja2 base template view should return HTTP 200."""
107108
# Note: These tests require the Jinja2 settings module
108-
pass
109109

110110
def test_jinja_errors_template_view_status(self):
111111
"""The Jinja2 errors template view should return HTTP 200."""
112-
pass

0 commit comments

Comments
 (0)