Repository navigation
Ruff PR auto-format - #6422
Ruff PR auto-format#6422
Conversation
WalkthroughThe PR systematically reorganizes imports across 50+ files, including reordering import statements, consolidating imports, and adjusting whitespace. Most changes are cosmetic; two files include functional modifications: removal of a deque initialization and loop logic adjustments. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~50 minutes The vast majority of changes are homogeneous (import reordering and formatting), which reduces per-file cognitive load. However, the sheer volume (50+ files) requires systematic verification. Pay special attention to:
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Code has been automatically formatted The code in this PR has been formatted using git pull origin ensure-ruff-auto-format |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
extra_tests/snippets/stdlib_io.py (1)
2-3: Consider removing unused imports.The import reordering looks good, but
BytesIOandStringIOappear to be unused in this file. Consider removing them to keep imports clean.Apply this diff to remove unused imports:
-from io import BufferedReader, BytesIO, FileIO, StringIO +from io import BufferedReader, FileIOBased on learnings, ruff is used for linting Python code.
extra_tests/snippets/stdlib_ctypes.py (1)
1-32: Remove unused import_FUNCFLAG_PYTHONAPI.Static analysis confirms that
_FUNCFLAG_PYTHONAPIat line 25 is imported but never used in the file. Remove the import statement to clean up the code.extra_tests/snippets/forbidden_instantiation.py (1)
1-16: Remove unused importTypefrom typing.Verified:
Typefromtyping(line 15) is imported but never used in the file. The code uses lowercasetypas a parameter name, not theTypeannotation. Ruff F401 check confirms this as a fixable issue.However, note that per coding guidelines, Python code should not be edited; bug fixes should be made through Rust code modifications only. If this test file needs cleanup, clarify whether test files are exempt from this restriction.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (48)
crates/sre_engine/generate_tests.py(1 hunks)crawl_sourcecode.py(1 hunks)extra_tests/custom_text_test_runner.py(1 hunks)extra_tests/jsontests.py(1 hunks)extra_tests/snippets/builtin_all.py(1 hunks)extra_tests/snippets/builtin_any.py(1 hunks)extra_tests/snippets/builtin_bytearray.py(1 hunks)extra_tests/snippets/builtin_exceptions.py(1 hunks)extra_tests/snippets/builtin_pow.py(1 hunks)extra_tests/snippets/builtin_print.py(1 hunks)extra_tests/snippets/builtin_str.py(1 hunks)extra_tests/snippets/dir_module/__init__.py(1 hunks)extra_tests/snippets/forbidden_instantiation.py(1 hunks)extra_tests/snippets/import.py(1 hunks)extra_tests/snippets/protocol_index_bad.py(1 hunks)extra_tests/snippets/stdlib_array.py(1 hunks)extra_tests/snippets/stdlib_binascii.py(1 hunks)extra_tests/snippets/stdlib_collections.py(0 hunks)extra_tests/snippets/stdlib_collections_deque.py(1 hunks)extra_tests/snippets/stdlib_csv.py(1 hunks)extra_tests/snippets/stdlib_ctypes.py(3 hunks)extra_tests/snippets/stdlib_datetime.py(1 hunks)extra_tests/snippets/stdlib_dir_module.py(1 hunks)extra_tests/snippets/stdlib_functools.py(1 hunks)extra_tests/snippets/stdlib_io.py(1 hunks)extra_tests/snippets/stdlib_itertools.py(1 hunks)extra_tests/snippets/stdlib_json.py(1 hunks)extra_tests/snippets/stdlib_marshal.py(1 hunks)extra_tests/snippets/stdlib_math.py(1 hunks)extra_tests/snippets/stdlib_os.py(1 hunks)extra_tests/snippets/stdlib_pwd.py(1 hunks)extra_tests/snippets/stdlib_select.py(1 hunks)extra_tests/snippets/stdlib_signal.py(1 hunks)extra_tests/snippets/stdlib_socket.py(1 hunks)extra_tests/snippets/stdlib_string.py(0 hunks)extra_tests/snippets/stdlib_struct.py(1 hunks)extra_tests/snippets/stdlib_subprocess.py(1 hunks)extra_tests/snippets/stdlib_sys.py(1 hunks)extra_tests/snippets/stdlib_weakref.py(1 hunks)extra_tests/snippets/stdlib_zlib.py(1 hunks)extra_tests/test_snippets.py(1 hunks)scripts/generate_checklist.py(1 hunks)scripts/make_ssl_data_rs.py(0 hunks)wasm/demo/snippets/asyncbrowser.py(1 hunks)wasm/demo/snippets/import_pypi.py(1 hunks)wasm/example/src/main.py(1 hunks)wasm/tests/conftest.py(2 hunks)whats_left.py(2 hunks)
💤 Files with no reviewable changes (3)
- scripts/make_ssl_data_rs.py
- extra_tests/snippets/stdlib_collections.py
- extra_tests/snippets/stdlib_string.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.py: In most cases, Python code should not be edited; bug fixes should be made through Rust code modifications only
Follow PEP 8 style for custom Python code
Use ruff for linting Python code
Files:
extra_tests/snippets/stdlib_sys.pyextra_tests/snippets/stdlib_weakref.pyextra_tests/snippets/stdlib_socket.pyextra_tests/snippets/stdlib_os.pycrawl_sourcecode.pyextra_tests/snippets/stdlib_json.pyextra_tests/snippets/builtin_str.pyextra_tests/snippets/builtin_exceptions.pyextra_tests/snippets/stdlib_zlib.pyextra_tests/snippets/stdlib_functools.pyextra_tests/snippets/stdlib_math.pyextra_tests/snippets/stdlib_itertools.pyextra_tests/snippets/stdlib_subprocess.pyextra_tests/snippets/dir_module/__init__.pyextra_tests/snippets/stdlib_datetime.pyextra_tests/snippets/stdlib_ctypes.pyextra_tests/custom_text_test_runner.pyextra_tests/snippets/builtin_print.pyextra_tests/test_snippets.pyextra_tests/snippets/protocol_index_bad.pyextra_tests/snippets/stdlib_struct.pywhats_left.pywasm/example/src/main.pyextra_tests/snippets/stdlib_io.pyextra_tests/snippets/import.pyextra_tests/snippets/builtin_pow.pyscripts/generate_checklist.pyextra_tests/snippets/stdlib_csv.pyextra_tests/snippets/stdlib_marshal.pyextra_tests/jsontests.pycrates/sre_engine/generate_tests.pyextra_tests/snippets/stdlib_array.pyextra_tests/snippets/stdlib_binascii.pywasm/demo/snippets/import_pypi.pyextra_tests/snippets/builtin_bytearray.pyextra_tests/snippets/builtin_all.pywasm/demo/snippets/asyncbrowser.pyextra_tests/snippets/stdlib_dir_module.pyextra_tests/snippets/stdlib_signal.pyextra_tests/snippets/stdlib_select.pyextra_tests/snippets/stdlib_pwd.pyextra_tests/snippets/forbidden_instantiation.pyextra_tests/snippets/stdlib_collections_deque.pyextra_tests/snippets/builtin_any.pywasm/tests/conftest.py
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-29T12:17:28.606Z
Learning: Applies to **/*.py : Use ruff for linting Python code
📚 Learning: 2025-11-29T12:17:28.606Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-29T12:17:28.606Z
Learning: Applies to Lib/test/**/*.py : NEVER modify test assertions, test logic, or test data in test files
Applied to files:
extra_tests/snippets/protocol_index_bad.pyextra_tests/snippets/stdlib_struct.pyextra_tests/snippets/stdlib_csv.pyextra_tests/snippets/stdlib_array.pyextra_tests/snippets/builtin_all.pyextra_tests/snippets/builtin_any.py
📚 Learning: 2025-11-29T12:17:28.606Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-29T12:17:28.606Z
Learning: Use `cargo run -- script.py` instead of the standard `python` command to run and test Python code with RustPython
Applied to files:
whats_left.py
🧬 Code graph analysis (13)
extra_tests/snippets/stdlib_json.py (1)
extra_tests/snippets/testutils.py (1)
assert_raises(5-12)
extra_tests/snippets/builtin_str.py (1)
extra_tests/snippets/testutils.py (3)
AssertRaises(15-32)assert_raises(5-12)skip_if_unsupported(81-95)
extra_tests/snippets/stdlib_datetime.py (1)
extra_tests/snippets/testutils.py (6)
assert_equal(59-60)assert_false(67-68)assert_in(77-78)assert_isinstance(71-74)assert_raises(5-12)assert_true(63-64)
extra_tests/snippets/builtin_print.py (1)
extra_tests/snippets/testutils.py (1)
assert_raises(5-12)
extra_tests/snippets/stdlib_struct.py (1)
extra_tests/snippets/testutils.py (1)
assert_raises(5-12)
wasm/example/src/main.py (2)
crates/wasm/Lib/browser.py (1)
alert(50-53)crates/wasm/src/browser_module.rs (1)
fetch(59-116)
extra_tests/snippets/builtin_pow.py (1)
extra_tests/snippets/testutils.py (2)
assert_equal(59-60)assert_raises(5-12)
extra_tests/snippets/stdlib_csv.py (1)
extra_tests/snippets/testutils.py (1)
assert_raises(5-12)
extra_tests/snippets/stdlib_binascii.py (1)
extra_tests/snippets/testutils.py (2)
assert_equal(59-60)assert_raises(5-12)
extra_tests/snippets/builtin_bytearray.py (1)
extra_tests/snippets/testutils.py (1)
assert_raises(5-12)
extra_tests/snippets/stdlib_select.py (1)
extra_tests/snippets/testutils.py (1)
assert_raises(5-12)
extra_tests/snippets/stdlib_pwd.py (1)
extra_tests/snippets/testutils.py (1)
assert_raises(5-12)
extra_tests/snippets/builtin_any.py (2)
extra_tests/snippets/testutils.py (2)
TestFailingBool(35-37)assert_raises(5-12)extra_tests/snippets/stdlib_functools.py (1)
TestFailingIter(49-51)
🪛 Flake8 (7.3.0)
extra_tests/snippets/dir_module/__init__.py
[error] 2-2: '.relative.value' imported but unused
(F401)
extra_tests/snippets/stdlib_datetime.py
[error] 11-11: 'datetime.MAXYEAR' imported but unused
(F401)
[error] 11-11: 'datetime.MINYEAR' imported but unused
(F401)
[error] 11-11: 'datetime.timezone' imported but unused
(F401)
[error] 12-12: 'operator.eq' imported but unused
(F401)
[error] 12-12: 'operator.floordiv' imported but unused
(F401)
[error] 12-12: 'operator.ge' imported but unused
(F401)
[error] 12-12: 'operator.gt' imported but unused
(F401)
[error] 12-12: 'operator.le' imported but unused
(F401)
[error] 12-12: 'operator.lt' imported but unused
(F401)
[error] 12-12: 'operator.mod' imported but unused
(F401)
[error] 12-12: 'operator.truediv' imported but unused
(F401)
extra_tests/snippets/stdlib_ctypes.py
[error] 24-24: '_ctypes.FUNCFLAG_PYTHONAPI as _FUNCFLAG_PYTHONAPI' imported but unused
(F401)
extra_tests/snippets/stdlib_io.py
[error] 2-2: 'io.BytesIO' imported but unused
(F401)
[error] 2-2: 'io.StringIO' imported but unused
(F401)
extra_tests/snippets/import.py
[error] 4-4: 'from import_star import *' used; unable to detect undefined names
(F403)
extra_tests/snippets/stdlib_dir_module.py
[error] 2-2: 'testutils.assert_equal' imported but unused
(F401)
extra_tests/snippets/forbidden_instantiation.py
[error] 15-15: 'typing.Type' imported but unused
(F401)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Check Rust code with clippy
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
🔇 Additional comments (35)
extra_tests/snippets/stdlib_sys.py (1)
1-3: Import reorder is safe and ruff-aligned. The new ordering (os,subprocess,sys) is behavior-preserving in this snippet and matches typical ruff/isort sorting.extra_tests/snippets/stdlib_zlib.py (1)
1-3: Formatting-only change is fine (blank line after import).
This aligns with PEP 8 / ruff formatting conventions and shouldn’t affect runtime behavior.extra_tests/snippets/protocol_index_bad.py (1)
4-6: Import reordering looks good—ruff-compliant formatting.The import reorganization follows PEP 8 conventions: standard library imports (
array) come first, followed by a blank line, then local imports (testutils). This is consistent with ruff's import-sorting expectations and preserves all test logic and assertions.extra_tests/snippets/stdlib_functools.py (1)
1-3: Import formatting aligns with PEP 8 and ruff standards.The addition of a blank line between imports from different modules follows PEP 8 conventions and ruff's auto-formatting rules. This change improves code organization without affecting runtime behavior.
extra_tests/snippets/stdlib_collections_deque.py (1)
4-5: LGTM! Import order now follows PEP 8 guidelines.The reorganization correctly groups standard library imports (
collections,typing) before local imports (testutils), which aligns with PEP 8 and ruff formatting standards. As per coding guidelines, this project uses ruff for linting Python code.extra_tests/snippets/import.py (1)
2-7: LGTM! Import reorganization aligns with testing objectives.The import statements have been reformatted and organized. While there are redundant imports (e.g.,
funcandother_funcimported multiple times with different aliases), this is intentional for a test file that validates various import mechanisms. The assertions throughout the file (lines 9-20) verify each import style works correctly.The static analysis warning about the star import (line 4) can be safely ignored—it's deliberately testing star import functionality (validated on line 22 with
STAR_IMPORT).crawl_sourcecode.py (1)
13-14: LGTM! Import reordering aligns with ruff formatting standards.The imports have been reordered alphabetically, which is consistent with the PR's objective to apply ruff auto-formatting across the codebase.
Based on coding guidelines, this aligns with the project standard to use ruff for linting Python code.
extra_tests/snippets/stdlib_marshal.py (1)
2-2: LGTM! Import ordering follows ruff standards.The unittest import has been correctly positioned after the marshal import, following alphabetical ordering conventions.
Based on coding guidelines, this change aligns with using ruff for Python code linting.
extra_tests/snippets/builtin_exceptions.py (1)
3-3: LGTM! Import reordering follows ruff conventions.The platform import has been repositioned to maintain alphabetical ordering of standard library imports.
Based on coding guidelines, this aligns with the project's use of ruff for linting.
extra_tests/snippets/stdlib_socket.py (1)
3-4: LGTM! Import organization follows ruff formatting standards.The socket import has been correctly positioned after os (alphabetical order), and the blank line properly separates standard library imports from subsequent from-imports, following PEP 8 conventions.
Based on coding guidelines, this aligns with using ruff for Python code linting.
crates/sre_engine/generate_tests.py (1)
1-1: LGTM! Import consolidation and reordering improves code organization.The json import has been consolidated at the top level (removing duplication), and the Path import has been repositioned, both following alphabetical ordering conventions enforced by ruff.
Based on coding guidelines, this aligns with using ruff for linting Python code.
Also applies to: 5-5
scripts/generate_checklist.py (1)
11-11: LGTM! Import reordering follows ruff standards.The typing import has been correctly repositioned after warnings to maintain alphabetical ordering of imports.
Based on coding guidelines, this change aligns with using ruff for Python code linting.
extra_tests/snippets/stdlib_itertools.py (1)
2-2: LGTM! Import ordering follows ruff conventions.The pickle import has been repositioned after itertools to maintain alphabetical ordering of standard library imports.
Based on coding guidelines, this aligns with using ruff for Python code linting.
extra_tests/snippets/stdlib_subprocess.py (1)
1-1: LGTM! Import organization follows ruff formatting standards.The imports have been reordered alphabetically with signal positioned at the top, followed by subprocess, sys, and time. This ensures the signal module is properly imported before its usage in the Unix-specific assertions (lines 56, 64).
Based on coding guidelines, this aligns with using ruff for linting Python code.
Also applies to: 4-4
extra_tests/snippets/stdlib_struct.py (1)
3-4: Import regrouping is fine (stdlib first, then local testutils).
No behavioral impact;assert_raisesremains used.extra_tests/snippets/stdlib_select.py (1)
3-6: Import order/grouping looks correct;sysusage matches platform checks.extra_tests/snippets/stdlib_weakref.py (1)
1-2: LGTM: import reorder is behavior-preserving and both symbols are used.extra_tests/snippets/builtin_str.py (1)
1-1: OK: testutils import reorder is cosmetic and keeps same symbols.extra_tests/snippets/stdlib_math.py (1)
1-3: Import grouping/spacing looks good; no behavioral change.extra_tests/snippets/builtin_all.py (1)
1-1: Good consolidation of testutils imports; behavior unchanged.extra_tests/snippets/stdlib_json.py (1)
2-5: Import reorder/grouping is fine and remains consistent with usage.extra_tests/jsontests.py (1)
1-3: LGTM!The import reorganization is appropriate for a ruff auto-format PR. Moving
import osto the top and adjusting whitespace aligns with standard Python conventions.extra_tests/snippets/stdlib_binascii.py (1)
3-3: LGTM!Alphabetical ordering of imports is consistent with ruff formatting standards.
extra_tests/snippets/builtin_any.py (1)
1-1: LGTM!Import consolidation is appropriate for ruff auto-formatting. No test logic has been modified.
wasm/demo/snippets/import_pypi.py (1)
16-16: LGTM!Import reordering has no runtime impact since both imports are completed before usage.
extra_tests/snippets/stdlib_signal.py (1)
3-4: LGTM!Import reordering and blank line adjustment are appropriate for ruff auto-formatting.
extra_tests/snippets/builtin_bytearray.py (1)
4-5: LGTM!Properly groups standard library imports before local imports, consistent with PEP 8 and ruff formatting conventions.
extra_tests/custom_text_test_runner.py (1)
28-38: LGTM!Import reorganization consolidates standard library imports and follows ruff formatting conventions. No functional changes.
wasm/example/src/main.py (1)
1-1: LGTM! Import alphabetization.The import reordering is consistent with ruff's auto-formatting rules.
whats_left.py (2)
19-25: LGTM! Import organization.The top-level imports have been alphabetized, which improves consistency.
327-334: LGTM! Function-scoped import organization.The imports within the
compare()function have been alphabetized consistently with the top-level imports.wasm/tests/conftest.py (2)
1-8: LGTM! Top-level import organization.The imports have been alphabetized, which is consistent with ruff formatting.
68-73: LGTM! Selenium import organization.The Selenium-related imports have been reordered while maintaining all necessary symbols (JavascriptException, WebDriverWait, Options).
extra_tests/snippets/stdlib_datetime.py (1)
7-21: LGTM! Import consolidation and alphabetization.The imports have been reorganized and consolidated. While static analysis flags several imports as unused (MAXYEAR, MINYEAR, timezone, operator functions), these are false positives — all flagged imports are used later in this large test file (e.g., MAXYEAR at line 2801, MINYEAR at line 3204, timezone at line 1826, operator functions at line 2497).
extra_tests/snippets/stdlib_pwd.py (1)
9-14: Unable to verify functional changes; file not found in repository.The file
extra_tests/snippets/stdlib_pwd.pycould not be located in the repository to verify whether theassert_raisesimport andfake_name += "1"loop logic were pre-existing or newly added. Without access to git history for this file, the claim that these modifications go beyond auto-formatting cannot be confirmed or refuted.
| from .dir_module_inner import value2 | ||
| from .relative import value |
There was a problem hiding this comment.
Fix lint blocker (F401): mark re-exported import as intentional (or export via __all__).
Flake8 reports Line 2 as unused; if this is a package re-export, annotate it to avoid CI lint failures.
Based on learnings, use ruff for linting Python code.
from .dir_module_inner import value2
-from .relative import value
+from .relative import value # noqa: F401
+
+__all__ = ["value", "value2"]🧰 Tools
🪛 Flake8 (7.3.0)
[error] 1-1: '.dir_module_inner.value2' imported but unused
(F401)
[error] 2-2: '.relative.value' imported but unused
(F401)
🤖 Prompt for AI Agents
extra_tests/snippets/dir_module/__init__.py lines 1-2: Flake8/ruff flags the
import on line 2 as unused (F401) because it's a package re-export; either mark
the re-export as intentional by appending a noqa for F401 to the import
statement or explicitly export the names via an __all__ list. Fix by choosing
one: 1) add the comment "# noqa: F401" to the import of value to silence the
unused-import lint, or 2) add an __all__ = ["value", "value2"] (and keep the
imports) so the module explicitly exports these symbols for re-export.
| from testutils import assert_equal | ||
|
|
||
| import dir_module | ||
| from testutils import assert_equal |
There was a problem hiding this comment.
Remove unused import.
The assert_equal import is not used anywhere in this file, as correctly identified by Flake8.
Apply this diff to remove the unused import:
-from testutils import assert_equal📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| from testutils import assert_equal |
🧰 Tools
🪛 Flake8 (7.3.0)
[error] 2-2: 'testutils.assert_equal' imported but unused
(F401)
🤖 Prompt for AI Agents
In extra_tests/snippets/stdlib_dir_module.py around line 2, the file imports
assert_equal from testutils but that symbol is unused; remove the unused import
line so the file no longer imports assert_equal (delete or comment out the "from
testutils import assert_equal" line) to satisfy Flake8.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.