Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: ruff improvements #354

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- unihan-etl: 0.25.0 -> 0.26.0

pytest plugin with cached UNIHAN data.
- ruff: code quality improvements (#354)

## cihai 0.26.0 (2023-07-01)

Expand Down
31 changes: 14 additions & 17 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# flake8: NOQA E501
# flake8: NOQA: E501
import inspect
import os
import pathlib
import sys
import typing as t
from os.path import dirname, relpath
from os.path import relpath
from pathlib import Path

import cihai
Expand All @@ -21,7 +21,7 @@

# package data
about: t.Dict[str, str] = {}
with open(src_root / "cihai" / "__about__.py") as fp:
with (src_root / "cihai" / "__about__.py").open() as fp:
exec(fp.read(), about)

extensions = [
Expand Down Expand Up @@ -136,8 +136,8 @@
latex_documents = [
(
"index",
"{0}.tex".format(about["__package_name__"]),
"{0} Documentation".format(about["__title__"]),
"{}.tex".format(about["__package_name__"]),
"{} Documentation".format(about["__title__"]),
about["__author__"],
"manual",
)
Expand All @@ -147,7 +147,7 @@
(
"index",
about["__package_name__"],
"{0} Documentation".format(about["__title__"]),
"{} Documentation".format(about["__title__"]),
about["__author__"],
1,
)
Expand All @@ -156,8 +156,8 @@
texinfo_documents = [
(
"index",
"{0}".format(about["__package_name__"]),
"{0} Documentation".format(about["__title__"]),
"{}".format(about["__package_name__"]),
"{} Documentation".format(about["__title__"]),
about["__author__"],
about["__package_name__"],
about["__description__"],
Expand Down Expand Up @@ -199,7 +199,7 @@ def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
for part in fullname.split("."):
try:
obj = getattr(obj, part)
except Exception:
except Exception: # ruff: noqa: PERF203
return None

# strip decorators, which would resolve to the source of the decorator
Expand All @@ -224,23 +224,20 @@ def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
except Exception:
lineno = None

if lineno:
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
else:
linespec = ""
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1) if lineno else ""

fn = relpath(fn, start=dirname(cihai.__file__))
fn = relpath(fn, start=pathlib.Path(cihai.__file__).parent)

if "dev" in about["__version__"]:
return "%s/blob/master/%s/%s/%s%s" % (
return "{}/blob/master/{}/{}/{}{}".format(
about["__github__"],
"src",
about["__package_name__"],
fn,
linespec,
)
else:
return "%s/blob/v%s/%s/%s/%s%s" % (
return "{}/blob/v{}/{}/{}/{}{}".format(
about["__github__"],
about["__version__"],
"src",
Expand Down
5 changes: 1 addition & 4 deletions src/cihai/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,7 @@ def parse_var(var: str) -> ParsedVar:
specified.
"""
bits = var.split("<", 1)
if len(bits) < 2:
tag = None
else:
tag = bits[1]
tag = None if len(bits) < 2 else bits[1]
return ucn_to_unicode(bits[0]), tag


Expand Down
5 changes: 1 addition & 4 deletions tests/test_extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ def variant_list(
field: str,
) -> t.Generator[t.Tuple[Unihan, t.List[str]], str, None]:
for char in c.unihan.with_fields([field]):
variants: t.List[str] = []
for var in char.untagged_vars(field):
variants.append(var)
yield (char, variants)
yield (char, list(char.untagged_vars(field)))

result = dict(variant_list("kZVariant"))

Expand Down