Skip to content

Commit

Permalink
Demonstrated superior-mypy-foo-skills by using type ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
euri10 committed Mar 4, 2024
1 parent 6732b63 commit 488e4bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 2 additions & 4 deletions litestar/contrib/minijinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def lookup(self, key: str) -> Any | None:
...


def _transform_state(
func: TemplateCallableType[Mapping[str, Any], P, T],
) -> TemplateCallableType[Mapping[str, Any], P, T]:
def _transform_state(func: TemplateCallableType[Mapping[str, Any], P, T]) -> TemplateCallableType[StateProtocol, P, T]:
"""Transform a template callable to receive a ``StateProtocol`` instance as first argument.
This is for wrapping callables like ``url_for()`` that receive a mapping as first argument so they can be used
Expand Down Expand Up @@ -181,7 +179,7 @@ def is_decorated(func: Callable) -> bool:
return hasattr(func, "__wrapped__") or func.__name__ not in globals()

if not is_decorated(template_callable):
template_callable = _transform_state(template_callable)
template_callable = _transform_state(template_callable) # type: ignore[arg-type]

Check warning on line 182 in litestar/contrib/minijinja.py

View check run for this annotation

Codecov / codecov/patch

litestar/contrib/minijinja.py#L182

Added line #L182 was not covered by tests
self.engine.add_global(key, pass_state(template_callable))

def render_string(self, template_string: str, context: Mapping[str, Any]) -> str:
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_plugins/test_flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class CustomCategory(str, Enum):
)
def test_flash_plugin(
tmp_path: Path,
# would gladly remove the ignore that works in test_template, not sure why not here
engine: type[TemplateEngineProtocol], # type: ignore[type-arg]
engine: type[TemplateEngineProtocol],
template_str: str,
category_enum: Enum,
) -> None:
Expand Down

0 comments on commit 488e4bb

Please sign in to comment.