Skip to content

Conversation

@cpcloud
Copy link
Contributor

@cpcloud cpcloud commented Jan 8, 2026

Enable flake8-bugbear ruff lints and fix problems.

@copy-pr-bot
Copy link

copy-pr-bot bot commented Jan 8, 2026

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 8, 2026

/ok to test

@cpcloud cpcloud changed the title flake8 bugbear fix: enable flake8-bugbear lints and fix found problems Jan 8, 2026
@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 8, 2026

Actually a decent amount of unnecessary API calls happening in these modules, mostly enumerates and pulling out keys or values of dicts without using them.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

enabled flake8-bugbear linting rules and fixed all identified issues across 29 Python files.

The changes primarily address:

  • B007: Removed unused loop variables by using _ placeholder, .values() instead of .items(), or adding noqa comments where the variable is used after the loop
  • B009/B010: Replaced getattr() and setattr() with direct attribute access where safe
  • B004: Replaced hasattr(value, "__call__") with callable(value)

All fixes are semantically equivalent to the original code. The two instances with noqa: B007 comments (interpreter.py and deviceufunc.py) correctly preserve loop variables that are used after the loop completes.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • All changes are automated linting fixes that maintain semantic equivalence. The refactorings (removing unused variables, replacing getattr/setattr with direct access, using callable() builtin) are standard Python best practices. The two noqa comments are correctly placed where loop variables are genuinely used after the loop.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
pyproject.toml 5/5 enabled flake8-bugbear rules B007 and added ignores for B028, B904, B905; formatting changes to improve readability
numba_cuda/numba/cuda/core/boxing.py 5/5 replaced setattr() calls with direct attribute assignment (B009/B010 fix)
numba_cuda/numba/cuda/core/bytecode.py 5/5 replaced loop with list comprehension to remove unused variable (B007 fix)
numba_cuda/numba/cuda/core/byteflow.py 5/5 removed unused loop variables by using .values() or _ placeholder (B007 fix)
numba_cuda/numba/cuda/core/interpreter.py 5/5 added noqa: B007 comment for loop variable i that is used after the loop
numba_cuda/numba/cuda/core/transforms.py 5/5 replaced manual loop with range object and removed unused loop variable (B007 fix)
numba_cuda/numba/cuda/cudaimpl.py 5/5 optimized strides computation by using in-place reverse instead of double list reversal (B007 fix)
numba_cuda/numba/cuda/deviceufunc.py 5/5 added noqa: B007 for loop variable i used in exception handler; replaced getattr() with direct attribute access (B009 fix)
numba_cuda/numba/cuda/tests/cudapy/test_vectorize.py 5/5 replaced setattr() calls with direct attribute assignment (B010 fix)
numba_cuda/numba/cuda/typing/templates.py 5/5 replaced getattr() calls with direct attribute access (B009 fix)

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

This PR enables flake8-bugbear lints in the ruff configuration and systematically fixes all flagged issues across 46 files. The changes are primarily code quality improvements with no behavioral modifications.

Key improvements:

  • Fixed mutable default arguments (B006) - Changed [] to () and {} to None in function signatures
  • Eliminated loop variable capture bugs (B023) - Functions defined in loops now explicitly receive loop variables as parameters
  • Replaced unused loop variables with _ (B007) - Improved code clarity
  • Removed unnecessary getattr() and setattr() calls (B009, B010) - Using direct attribute access
  • Improved code efficiency - Changed list to set for membership checks, used generator expressions
  • Added strategic noqa comments where lint warnings are intentional (e.g., B018 for side-effect attribute access in cloudpickle)
  • Removed dead test code - Deleted already-skipped TestFailingStream class

Configuration changes:

  • Enabled flake8-bugbear rules ("B") in pyproject.toml
  • Added specific rule exceptions (B028, B904, B905, B019) for project-wide patterns
  • Added per-file exceptions for test files (B007, B018, B023)
  • Updated ruff to >=0.14.10 in pixi.toml

All changes are defensive improvements that eliminate potential bugs without altering functionality.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - all changes are defensive code quality improvements
  • The PR exclusively consists of automated lint fixes addressing flake8-bugbear warnings. Key fixes include eliminating mutable default arguments (common Python gotcha), fixing loop variable capture in closures (prevents subtle bugs), and removing unnecessary code patterns. All changes improve code quality without altering behavior. The systematic nature of the changes and focus on well-known anti-patterns make this a low-risk PR.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
pyproject.toml 5/5 Enabled flake8-bugbear lints (B rules) and added specific rule exceptions; reformatted with more readable line breaks
pixi.toml 5/5 Added ruff >=0.14.10 dependency and dev environment for linting work
numba_cuda/numba/cuda/core/interpreter.py 5/5 Fixed loop variable capture issues in closures by passing parameters explicitly; added noqa comments where needed
numba_cuda/numba/cuda/decorators.py 5/5 Changed mutable default argument from [] to () in jit decorator
numba_cuda/numba/cuda/extending.py 5/5 Fixed mutable default argument from {} to None with proper handling in function body
numba_cuda/numba/cuda/typing/templates.py 5/5 Replaced unnecessary getattr() calls with direct attribute access
numba_cuda/numba/cuda/core/ir.py 5/5 Improved loop efficiency, changed list to set for membership checks, fixed closure variable capture
numba_cuda/numba/cuda/core/byteflow.py 5/5 Replaced unused loop variables with _, changed append loop to extend with generator for efficiency
numba_cuda/numba/cuda/deviceufunc.py 5/5 Fixed mutable default arguments, replaced getattr() with direct access, modernized string formatting
numba_cuda/numba/cuda/np/arrayobj.py 5/5 Replaced unused loop variables with _, removed unnecessary setattr() call in favor of direct assignment

@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 8, 2026

/ok to test

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

This PR systematically enables flake8-bugbear lints and fixes all identified issues across 46 files.

Key changes:

  • Enabled flake8-bugbear rules (B-series) in pyproject.toml with specific exceptions for problematic rules (B028, B904, B905, B019) and test files (B007, B018, B023)
  • Fixed mutable default arguments (B006) by replacing {} with None and [] with () in function signatures across extending.py, decorators.py, base.py, deviceufunc.py, and test_caching.py
  • Replaced unused loop variables with _ (B007) in 30+ files to indicate intentional non-use
  • Fixed unnecessary getattr() calls (B009) by using direct attribute access in templates.py
  • Fixed setattr() usage (B010) by using direct assignment in arrayobj.py
  • Fixed function-in-loop closure issue (B023) in interpreter.py by moving nested function outside loop and passing required parameters
  • Added # noqa comments where violations are intentional (e.g., checking cell_contents for side effects)
  • Removed permanently skipped test class in test_streams.py
  • Updated formatting and added ruff to development environment

All changes follow best practices and improve code quality without altering functionality.

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • All changes are automated linting fixes that follow established best practices. The modifications are systematic (replacing unused variables, fixing mutable defaults, simplifying attribute access) and do not alter program behavior. The fixes address real code quality issues identified by flake8-bugbear. Appropriate # noqa comments are used where violations are intentional.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
pyproject.toml 5/5 enabled flake8-bugbear lints (B rules) and added specific rule exceptions for tests, formatted arrays more compactly
numba_cuda/numba/cuda/extending.py 5/5 fixed mutable default argument in overload function from {} to None (B006)
numba_cuda/numba/cuda/decorators.py 5/5 fixed mutable default argument from [] to () for link parameter (B006)
numba_cuda/numba/cuda/core/base.py 5/5 fixed mutable default arguments in compile functions from {} to None with proper handling (B006)
numba_cuda/numba/cuda/core/interpreter.py 5/5 fixed function-in-loop by passing blk parameter, moved do_change outside loop scope, added noqa for necessary cases (B023, B007)
numba_cuda/numba/cuda/deviceufunc.py 5/5 fixed mutable defaults, replaced .format() with f-string, added noqa for necessary loop variable usage (B006, B007)
numba_cuda/numba/cuda/typing/templates.py 5/5 replaced unnecessary getattr calls with direct attribute access (B009)
numba_cuda/numba/cuda/np/arrayobj.py 5/5 replaced unused loop variables, simplified setattr to direct assignment (B007, B010)
numba_cuda/numba/cuda/tests/cudadrv/test_streams.py 5/5 removed unused test class that was permanently skipped
numba_cuda/numba/cuda/tests/cudapy/test_caching.py 5/5 removed unused envvars parameter and its usage (B006)

Comment on lines 40 to 41
assert len(args) == arity
assert len(sig.args) == arity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these throw instead of asserting as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on whether these are validating input for users or making assertions about invariants. If they are asserting invariants then I would leave them. If users can provide "typical" inputs that can violate these assertions then we should make them proper raises.

@cpcloud
Copy link
Contributor Author

cpcloud commented Jan 22, 2026

/ok to test

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 22, 2026

Greptile Summary

This PR systematically enables flake8-bugbear lints and fixes all identified issues across 45 files. The changes focus on improving code quality by addressing common Python pitfalls.

Key Changes:

  • Configuration: Enabled flake8-bugbear lints with selective ignores (B028, B904, B905, B019) and per-file ignores for test files (B007, B018, B023)
  • Mutable default arguments (B006): Fixed all instances of mutable defaults (list=[], dict={}) by replacing with None or immutable types (tuple=())
  • Unnecessary getattr/setattr (B009/B010): Replaced getattr(obj, "attr") with direct attribute access obj.attr and removed unnecessary setattr calls
  • Loop variable issues (B007/B023): Fixed unused loop variables with underscore and resolved function-in-loop closures by passing variables as parameters
  • Empty pass statements (B027): Removed empty pass from abstract methods that don't need implementation
  • Code style improvements: Converted loops to comprehensions/generators where appropriate, changed lists to sets for membership checks

Impact:
All changes are non-functional improvements that maintain existing behavior while following Python best practices. The fixes address potential bugs (mutable defaults, closure issues) and improve code readability and performance (direct attribute access, appropriate data structures).

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • All changes are automated lint fixes following established Python best practices. The fixes address real code quality issues (mutable defaults, closure bugs) without changing functionality. Changes are well-tested across 45 files with consistent patterns and appropriate use of noqa comments where intentional.
  • No files require special attention

Important Files Changed

Filename Overview
pyproject.toml Enabled flake8-bugbear lints with specific rules ignored and reformatted for consistency
pixi.toml Added ruff to dev environment and reformatted task configuration
numba_cuda/numba/cuda/decorators.py Changed mutable default argument from list to tuple in jit decorator (B006)
numba_cuda/numba/cuda/extending.py Fixed mutable default dict argument in overload function (B006)
numba_cuda/numba/cuda/deviceufunc.py Fixed mutable defaults, replaced getattr with direct access, improved f-string formatting
numba_cuda/numba/cuda/core/interpreter.py Fixed loop variable closure issue by passing block as parameter (B023), added noqa for intentional unused loop var
numba_cuda/numba/cuda/core/bytecode.py Replaced loop with list comprehension to avoid unused loop variable (B007)
numba_cuda/numba/cuda/core/ir.py Fixed loop variable closure (B023), optimized count_spaces with generator, changed list to set for membership checks
numba_cuda/numba/cuda/typing/templates.py Replaced unnecessary getattr with direct attribute access (B009)
numba_cuda/numba/cuda/np/arrayobj.py Replaced unused loop variables with underscore, removed unnecessary setattr (B010)

@cpcloud cpcloud enabled auto-merge (squash) January 22, 2026 16:30
@cpcloud cpcloud merged commit b389660 into NVIDIA:main Jan 22, 2026
105 checks passed
@cpcloud cpcloud deleted the flake8-bugbear branch January 23, 2026 16:34
gmarkall added a commit to gmarkall/numba-cuda that referenced this pull request Jan 27, 2026
- Add Python 3.14 to the wheel publishing matrix (NVIDIA#750)
- feat: swap out internal device array usage with `StridedMemoryView` (NVIDIA#703)
- Fix max block size computation in `forall` (NVIDIA#744)
- Fix prologue debug line info pointing to decorator instead of def line (NVIDIA#746)
- Fix kernel return type in DISubroutineType debug metadata (NVIDIA#745)
- Fix missing line info in Jupyter notebooks (NVIDIA#742)
- Fix: Pass correct flags to linker when debugging in the presence of LTOIR code (NVIDIA#698)
- chore(deps): add cuda-pathfinder to pixi deps (NVIDIA#741)
- fix: enable flake8-bugbear lints and fix found problems (NVIDIA#708)
- fix: Fix race condition in CUDA Simulator (NVIDIA#690)
- ci: run tests in parallel (NVIDIA#740)
- feat: users can pass `shared_memory_carveout` to @cuda.jit (NVIDIA#642)
- Fix compatibility with NumPy 2.4: np.trapz and np.in1d removed (NVIDIA#739)
- Pass the -numba-debug flag to libnvvm (NVIDIA#681)
- ci: remove rapids containers from conda ci (NVIDIA#737)
- Use `pathfinder` for dynamic libraries (NVIDIA#308)
- CI: Add CUDA 13.1 testing support (NVIDIA#705)
- Adding `pixi run test` and `pixi run test-par` support (NVIDIA#724)
- Disable per-PR nvmath tests + follow same test practice (NVIDIA#723)
- chore(deps): regenerate pixi lockfile (NVIDIA#722)
- Fix DISubprogram line number to point to function definition line (NVIDIA#695)
- revert: chore(dev): build pixi using rattler (NVIDIA#713) (NVIDIA#719)
- [feat] Initial version of the Numba CUDA GDB pretty-printer (NVIDIA#692)
- chore(dev): build pixi using rattler (NVIDIA#713)
- build(deps): bump the actions-monthly group across 1 directory with 8 updates (NVIDIA#704)
@gmarkall gmarkall mentioned this pull request Jan 27, 2026
kkraus14 pushed a commit that referenced this pull request Jan 28, 2026
- Add Python 3.14 to the wheel publishing matrix (#750)
- feat: swap out internal device array usage with `StridedMemoryView`
(#703)
- Fix max block size computation in `forall` (#744)
- Fix prologue debug line info pointing to decorator instead of def line
(#746)
- Fix kernel return type in DISubroutineType debug metadata (#745)
- Fix missing line info in Jupyter notebooks (#742)
- Fix: Pass correct flags to linker when debugging in the presence of
LTOIR code (#698)
- chore(deps): add cuda-pathfinder to pixi deps (#741)
- fix: enable flake8-bugbear lints and fix found problems (#708)
- fix: Fix race condition in CUDA Simulator (#690)
- ci: run tests in parallel (#740)
- feat: users can pass `shared_memory_carveout` to @cuda.jit (#642)
- Fix compatibility with NumPy 2.4: np.trapz and np.in1d removed (#739)
- Pass the -numba-debug flag to libnvvm (#681)
- ci: remove rapids containers from conda ci (#737)
- Use `pathfinder` for dynamic libraries (#308)
- CI: Add CUDA 13.1 testing support (#705)
- Adding `pixi run test` and `pixi run test-par` support (#724)
- Disable per-PR nvmath tests + follow same test practice (#723)
- chore(deps): regenerate pixi lockfile (#722)
- Fix DISubprogram line number to point to function definition line
(#695)
- revert: chore(dev): build pixi using rattler (#713) (#719)
- [feat] Initial version of the Numba CUDA GDB pretty-printer (#692)
- chore(dev): build pixi using rattler (#713)
- build(deps): bump the actions-monthly group across 1 directory with 8
updates (#704)

<!--

Thank you for contributing to numba-cuda :)

Here are some guidelines to help the review process go smoothly.

1. Please write a description in this text box of the changes that are
being
   made.

2. Please ensure that you have written units tests for the changes
made/features
   added.

3. If you are closing an issue please use one of the automatic closing
words as
noted here:
https://help.github.com/articles/closing-issues-using-keywords/

4. If your pull request is not ready for review but you want to make use
of the
continuous integration testing facilities please label it with `[WIP]`.

5. If your pull request is ready to be reviewed without requiring
additional
work on top of it, then remove the `[WIP]` label (if present) and
replace
it with `[REVIEW]`. If assistance is required to complete the
functionality,
for example when the C/C++ code of a feature is complete but Python
bindings
are still required, then add the label `[HELP-REQ]` so that others can
triage
and assist. The additional changes then can be implemented on top of the
same PR. If the assistance is done by members of the rapidsAI team, then
no
additional actions are required by the creator of the original PR for
this,
otherwise the original author of the PR needs to give permission to the
person(s) assisting to commit to their personal fork of the project. If
that
doesn't happen then a new PR based on the code of the original PR can be
opened by the person assisting, which then will be the PR that will be
   merged.

6. Once all work has been done and review has taken place please do not
add
features or make changes out of the scope of those requested by the
reviewer
(doing this just add delays as already reviewed code ends up having to
be
re-reviewed/it is hard to tell what is new etc!). Further, please do not
rebase your branch on main/force push/rewrite history, doing any of
these
   causes the context of any comments made by reviewers to be lost. If
   conflicts occur against main they should be resolved by merging main
   into the branch used for making the pull request.

Many thanks in advance for your cooperation!

-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants