ruff
80dbc62a - [`pylint`] Allow dunder submodules and improve diagnostic range (`PLC2701`) (#22804)

Commit
165 days ago
[`pylint`] Allow dunder submodules and improve diagnostic range (`PLC2701`) (#22804) ## Summary This PR addresses two improvements for the `PLC2701` (`import-private-name`) rule: 1. **Excludes dunder submodules**: Specifically handles the false positive where `__main__` was being flagged as a private name import. It now ensures that any segment identified as a "dunder" (starting and ending with `__`) is ignored by the rule. 2. **Improves diagnostic ranges**: Refines the error highlight to be more surgical. Instead of pointing to the end of the import binding, the linter now pinpoint's the exact private segment—whether it's in the module path (e.g., `from pkg._private import func`) or the imported member (e.g., `from pkg import _private`). Closes #22187 ## Test Plan - **Manual Verification**: Verified using a `repro.py` script covering three scenarios: - `from pkg import _private` (Surgical highlight on member) - `from pkg._private import func` (Surgical highlight on module path) - `from pkg.__main__ import func` (Correctly ignored) - **Snapshot Testing**: Updated existing test snapshots in `crates/ruff_linter/src/rules/pylint/snapshots/`. The diffs confirm that diagnostic ranges have shifted from the imported name to the actual private name causing the violation. --------- Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
Author
Parents
Loading