Skip to content

PLC2701 treats os._exit as private, unlike SLF001 #18143

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

Open
dscorbett opened this issue May 16, 2025 · 2 comments · May be fixed by #18166
Open

PLC2701 treats os._exit as private, unlike SLF001 #18143

dscorbett opened this issue May 16, 2025 · 2 comments · May be fixed by #18166
Labels
bug Something isn't working

Comments

@dscorbett
Copy link

Summary

Despite its name, os._exit is not private; see #6483. import-private-name (PLC2701) treats it as private, which is inconsistent with private-member-access (SLF001). The two rules should share the same set of exceptionally non-private module members (which is currently just os._exit).

$ cat >plc2701.py <<'# EOF'
from os import _exit
# EOF

$ ruff --isolated check plc2701.py --preview --select PLC2701 --output-format concise -q
plc2701.py:1:16: PLC2701 Private name import `_exit` from external module `os`

Version

ruff 0.11.10 (b35bf8a 2025-05-15)

@ntBre ntBre added the bug Something isn't working label May 16, 2025
@danparizher
Copy link
Contributor

danparizher commented May 17, 2025

Would the solution here not be as simple as adding this snippet to crates\ruff_linter\src\rules\pylint\rules\import_private_name.rs?:

        if matches!(import_info.qualified_name.segments(), ["os", "_exit"]) {
            continue;
        }

Are there any situations where we would need to expand on this?

@dscorbett
Copy link
Author

That solution could work. There are other underscore-initial public module members in the standard library, though, so the list will probably be expanded at some point.

danparizher added a commit to danparizher/ruff that referenced this issue May 18, 2025
This change updates the PLC2701 rule to correctly identify os._exit as a non-private member, aligning its behavior with the SLF001 rule. Fixes astral-sh#18143
@danparizher danparizher linked a pull request May 18, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants