Skip to content

Commit

Permalink
chore(ruff): Fix typings
Browse files Browse the repository at this point in the history
docs/conf.py:201:9: PERF203 `try`-`except` within a loop incurs performance overhead
src/cihai/conversion.py:129:23: UP018 [*] Unnecessary `int` call (rewrite as a literal)
src/cihai/conversion.py:215:19: UP018 [*] Unnecessary `int` call (rewrite as a literal)
  • Loading branch information
tony committed Aug 19, 2023
1 parent 9a4d50a commit 927cec9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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: # ruff: noqa: PERF203
except Exception: # noqa: PERF203
return None

# strip decorators, which would resolve to the source of the decorator
Expand Down
4 changes: 2 additions & 2 deletions src/cihai/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def ucn_to_unicode(ucn: str) -> str:
"""
if isinstance(ucn, str):
ucn = ucn.strip("U+")
if len(ucn) > int(4):
if len(ucn) > 4:
char_bytes = b"\\U" + format(int(ucn, 16), "08x").encode("latin1")
char = char_bytes.decode("unicode_escape")
else:
Expand Down Expand Up @@ -212,7 +212,7 @@ def python_to_ucn(uni_char: str, as_bytes: bool = False) -> t.Union[bytes, str]:
"""
ucn = uni_char.encode("unicode_escape").decode("latin1")
ucn = str(ucn).replace("\\", "").upper().lstrip("U")
if len(ucn) > int(4):
if len(ucn) > 4:
# get rid of the zeroes that Python uses to pad 32 byte UCNs
ucn = ucn.lstrip("0")
ucn = "U+" + ucn.upper()
Expand Down

0 comments on commit 927cec9

Please sign in to comment.