Skip to content

Commit

Permalink
ci: Enable RSE and RET ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tefra committed Mar 22, 2024
1 parent cde3606 commit bf24054
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
rev: v0.3.3
hooks:
- id: ruff
args: [ --fix, --show-fixes ]
args: [ --fix, --show-fixes]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
Expand Down
Empty file added docs/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ select = [
"I",
# pydocstyle
"D",
# flake-raise
"RSE",
# flake-return
"RET",
]

ignore = [
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_annotations():
schema = filepath.joinpath("model.xsd")
runner = CliRunner()
result = runner.invoke(
cli, [str(schema), f"--config={str(filepath.joinpath('xsdata.xml'))}"]
cli, [str(schema), f"--config={filepath.joinpath('xsdata.xml')!s}"]
)

if result.exception:
Expand Down
9 changes: 1 addition & 8 deletions tests/integration/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from xsdata.formats.dataclass.parsers import JsonParser
from xsdata.formats.dataclass.serializers import JsonSerializer
from xsdata.formats.dataclass.serializers.config import SerializerConfig
from xsdata.utils.testing import load_class
from xsdata.utils.testing import filter_none, load_class

os.chdir(root)

Expand Down Expand Up @@ -36,10 +36,3 @@ def test_json_documents():
actual = serializer.render(obj)

assert filter_none(json.loads(ori)) == filter_none(json.loads(actual))


def filter_none(d):
if isinstance(d, dict):
return {k: filter_none(v) for k, v in d.items() if v is not None}
else:
return d
11 changes: 2 additions & 9 deletions tests/integration/test_stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from xsdata.formats.dataclass.parsers import JsonParser
from xsdata.formats.dataclass.serializers import JsonSerializer
from xsdata.formats.dataclass.serializers.config import SerializerConfig
from xsdata.utils.testing import load_class
from xsdata.utils.testing import filter_none, load_class

os.chdir(root)

Expand All @@ -20,7 +20,7 @@ def test_json_documents():
cli,
[
str(filepath.joinpath("samples")),
f"--config={str(filepath.joinpath('.xsdata.xml'))}",
f"--config={filepath.joinpath('.xsdata.xml')!s}",
],
)

Expand All @@ -39,10 +39,3 @@ def test_json_documents():
actual = serializer.render(obj)

assert filter_none(json.loads(ori)) == filter_none(json.loads(actual))


def filter_none(d):
if isinstance(d, dict):
return {k: filter_none(v) for k, v in d.items() if v is not None}
else:
return d
10 changes: 5 additions & 5 deletions xsdata/formats/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def deserialize(self, value: Any, **kwargs: Any) -> Decimal:
try:
return Decimal(value)
except InvalidOperation:
raise ConverterError()
raise ConverterError

def serialize(self, value: Decimal, **kwargs: Any) -> str:
"""Convert a decimal value sto string.
Expand Down Expand Up @@ -585,21 +585,21 @@ def resolve(value: str, ns_map: Optional[Dict] = None) -> Tuple[str, str]:
value = value.strip()

if not value:
raise ConverterError()
raise ConverterError

if value[0] == "{":
uri, name = text.split(value[1:], "}")

if not namespaces.is_uri(uri):
raise ConverterError()
raise ConverterError
else:
prefix, name = text.split(value, ":")
uri = ns_map.get(prefix) if ns_map else None
if prefix and not uri:
raise ConverterError(f"Unknown namespace prefix: `{prefix}`")

if " " in name or not namespaces.is_ncname(name):
raise ConverterError()
raise ConverterError

return uri, name

Expand Down Expand Up @@ -648,7 +648,7 @@ def deserialize(
if self.match(value, values, length, member.value, **kwargs):
return member

raise ConverterError()
raise ConverterError

@classmethod
def match(
Expand Down
14 changes: 7 additions & 7 deletions xsdata/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def parse(self) -> Iterator[int]:
yield from self.parse_var(var)

if self.vidx != self.vlen:
raise ValueError()
raise ValueError

except Exception:
raise ValueError(
Expand All @@ -177,7 +177,7 @@ def peek(self) -> str:
def skip(self, char: str):
"""Validate and skip over the given char."""
if not self.has_more() or self.peek() != char:
raise ValueError()
raise ValueError

self.vidx += 1

Expand All @@ -194,7 +194,7 @@ def parse_var(self, var: str):
elif var == "z":
yield self.parse_offset()
else:
raise ValueError()
raise ValueError

def parse_year(self) -> int:
"""Parse the year argument."""
Expand All @@ -216,7 +216,7 @@ def parse_year(self) -> int:
or (leading_zeros == 4 and year > 0)
or (leading_zeros > 4)
):
raise ValueError()
raise ValueError

if negative:
return -year
Expand All @@ -228,8 +228,8 @@ def parse_fractional_second(self) -> int:
if self.has_more() and self.peek() == ".":
self.vidx += 1
return self.parse_fixed_digits(9)
else:
return 0

return 0

def parse_digits(self, digits: int) -> int:
"""Parse the given number of digits."""
Expand Down Expand Up @@ -275,4 +275,4 @@ def parse_offset(self) -> Optional[int]:
offset *= -1 if ctrl == "-" else 1
return offset

raise ValueError()
raise ValueError
4 changes: 2 additions & 2 deletions xsdata/utils/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def is_ncname(name: Optional[str]) -> bool:
for char in name[1:]:
if char.isalpha() or char.isdigit() or char in NCNAME_PUNCTUATION:
continue
else:
return False

return False

return True

Expand Down
7 changes: 7 additions & 0 deletions xsdata/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
}


def filter_none(d: Any) -> Any:
if not isinstance(d, dict):
return d

return {k: filter_none(v) for k, v in d.items() if v is not None}


def load_class(output: str, clazz_name: str) -> Any:
search = "Generating package: "
start = len(search)
Expand Down

0 comments on commit bf24054

Please sign in to comment.