Skip to content

[pylint] Allow os._exit imports in import-private-name (PLC2701) - #27738

Merged
ntBre merged 2 commits into
astral-sh:mainfrom
lakshayxi:fix-plc2701-os-exit
Aug 14, 2026
Merged

ntBre merged 2 commits into
astral-sh:mainfrom
lakshayxi:fix-plc2701-os-exit

Conversation

@lakshayxi

Copy link
Copy Markdown
Contributor

Summary

PLC2701 currently reports from os import _exit as a private import, even though os._exit is a documented public API. SLF001 already handles os._exit as an exception to the usual leading-underscore rule.

This change moves that exception into a shared helper so PLC2701 and SLF001 treat os._exit consistently.

Fixes #18143.

Test Plan

  • Added tests for direct and aliased os._exit imports.
  • Added negative cases to make sure _exit from other modules and other private os members are still reported.
  • Added coverage for mixed imports and aliased SLF001 access.
  • Ran the relevant Ruff tests, Clippy, formatting checks, and prek.

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre August 14, 2026 00:04
@ntBre ntBre added the bug An issue describing something that isn't working, or a PR that fixes a bug label Aug 14, 2026

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! This looks good to me, I just had one nit/suggestion about the helper name.

Comment thread crates/ruff_linter/src/rules/pylint/helpers.rs Outdated
@astral-sh-bot

astral-sh-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre
ntBre enabled auto-merge (squash) August 14, 2026 19:23
@ntBre
ntBre merged commit 5226c06 into astral-sh:main Aug 14, 2026
47 checks passed
George-Ogden pushed a commit to George-Ogden/ruff that referenced this pull request Aug 16, 2026
…1`) (astral-sh#27738)

## Summary

`PLC2701` currently reports `from os import _exit` as a private import,
even though `os._exit` is a documented public API. `SLF001` already
handles `os._exit` as an exception to the usual leading-underscore rule.

This change moves that exception into a shared helper so `PLC2701` and
`SLF001` treat `os._exit` consistently.

Fixes astral-sh#18143.

## Test Plan

- Added tests for direct and aliased `os._exit` imports.
- Added negative cases to make sure `_exit` from other modules and other
private `os` members are still reported.
- Added coverage for mixed imports and aliased `SLF001` access.
- Ran the relevant Ruff tests, Clippy, formatting checks, and `prek`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PLC2701 treats os._exit as private, unlike SLF001

2 participants