Skip to content

Commit

Permalink
chore: Ruff fixes (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Jul 18, 2023
2 parents 34db1ad + 5f50400 commit ea53b6d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $ pip install --user --upgrade --pre unihan-db
- unihan-etl: 0.25.0 -> 0.26.0

pytest plugin with cached UNIHAN data.
- ruff: Code quality fixes (#316)

## unihan-db 0.11.0 (2023-07-01)

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

import unihan_db

if t.TYPE_CHECKING:
from sphinx.application import Sphinx

# Get the project root dir, which is the parent dir of this
cwd = Path(__file__).parent
cwd = pathlib.Path(__file__).parent
project_root = cwd.parent
src_root = project_root / "src"

Expand All @@ -21,7 +20,7 @@

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


Expand Down Expand Up @@ -171,9 +170,7 @@
}


def linkcode_resolve(
domain: str, info: t.Dict[str, str]
) -> t.Union[None, str]:
def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
"""
Determine the URL corresponding to Python object
Expand All @@ -196,7 +193,7 @@ def linkcode_resolve(
for part in fullname.split("."):
try:
obj = getattr(obj, part)
except Exception:
except Exception: # noqa: PERF203
return None

# strip decorators, which would resolve to the source of the decorator
Expand All @@ -221,12 +218,9 @@ def linkcode_resolve(
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(unihan_db.__file__))
fn = relpath(fn, start=pathlib.Path(unihan_db.__file__).parent)

if "dev" in about["__version__"]:
return "{}/blob/master/{}/{}/{}{}".format(
Expand All @@ -250,7 +244,7 @@ def linkcode_resolve(
def remove_tabs_js(app: "Sphinx", exc: Exception) -> None:
# Fix for sphinx-inline-tabs#18
if app.builder.format == "html" and not exc:
tabs_js = Path(app.builder.outdir) / "_static" / "tabs.js"
tabs_js = pathlib.Path(app.builder.outdir) / "_static" / "tabs.js"
tabs_js.unlink(missing_ok=True)


Expand Down
1 change: 1 addition & 0 deletions src/unihan_db/importer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: PERF401
import typing as t

from unihan_db.tables import (
Expand Down

0 comments on commit ea53b6d

Please sign in to comment.