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

Allow banning of certain builtins in "banned-api" #10079

Open
jonathanslenders opened this issue Feb 22, 2024 · 1 comment · May be fixed by #15736
Open

Allow banning of certain builtins in "banned-api" #10079

jonathanslenders opened this issue Feb 22, 2024 · 1 comment · May be fixed by #15736

Comments

@jonathanslenders
Copy link

I'd love to ban usage of certain builtins using the "banned-api" (TID251) rule.
Something like this:

[tool.ruff.lint.flake8-tidy-imports.banned-api]
# Don't use delattr/getattr/setattr -> too dynamic!
"__builtins__.delattr".msg = "Don't use delattr/setattr/getattr."
"__builtins__.setattr".msg = "Don't use delattr/setattr/getattr."
"__builtins__.getattr".msg = "Don't use delattr/setattr/getattr."

# Don't use `@property`, because methods are more flexible and allow access to unbound methods.
"__builtins__.property".msg = "Don't use properties in this part of the code."

# Don't print. Basically the same as the `T` rule.
"__builtins__.print".msg = "Don't use print."

"__builtins__.list".msg = "Use list literal instead."
@KotlinIsland
Copy link
Contributor

I would prefer builtins.eggs over __builtins__.eggs, that's the actual name of the module, and:

As an implementation detail, most modules have the name __builtins__ made available as part of their globals. The value of __builtins__ is normally either this module or the value of this module’s __dict__ attribute. Since this is an implementation detail, it may not be used by alternate implementations of Python.
- https://docs.python.org/3/library/builtins.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants