Skip to content

Commit

Permalink
chore: ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Oct 9, 2024
1 parent 787f2a7 commit 946fb4a
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/jinjarope/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def load_jinja_file(
self._add_loader(loader)

@overload
def compile( # type: ignore[misc] # noqa: A003
def compile( # type: ignore[misc]
self,
source: str | jinja2.nodes.Template,
name: str | None = None,
Expand All @@ -191,7 +191,7 @@ def compile( # type: ignore[misc] # noqa: A003
) -> CodeType: ...

@overload
def compile( # noqa: A003
def compile(
self,
source: str | jinja2.nodes.Template,
name: str | None = None,
Expand All @@ -200,7 +200,7 @@ def compile( # noqa: A003
defer_init: bool = False,
) -> str: ...

def compile( # noqa: A003
def compile(
self,
source: str | jinja2.nodes.Template,
name: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions src/jinjarope/fsspecloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FsSpecProtocolPathLoader(loaders_.LoaderMixin, jinja2.BaseLoader):
ID = "fsspec_protocol_path"

def __eq__(self, other):
return type(self) == type(other)
return type(self) is type(other)

def __hash__(self):
return hash(type(self))
Expand Down Expand Up @@ -117,7 +117,7 @@ def __repr__(self):

def __eq__(self, other):
return (
type(self) == type(other)
type(self) is type(other)
and self.storage_options == other.storage_options
and self.fs == other.fs
and self.path == other.path
Expand Down
10 changes: 5 additions & 5 deletions src/jinjarope/htmlfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import posixpath
import re
from typing import TYPE_CHECKING, Any, Literal
from xml.etree import ElementTree as Et
from xml.etree import ElementTree as ET


if TYPE_CHECKING:
Expand Down Expand Up @@ -170,7 +170,7 @@ def _parse(obj, selector: str = ""):

@functools.lru_cache
def format_xml(
str_or_elem: str | Et.Element,
str_or_elem: str | ET.Element,
indent: str | int = " ",
level: int = 0,
method: Literal["xml", "html", "text", "c14n"] = "html",
Expand All @@ -190,10 +190,10 @@ def format_xml(
(applies when mode is "xml")
"""
if isinstance(str_or_elem, str):
str_or_elem = Et.fromstring(str_or_elem)
str_or_elem = ET.fromstring(str_or_elem)
space = indent if isinstance(indent, str) else indent * " "
Et.indent(str_or_elem, space=space, level=level)
return Et.tostring(
ET.indent(str_or_elem, space=space, level=level)
return ET.tostring(
str_or_elem,
encoding="unicode",
method=method,
Expand Down
14 changes: 7 additions & 7 deletions src/jinjarope/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __repr__(self):
return utils.get_repr(self, self.mapping)

def __eq__(self, other):
return type(self) == type(other) and self.mapping == other.mapping
return type(self) is type(other) and self.mapping == other.mapping

def __hash__(self):
return hash(tuple(sorted(self.mapping.items())))
Expand All @@ -85,7 +85,7 @@ def __repr__(self):

def __eq__(self, other):
return (
type(self) == type(other)
type(self) is type(other)
and self.package_name == other.package_name
and self.module == other.module
)
Expand All @@ -107,7 +107,7 @@ def __repr__(self):
return utils.get_repr(self, self.load_func)

def __eq__(self, other):
return type(self) == type(other) and self.load_func == other.load_func
return type(self) is type(other) and self.load_func == other.load_func

def __hash__(self):
return hash(self.load_func)
Expand Down Expand Up @@ -151,7 +151,7 @@ def __repr__(self):

def __eq__(self, other):
return (
type(self) == type(other)
type(self) is type(other)
and self.package_name == other.package_name
and self.package_path == other.package_path
)
Expand All @@ -176,7 +176,7 @@ def __bool__(self):
return len(self.searchpath) > 0

def __eq__(self, other):
return type(self) == type(other) and self.searchpath == other.searchpath
return type(self) is type(other) and self.searchpath == other.searchpath

def __hash__(self):
return hash(tuple(self.searchpath))
Expand All @@ -194,7 +194,7 @@ def __bool__(self):
return len(self.loaders) > 0

def __eq__(self, other):
return type(self) == type(other) and self.loaders == other.loaders
return type(self) is type(other) and self.loaders == other.loaders

def __hash__(self):
return hash(tuple(self.loaders))
Expand All @@ -219,7 +219,7 @@ def __add__(self, other):
return DictLoader(mapping)

def __eq__(self, other):
return type(self) == type(other) and self.mapping == other.mapping
return type(self) is type(other) and self.mapping == other.mapping

def __hash__(self):
return hash(tuple(sorted(self.mapping.items())))
Expand Down
3 changes: 2 additions & 1 deletion src/jinjarope/regexfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ def re_escape(string: str, re_type: Literal["python", "posix_basic"] = "python")
# list of BRE special chars:
return re_replace(string, r"([].[^$*\\])", r"\\\1")
case _:
raise NotImplementedError("Invalid regex type (%s)" % re_type)
msg = f"Invalid regex type ({re_type})"
raise NotImplementedError(msg)
2 changes: 1 addition & 1 deletion src/jinjarope/rewriteloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __repr__(self):

def __eq__(self, other):
return (
type(self) == type(other)
type(self) is type(other)
and self.loader == other.loader
and self.rewrite_fn == other.rewrite_fn
)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from jinjarope import cli
from typer.testing import CliRunner

from jinjarope import cli


def test_render_with_cli():
runner = CliRunner()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from typing import TYPE_CHECKING

import jinja2
import jinjarope
import pytest

import jinjarope


if TYPE_CHECKING:
import pathlib
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fsspec_loaders.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import jinja2
from jinjarope import environment, fsspecloaders
import pytest

from jinjarope import environment, fsspecloaders


def test_fsspec_protocol_loader():
env = environment.Environment()
Expand Down
9 changes: 5 additions & 4 deletions tests/test_htmlfilters.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from xml.etree import ElementTree as Et
from xml.etree import ElementTree as ET

from jinjarope import htmlfilters
import pytest

from jinjarope import htmlfilters


def test_wrap_in_elem():
assert htmlfilters.wrap_in_elem("Hello", "p") == "<p>Hello</p>"
Expand Down Expand Up @@ -92,8 +93,8 @@ def test_format_xml_with_str():


def test_format_xml_with_element():
xml_elem = Et.Element("root")
child = Et.SubElement(xml_elem, "child")
xml_elem = ET.Element("root")
child = ET.SubElement(xml_elem, "child")
child.text = "text"
formatted_xml = htmlfilters.format_xml(xml_elem)
expected_xml = "<root>\n <child>text</child>\n</root>"
Expand Down
3 changes: 2 additions & 1 deletion tests/test_jinjaloaderfilesystem.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import jinja2
from jinjarope import jinjaloaderfilesystem
import pytest

from jinjarope import jinjaloaderfilesystem


dct = {"home.html": "Home", "about.html": "About", "subfolder/sub.html": "Sub"}

Expand Down
3 changes: 2 additions & 1 deletion tests/test_manual.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from jinjarope import manual
import mknodes as mk

from jinjarope import manual


def test_building_the_docs():
build = manual.Build()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_nested_dict_loader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import jinja2
from jinjarope import configloaders
import pytest

from jinjarope import configloaders


def test_nested_dict_loader():
templates = {
Expand Down
3 changes: 2 additions & 1 deletion tests/test_regexfilters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

from jinja2.exceptions import FilterArgumentError
from jinjarope import regexfilters
import pytest

from jinjarope import regexfilters


def test_re_replace():
assert (
Expand Down
3 changes: 2 additions & 1 deletion tests/test_template_file_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from typing import TYPE_CHECKING

import jinja2
from jinjarope import configloaders
import pytest

from jinjarope import configloaders


if TYPE_CHECKING:
import pathlib
Expand Down

0 comments on commit 946fb4a

Please sign in to comment.