Skip to content
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

Add private function calls check to make sure there isn't one being called outside of the module it was defined #9138

Closed
Eric-Mendes opened this issue Dec 14, 2023 · 4 comments · Fixed by #5920
Labels
question Asking for support or clarification

Comments

@Eric-Mendes
Copy link

I have drafted a pre-commit hook to make sure there isn't a private function being called outside of the module it was defined. Would it make sense as an optional linting rule? If so I'd be happy to contribute with code.

@charliermarsh
Copy link
Member

Is this similar to private-member-access?

@charliermarsh charliermarsh added the question Asking for support or clarification label Dec 15, 2023
@Eric-Mendes
Copy link
Author

Perhaps it could be an extension to that rule, @charliermarsh. My code doesn't check for class private member access. It checks for module private member access. Here's an example of something that should raise an exception:

# a.py
def _foo(*args, **kwargs):
    return "Hello World"
# b.py
import a

print(a._foo())  # Raises an exception
# c.py
from a import _foo

print(_foo())  # Also raises an exception

Have I misunderstood the rule you've mentioned, or am I really onto something here?

@charliermarsh
Copy link
Member

I believe this would be closed by #5920.

@Eric-Mendes
Copy link
Author

Indeed, @charliermarsh. Thanks for pointing that out, I didn't see that issue before.

charliermarsh pushed a commit that referenced this issue Jan 16, 2024
## Summary

Implements [`import-private-name`
(`C2701`)](https://pylint.pycqa.org/en/latest/user_guide/messages/convention/import-private-name.html)
as `import-private-name` (`PLC2701`). Includes documentation.

Related to #970.

Closes #9138.

### PEP 420 namespace package limitation

`checker.module_path` doesn't seem to support automatic detection of
namespace packages (PEP 420). This leads to 'false' positives (Pylint
allows both).

Currently, for this to work like Pylint, users would have to [manually
input known namespace
packages](https://beta.ruff.rs/docs/settings/#namespace-packages).

## Test Plan

`cargo test`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants