-
Notifications
You must be signed in to change notification settings - Fork 55
fix: enable flake8-bugbear lints and fix found problems #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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. |
|
/ok to test |
|
Actually a decent amount of unnecessary API calls happening in these modules, mostly |
There was a problem hiding this 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 addingnoqacomments where the variable is used after the loop - B009/B010: Replaced
getattr()andsetattr()with direct attribute access where safe - B004: Replaced
hasattr(value, "__call__")withcallable(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) |
There was a problem hiding this 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{}toNonein 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()andsetattr()calls (B009, B010) - Using direct attribute access - Improved code efficiency - Changed list to set for membership checks, used generator expressions
- Added strategic
noqacomments where lint warnings are intentional (e.g., B018 for side-effect attribute access in cloudpickle) - Removed dead test code - Deleted already-skipped
TestFailingStreamclass
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 |
|
/ok to test |
There was a problem hiding this 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.tomlwith specific exceptions for problematic rules (B028, B904, B905, B019) and test files (B007, B018, B023) - Fixed mutable default arguments (B006) by replacing
{}withNoneand[]with()in function signatures acrossextending.py,decorators.py,base.py,deviceufunc.py, andtest_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 intemplates.py - Fixed
setattr()usage (B010) by using direct assignment inarrayobj.py - Fixed function-in-loop closure issue (B023) in
interpreter.pyby moving nested function outside loop and passing required parameters - Added
# noqacomments where violations are intentional (e.g., checkingcell_contentsfor 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
# noqacomments 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) |
| assert len(args) == arity | ||
| assert len(sig.args) == arity |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
6288559 to
3194144
Compare
|
/ok to test |
Greptile SummaryThis 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:
Impact: Confidence Score: 5/5
Important Files Changed
|
- 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)
- 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! -->
Enable
flake8-bugbearruff lints and fix problems.