Skip to content

Commit eba2a71

Browse files
committed
Update config, fix lints for ruff 0.15.2
1 parent d28372e commit eba2a71

5 files changed

Lines changed: 27 additions & 38 deletions

File tree

gen_wrap.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,10 @@
5252
NON_COPYABLE = ["ctx", "printer", "access_info"]
5353
NON_COPYABLE_WITH_ISL_PREFIX = [f"isl_{i}" for i in NON_COPYABLE]
5454

55-
PYTHON_RESERVED_WORDS = """
56-
and del from not while
57-
as elif global or with
58-
assert else if pass yield
59-
break except import print
60-
class exec in raise
61-
continue finally is return
62-
def for lambda try
63-
""".split()
55+
PYTHON_RESERVED_WORDS = ["and", "del", "from", "not", "while", "as", "elif", "global",
56+
"or", "with", "assert", "else", "if", "pass", "yield", "break", "except", "import",
57+
"print", "class", "exec", "in", "raise", "continue", "finally", "is", "return", "def",
58+
"for", "lambda", "try"]
6459

6560

6661
class Retry(RuntimeError): # noqa: N818
@@ -86,8 +81,7 @@ def to_py_class(cls: str):
8681
if cls == "int":
8782
return cls
8883

89-
if cls.startswith("isl_"):
90-
cls = cls[4:]
84+
cls = cls.removeprefix("isl_")
9185

9286
if cls == "ctx":
9387
return "Context"
@@ -105,9 +99,7 @@ def to_py_class(cls: str):
10599
else:
106100
result += c
107101

108-
result = result.replace("Qpoly", "QPoly")
109-
110-
return result
102+
return result.replace("Qpoly", "QPoly")
111103

112104

113105
# {{{ data model
@@ -503,11 +495,9 @@ def get_preprocessed_header(self, fname: str) -> str:
503495
self.get_header_contents(mh)
504496
for mh in self.macro_headers]
505497

506-
prepro_header = preprocess_with_macros(
498+
return preprocess_with_macros(
507499
macro_header_contents, self.get_header_contents(fname))
508500

509-
return prepro_header
510-
511501
# {{{ read_header
512502

513503
def read_header(self, fname: str):
@@ -536,11 +526,8 @@ def read_header(self, fname: str):
536526
while i < len(lines):
537527
line = lines[i].strip()
538528

539-
if (not line
540-
or line.startswith("extern")
541-
or STRUCT_DECL_RE.search(line)
542-
or line.startswith("typedef")
543-
or line == "}"):
529+
if (not line or line.startswith(("extern", "typedef"))
530+
or STRUCT_DECL_RE.search(line) or line == "}"):
544531
i += 1
545532
elif "/*" in line:
546533
while True:
@@ -661,7 +648,7 @@ def parse_decl(self, decl: str):
661648
if name.startswith("options_"):
662649
class_name = "ctx"
663650
name = name[len("options_"):]
664-
elif name.startswith("equality_") or name.startswith("inequality_"):
651+
elif name.startswith(("equality_", "inequality_")):
665652
class_name = "constraint"
666653
elif name == "ast_op_type_set_print_name":
667654
class_name = "printer"
@@ -697,7 +684,7 @@ def parse_decl(self, decl: str):
697684
return
698685

699686
if class_name == "options":
700-
assert name.startswith("set_") or name.startswith("get_"), (name, c_name)
687+
assert name.startswith(("set_", "get_")), (name, c_name)
701688
name = f"{name[:4]}option_{name[4:]}"
702689

703690
words = return_base_type.split()
@@ -1497,9 +1484,8 @@ def write_exposer(
14971484
if basic_cls == "basic_set":
14981485
if meth.name in ["is_params", "get_hash"]:
14991486
continue
1500-
elif basic_cls == "basic_map":
1501-
if meth.name in ["get_hash"]:
1502-
continue
1487+
elif basic_cls == "basic_map" and meth.name in ["get_hash"]:
1488+
continue
15031489

15041490
basic_overloads.append(meth)
15051491

islpy/_monkeypatch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919

2020
if TYPE_CHECKING:
21-
import islpy._isl as _isl
21+
from islpy import _isl
2222
else:
2323
import sys
2424
if "_isl" not in sys.modules:
25-
import islpy._isl as _isl
25+
from islpy import _isl
2626
else:
2727
# This is used for monkeypatching during stub generation.
2828
# See stubgen/stubgen.py and CMakeLists for orchestration details.

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ extend-ignore = [
103103
"UP031", # use f-strings instead of %
104104
"UP032", # use f-strings instead of .format
105105
"RUF067", # no code in __init__ *shrug*
106+
"TRY300",
107+
"SIM102",
106108
]
107109

108110
[tool.ruff.lint.flake8-quotes]
@@ -123,6 +125,10 @@ lines-after-imports = 2
123125
"RUF012"
124126
]
125127

128+
"test/test_*.py" = ["S102"]
129+
"doc/conf.py" = ["S102"]
130+
"gen_wrap.py" = ["SIM115"]
131+
126132
[tool.cibuildwheel]
127133
# i686 does not have enough memory for LTO to complete
128134
# 3.14 on musl has a hard-to-debug test crash

stubgen/stubgen.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def main():
6666
for fname in cast("list[str]", args.exec or []):
6767
execdict = {"__name__": "islpy._monkeypatch"}
6868
with open(fname) as inf:
69-
exec(compile(inf.read(), fname, "exec"), execdict)
69+
exec(compile(inf.read(), fname, "exec"), execdict) # noqa: S102
7070

7171
sg = StubGen(
7272
module=mod,
@@ -75,10 +75,9 @@ def main():
7575
include_docstrings=False,
7676
)
7777
sg.put(mod)
78-
prefix_lines = "\n".join([
79-
"from typing_extensions import Self",
80-
"from collections.abc import Callable",
81-
])
78+
prefix_lines = (
79+
"from typing_extensions import Self\n"
80+
"from collections.abc import Callable")
8281
with open(output_path / "_isl.pyi", "w") as outf:
8382
outf.write(f"{prefix_lines}\n{sg.get()}")
8483

test/test_isl.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,11 @@ def callback(node, build):
220220

221221
def cb_print_user(printer, options, node):
222222
print("Callback user called")
223-
printer = printer.print_str("Callback user")
224-
return printer
223+
return printer.print_str("Callback user")
225224

226225
def cb_print_for(printer, options, node):
227226
print("Callback for called")
228-
printer = printer.print_str("Callback For")
229-
return printer
227+
return printer.print_str("Callback For")
230228

231229
opts = isl.AstPrintOptions.alloc(isl.DEFAULT_CONTEXT)
232230
opts, _cb_print_user_handle = opts.set_print_user(cb_print_user)

0 commit comments

Comments
 (0)