From 1e273cd77236890ed393a38fbe3c5d194d834a2e Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Tue, 18 Jul 2023 08:56:24 -0500 Subject: [PATCH] chore: Ruff fixes --- docs/conf.py | 26 ++++++++++---------------- src/unihan_db/importer.py | 1 + 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index c90595ed..0e45556f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,10 +1,9 @@ -# 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 @@ -12,7 +11,7 @@ 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" @@ -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) @@ -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 @@ -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 @@ -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( @@ -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) diff --git a/src/unihan_db/importer.py b/src/unihan_db/importer.py index d0852876..48ba2f33 100644 --- a/src/unihan_db/importer.py +++ b/src/unihan_db/importer.py @@ -1,3 +1,4 @@ +# flake8: noqa: PERF401 import typing as t from unihan_db.tables import (