Skip to content

Commit

Permalink
fix(typing): Resolve/ignore typing in tools/
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Sep 3, 2024
1 parent 11280df commit f6b4923
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tools/schemapi/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def get_args(self, si: SchemaInfo) -> list[str]:
f"{p}: {info.to_type_repr(target='annotation', use_undefined=True)} = Undefined"
for p, info in prop_infos.items()
)
elif si.type:
elif isinstance(si.type, str):
py_type = jsonschema_to_python_types[si.type]
if py_type == "list":
# Try to get a type hint like "List[str]" which is more specific
Expand Down
17 changes: 7 additions & 10 deletions tools/schemapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import subprocess
import textwrap
import urllib
import urllib.parse
from html import unescape
from itertools import chain
from operator import itemgetter
Expand Down Expand Up @@ -289,7 +289,7 @@ def get_valid_identifier(

def is_valid_identifier(s: str, /) -> bool:
"""Return ``True`` if ``s`` contains a valid Python identifier."""
return _VALID_IDENT.match(s) and not keyword.iskeyword(s)
return _VALID_IDENT.match(s) is not None and not keyword.iskeyword(s)


class SchemaProperties:
Expand All @@ -311,11 +311,8 @@ def __bool__(self) -> bool:
def __dir__(self) -> list[str]:
return list(self._properties.keys())

def __getattr__(self, attr):
try:
return self[attr]
except KeyError:
return super().__getattr__(attr)
def __getattr__(self, attr) -> SchemaInfo:
return self[attr]

def __getitem__(self, attr) -> SchemaInfo:
dct = self._properties[attr]
Expand Down Expand Up @@ -748,7 +745,7 @@ def __init__(
super().__init__(renderer, block, inline, plugins)

def __call__(self, s: str) -> str:
s = super().__call__(s)
s = super().__call__(s) # pyright: ignore[reportAssignmentType]
return unescape(s).replace(r"\ ,", ",").replace(r"\ ", " ")


Expand Down Expand Up @@ -1045,8 +1042,8 @@ def ruff_write_lint_format_str(

def import_type_checking(*imports: str) -> str:
"""Write an `if TYPE_CHECKING` block."""
imports = "\n".join(f" {s}" for s in imports)
return f"\nif TYPE_CHECKING:\n # ruff: noqa: F405\n{imports}\n"
imps = "\n".join(f" {s}" for s in imports)
return f"\nif TYPE_CHECKING:\n # ruff: noqa: F405\n{imps}\n"


def import_typing_extensions(
Expand Down

0 comments on commit f6b4923

Please sign in to comment.