Conversation
There was a problem hiding this comment.
Pull request overview
Updates codebase style and linting configuration for “Ruff152”, primarily by modernizing imports, simplifying control flow, and aligning project config/baselines with updated static analysis output.
Changes:
- Refactors Python code to satisfy Ruff rules (imports, loops, conditionals, context managers).
- Updates Ruff configuration (global ignores and per-file ignores) and refreshes Based Pyright baseline.
- Bumps the
pyopencl/compytesubmodule revision.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/test_wrapper.py | Consolidates pyopencl submodule imports into a single from pyopencl import ... import. |
| test/test_enqueue_copy.py | Removes unused shebang/blank header lines for lint cleanliness. |
| test/test_clrandom.py | Consolidates pyopencl submodule imports into from pyopencl import .... |
| test/test_clmath.py | Simplifies imports and minor loop/conditional cleanups to satisfy linting. |
| test/test_arrays_in_structs.py | Consolidates imports and simplifies expected-result construction. |
| test/test_array.py | Removes shebang, modernizes import style, and adds targeted lint suppression for broad except. |
| test/test_algorithm.py | Switches to from pyopencl import clrandom within tests. |
| pyproject.toml | Adjusts Python requirement and extends Ruff configuration/ignores. |
| pyopencl/tools.py | Adds lint suppression for broad except in identifier parsing helper. |
| pyopencl/scan.py | Rewrites word sets as set literals and simplifies a small loop range. |
| pyopencl/invoker.py | Modernizes _cl import style and simplifies arg-size branching. |
| pyopencl/elementwise.py | Simplifies conditional logic for complex include handling. |
| pyopencl/compyte | Updates submodule commit pointer. |
| pyopencl/clrandom.py | Modernizes cltypes import style. |
| pyopencl/clmath.py | Modernizes elementwise import style. |
| pyopencl/characterize/init.py | Adds type hints, lint suppressions, and slightly refactors PoCL bug detection logic. |
| pyopencl/cache.py | Improves file handling via context managers; adds SIM115 suppression where needed. |
| pyopencl/bitonic_sort.py | Simplifies get_program by returning built program directly. |
| pyopencl/array.py | Consolidates imports and simplifies several conditionals/type annotations. |
| pyopencl/algorithm.py | Simplifies dtype field list construction with a comprehension. |
| pyopencl/_monkeypatch.py | Modernizes _cl import and simplifies dict iteration. |
| pyopencl/_cl.pyi | Adjusts stub style (...), and simplifies Literal unions. |
| pyopencl/init.py | Modernizes _cl import, simplifies option parsing, improves temp-file handling, and adds lint suppression. |
| examples/transpose.py | Simplifies event collection loop with a list comprehension. |
| examples/svm.py | Removes unused shebang/blank header lines. |
| examples/pi-monte-carlo.py | Removes shebang and simplifies functions to return literals directly. |
| examples/n-body.py | Removes shebang and simplifies elapsed-time return. |
| examples/image_filters_using_image2d_t.py | Removes shebang line for lint cleanliness. |
| examples/dump-properties.py | Simplifies string transform + return expression. |
| examples/demo.py | Removes unused shebang/blank header lines. |
| examples/black-hole-accretion.py | Removes shebang/comment noise; simplifies returns and conditionals. |
| contrib/fortran-to-opencl/translate.py | Refactors regex flags/import style, simplifies list building, and improves file handling. |
| .basedpyright/baseline.json | Refreshes baseline entries/ranges consistent with updated typing analysis. |
Comments suppressed due to low confidence (1)
pyopencl/init.py:611
- Using a backslash for line continuation inside a
withstatement is fragile (can break when trailing whitespace is introduced) and is generally discouraged. Consider rewriting this using parentheses (implicit continuation) or fitting it on one line to improve robustness and readability.
with NamedTemporaryFile(mode="wt", delete=False, suffix=".cl") \
as srcfile:
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pyproject.toml
Outdated
| { name = "Andreas Kloeckner", email = "inform@tiker.net" }, | ||
| ] | ||
| requires-python = "~=3.10" | ||
| requires-python = "~=3.10.0" |
There was a problem hiding this comment.
~=3.10.0 narrows the supported Python range to >=3.10.0,<3.11.0 (patch-specified compatible release). If the intent is to support all Python 3.10+ (or all 3.x from 3.10), consider reverting to ~=3.10 or using an explicit range like >=3.10 to avoid unintentionally dropping 3.11/3.12+.
| requires-python = "~=3.10.0" | |
| requires-python = ">=3.10" |
| def map_subscript(self, expr, enclosing_prec): | ||
| idx_dtype = self.infer_type(expr.index) | ||
| if not "i" == idx_dtype.kind or "u" == idx_dtype.kind: | ||
| if "i" != idx_dtype.kind or "u" == idx_dtype.kind: |
There was a problem hiding this comment.
This condition is logically equivalent to idx_dtype.kind != "i" (the "u" == idx_dtype.kind clause is redundant), which means unsigned integer indices (kind == "u") will always be cast to (int). If the intent is “cast unless the index dtype is an integer (signed or unsigned)”, this should instead check membership (e.g., idx_dtype.kind not in ("i", "u")) to avoid potentially incorrect casts for unsigned indices.
| if "i" != idx_dtype.kind or "u" == idx_dtype.kind: | |
| if idx_dtype.kind not in ("i", "u"): |
| "unit_size", "index_type", "interval_begin", "interval_size", "offset_end", "K", | ||
| "SCAN_EXPR", "do_update", "WG_SIZE", "first_segment_start_in_k_group", "scan_type", | ||
| "segment_start_in_subtree", "offset", "interval_results", "interval_end", | ||
| "first_segment_start_in_subtree", "unit_base", "first_segment_start_in_interval", | ||
| "k", "INPUT_EXPR", "prev_group_sum", "prev", "pv", "value", "partial_val", "pgs", | ||
| "is_seg_start", "update_i", "scan_item_at_i", "seq_i", "read_i", "l_", "o_mod_k", | ||
| "o_div_k", "l_segment_start_flags", "scan_value", "sum", "first_seg_start_in_interval", | ||
| "g_segment_start_flags", "group_base", "seg_end", "my_val", "DEBUG", "ARGS", | ||
| "ints_to_store", "ints_per_wg", "scan_types_per_int", "linear_index", | ||
| "linear_scan_data_idx", "dest", "src", "store_base", "wrapped_scan_type", "dummy", | ||
| "scan_tmp", "tmp_aux", "LID_2", "LID_1", "LID_0", "LDIM_0", "LDIM_1", "LDIM_2", | ||
| "GDIM_0", "GDIM_1", "GDIM_2", "GID_0", "GID_1", "GID_2"} | ||
|
|
||
| _IGNORED_WORDS = {"4", "8", "32", "typedef", "for", "endfor", "if", "void", "while", | ||
| "endwhile", "endif", "else", "const", "printf", "None", "return", "bool", "n", "char", | ||
| "true", "false", "ifdef", "pycl_printf", "str", "range", "assert", "np", "iinfo", | ||
| "max", "itemsize", "__packed__", "struct", "restrict", "ptrdiff_t", "set", "iteritems", | ||
| "len", "setdefault", "GLOBAL_MEM", "LOCAL_MEM_ARG", "WITHIN_KERNEL", "LOCAL_MEM", | ||
| "KERNEL", "REQD_WG_SIZE", "local_barrier", "CLK_LOCAL_MEM_FENCE", "OPENCL", "EXTENSION", | ||
| "pragma", "__attribute__", "__global", "__kernel", "__local", "get_local_size", | ||
| "get_local_id", "cl_khr_fp64", "reqd_work_group_size", "get_num_groups", "barrier", |
There was a problem hiding this comment.
Converting these large “word lists” into single massive set literals makes future edits and diffs harder to review (and the formatting here is difficult to read/maintain). Consider formatting the set literal across multiple properly indented lines (one item per line, trailing commas), or retaining the original triple-quoted + .split() approach if readability is the priority.
| "unit_size", "index_type", "interval_begin", "interval_size", "offset_end", "K", | |
| "SCAN_EXPR", "do_update", "WG_SIZE", "first_segment_start_in_k_group", "scan_type", | |
| "segment_start_in_subtree", "offset", "interval_results", "interval_end", | |
| "first_segment_start_in_subtree", "unit_base", "first_segment_start_in_interval", | |
| "k", "INPUT_EXPR", "prev_group_sum", "prev", "pv", "value", "partial_val", "pgs", | |
| "is_seg_start", "update_i", "scan_item_at_i", "seq_i", "read_i", "l_", "o_mod_k", | |
| "o_div_k", "l_segment_start_flags", "scan_value", "sum", "first_seg_start_in_interval", | |
| "g_segment_start_flags", "group_base", "seg_end", "my_val", "DEBUG", "ARGS", | |
| "ints_to_store", "ints_per_wg", "scan_types_per_int", "linear_index", | |
| "linear_scan_data_idx", "dest", "src", "store_base", "wrapped_scan_type", "dummy", | |
| "scan_tmp", "tmp_aux", "LID_2", "LID_1", "LID_0", "LDIM_0", "LDIM_1", "LDIM_2", | |
| "GDIM_0", "GDIM_1", "GDIM_2", "GID_0", "GID_1", "GID_2"} | |
| _IGNORED_WORDS = {"4", "8", "32", "typedef", "for", "endfor", "if", "void", "while", | |
| "endwhile", "endif", "else", "const", "printf", "None", "return", "bool", "n", "char", | |
| "true", "false", "ifdef", "pycl_printf", "str", "range", "assert", "np", "iinfo", | |
| "max", "itemsize", "__packed__", "struct", "restrict", "ptrdiff_t", "set", "iteritems", | |
| "len", "setdefault", "GLOBAL_MEM", "LOCAL_MEM_ARG", "WITHIN_KERNEL", "LOCAL_MEM", | |
| "KERNEL", "REQD_WG_SIZE", "local_barrier", "CLK_LOCAL_MEM_FENCE", "OPENCL", "EXTENSION", | |
| "pragma", "__attribute__", "__global", "__kernel", "__local", "get_local_size", | |
| "get_local_id", "cl_khr_fp64", "reqd_work_group_size", "get_num_groups", "barrier", | |
| "unit_size", | |
| "index_type", | |
| "interval_begin", | |
| "interval_size", | |
| "offset_end", | |
| "K", | |
| "SCAN_EXPR", | |
| "do_update", | |
| "WG_SIZE", | |
| "first_segment_start_in_k_group", | |
| "scan_type", | |
| "segment_start_in_subtree", | |
| "offset", | |
| "interval_results", | |
| "interval_end", | |
| "first_segment_start_in_subtree", | |
| "unit_base", | |
| "first_segment_start_in_interval", | |
| "k", | |
| "INPUT_EXPR", | |
| "prev_group_sum", | |
| "prev", | |
| "pv", | |
| "value", | |
| "partial_val", | |
| "pgs", | |
| "is_seg_start", | |
| "update_i", | |
| "scan_item_at_i", | |
| "seq_i", | |
| "read_i", | |
| "l_", | |
| "o_mod_k", | |
| "o_div_k", | |
| "l_segment_start_flags", | |
| "scan_value", | |
| "sum", | |
| "first_seg_start_in_interval", | |
| "g_segment_start_flags", | |
| "group_base", | |
| "seg_end", | |
| "my_val", | |
| "DEBUG", | |
| "ARGS", | |
| "ints_to_store", | |
| "ints_per_wg", | |
| "scan_types_per_int", | |
| "linear_index", | |
| "linear_scan_data_idx", | |
| "dest", | |
| "src", | |
| "store_base", | |
| "wrapped_scan_type", | |
| "dummy", | |
| "scan_tmp", | |
| "tmp_aux", | |
| "LID_2", | |
| "LID_1", | |
| "LID_0", | |
| "LDIM_0", | |
| "LDIM_1", | |
| "LDIM_2", | |
| "GDIM_0", | |
| "GDIM_1", | |
| "GDIM_2", | |
| "GID_0", | |
| "GID_1", | |
| "GID_2", | |
| } | |
| _IGNORED_WORDS = { | |
| "4", | |
| "8", | |
| "32", | |
| "typedef", | |
| "for", | |
| "endfor", | |
| "if", | |
| "void", | |
| "while", | |
| "endwhile", | |
| "endif", | |
| "else", | |
| "const", | |
| "printf", | |
| "None", | |
| "return", | |
| "bool", | |
| "n", | |
| "char", | |
| "true", | |
| "false", | |
| "ifdef", | |
| "pycl_printf", | |
| "str", | |
| "range", | |
| "assert", | |
| "np", | |
| "iinfo", | |
| "max", | |
| "itemsize", | |
| "__packed__", | |
| "struct", | |
| "restrict", | |
| "ptrdiff_t", | |
| "set", | |
| "iteritems", | |
| "len", | |
| "setdefault", | |
| "GLOBAL_MEM", | |
| "LOCAL_MEM_ARG", | |
| "WITHIN_KERNEL", | |
| "LOCAL_MEM", | |
| "KERNEL", | |
| "REQD_WG_SIZE", | |
| "local_barrier", | |
| "CLK_LOCAL_MEM_FENCE", | |
| "OPENCL", | |
| "EXTENSION", | |
| "pragma", | |
| "__attribute__", | |
| "__global", | |
| "__kernel", | |
| "__local", | |
| "get_local_size", | |
| "get_local_id", | |
| "cl_khr_fp64", | |
| "reqd_work_group_size", | |
| "get_num_groups", | |
| "barrier", | |
| } |
No description provided.