diff --git a/gen_wrap.py b/gen_wrap.py index 549925a..4a1caa9 100644 --- a/gen_wrap.py +++ b/gen_wrap.py @@ -52,15 +52,10 @@ NON_COPYABLE = ["ctx", "printer", "access_info"] NON_COPYABLE_WITH_ISL_PREFIX = [f"isl_{i}" for i in NON_COPYABLE] -PYTHON_RESERVED_WORDS = """ -and del from not while -as elif global or with -assert else if pass yield -break except import print -class exec in raise -continue finally is return -def for lambda try -""".split() +PYTHON_RESERVED_WORDS = ["and", "del", "from", "not", "while", "as", "elif", "global", +"or", "with", "assert", "else", "if", "pass", "yield", "break", "except", "import", +"print", "class", "exec", "in", "raise", "continue", "finally", "is", "return", "def", +"for", "lambda", "try"] class Retry(RuntimeError): # noqa: N818 @@ -86,8 +81,7 @@ def to_py_class(cls: str): if cls == "int": return cls - if cls.startswith("isl_"): - cls = cls[4:] + cls = cls.removeprefix("isl_") if cls == "ctx": return "Context" @@ -105,9 +99,7 @@ def to_py_class(cls: str): else: result += c - result = result.replace("Qpoly", "QPoly") - - return result + return result.replace("Qpoly", "QPoly") # {{{ data model @@ -503,11 +495,9 @@ def get_preprocessed_header(self, fname: str) -> str: self.get_header_contents(mh) for mh in self.macro_headers] - prepro_header = preprocess_with_macros( + return preprocess_with_macros( macro_header_contents, self.get_header_contents(fname)) - return prepro_header - # {{{ read_header def read_header(self, fname: str): @@ -536,11 +526,8 @@ def read_header(self, fname: str): while i < len(lines): line = lines[i].strip() - if (not line - or line.startswith("extern") - or STRUCT_DECL_RE.search(line) - or line.startswith("typedef") - or line == "}"): + if (not line or line.startswith(("extern", "typedef")) + or STRUCT_DECL_RE.search(line) or line == "}"): i += 1 elif "/*" in line: while True: @@ -661,7 +648,7 @@ def parse_decl(self, decl: str): if name.startswith("options_"): class_name = "ctx" name = name[len("options_"):] - elif name.startswith("equality_") or name.startswith("inequality_"): + elif name.startswith(("equality_", "inequality_")): class_name = "constraint" elif name == "ast_op_type_set_print_name": class_name = "printer" @@ -697,7 +684,7 @@ def parse_decl(self, decl: str): return if class_name == "options": - assert name.startswith("set_") or name.startswith("get_"), (name, c_name) + assert name.startswith(("set_", "get_")), (name, c_name) name = f"{name[:4]}option_{name[4:]}" words = return_base_type.split() @@ -1497,9 +1484,8 @@ def write_exposer( if basic_cls == "basic_set": if meth.name in ["is_params", "get_hash"]: continue - elif basic_cls == "basic_map": - if meth.name in ["get_hash"]: - continue + elif basic_cls == "basic_map" and meth.name in ["get_hash"]: + continue basic_overloads.append(meth) diff --git a/islpy/_monkeypatch.py b/islpy/_monkeypatch.py index 791cacd..c0cdec3 100644 --- a/islpy/_monkeypatch.py +++ b/islpy/_monkeypatch.py @@ -18,11 +18,11 @@ if TYPE_CHECKING: - import islpy._isl as _isl + from islpy import _isl else: import sys if "_isl" not in sys.modules: - import islpy._isl as _isl + from islpy import _isl else: # This is used for monkeypatching during stub generation. # See stubgen/stubgen.py and CMakeLists for orchestration details. diff --git a/pyproject.toml b/pyproject.toml index aa8f87c..3592769 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,6 +103,8 @@ extend-ignore = [ "UP031", # use f-strings instead of % "UP032", # use f-strings instead of .format "RUF067", # no code in __init__ *shrug* + "TRY300", + "SIM102", ] [tool.ruff.lint.flake8-quotes] @@ -123,6 +125,10 @@ lines-after-imports = 2 "RUF012" ] +"test/test_*.py" = ["S102"] +"doc/conf.py" = ["S102"] +"gen_wrap.py" = ["SIM115"] + [tool.cibuildwheel] # i686 does not have enough memory for LTO to complete # 3.14 on musl has a hard-to-debug test crash diff --git a/stubgen/stubgen.py b/stubgen/stubgen.py index 5b11a01..c7a9cd3 100644 --- a/stubgen/stubgen.py +++ b/stubgen/stubgen.py @@ -66,7 +66,7 @@ def main(): for fname in cast("list[str]", args.exec or []): execdict = {"__name__": "islpy._monkeypatch"} with open(fname) as inf: - exec(compile(inf.read(), fname, "exec"), execdict) + exec(compile(inf.read(), fname, "exec"), execdict) # noqa: S102 sg = StubGen( module=mod, @@ -75,10 +75,9 @@ def main(): include_docstrings=False, ) sg.put(mod) - prefix_lines = "\n".join([ - "from typing_extensions import Self", - "from collections.abc import Callable", - ]) + prefix_lines = ( + "from typing_extensions import Self\n" + "from collections.abc import Callable") with open(output_path / "_isl.pyi", "w") as outf: outf.write(f"{prefix_lines}\n{sg.get()}") diff --git a/test/test_isl.py b/test/test_isl.py index 12bc1b3..d2a1aaa 100644 --- a/test/test_isl.py +++ b/test/test_isl.py @@ -220,13 +220,11 @@ def callback(node, build): def cb_print_user(printer, options, node): print("Callback user called") - printer = printer.print_str("Callback user") - return printer + return printer.print_str("Callback user") def cb_print_for(printer, options, node): print("Callback for called") - printer = printer.print_str("Callback For") - return printer + return printer.print_str("Callback For") opts = isl.AstPrintOptions.alloc(isl.DEFAULT_CONTEXT) opts, _cb_print_user_handle = opts.set_print_user(cb_print_user)