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

N814 false positive: from decimal import Decimal as D #13543

Open
rdaysky opened this issue Sep 28, 2024 · 5 comments
Open

N814 false positive: from decimal import Decimal as D #13543

rdaysky opened this issue Sep 28, 2024 · 5 comments
Labels
help wanted Contributions especially welcome rule Implementing or modifying a lint rule

Comments

@rdaysky
Copy link

rdaysky commented Sep 28, 2024

N814 (camelcase-imported-as-constant) triggers even if the alias is a single uppercase letter in code like

from decimal import Decimal as D
from fractions import Fraction as F

but perhaps it shouldn’t?

@charliermarsh charliermarsh added the bug Something isn't working label Sep 28, 2024
@charliermarsh
Copy link
Member

I tend to agree that we shouldn't flag this.

@charliermarsh charliermarsh added rule Implementing or modifying a lint rule help wanted Contributions especially welcome and removed bug Something isn't working labels Sep 28, 2024
@rdaysky
Copy link
Author

rdaysky commented Sep 28, 2024

It’s also an interesting question whether from collections.abc import AsyncGenerator as AG is acceptable style for a module that defines a lot of them.

@dhruvmanila
Copy link
Member

Did you mean N817 instead of N814? These won't be flagged by the latter as it'll be considered as an acronym for the imported name. See https://play.ruff.rs/9326f4aa-a8bf-47c0-a45f-5b3d04b902c7.

@dhruvmanila
Copy link
Member

You can also use the extend-aliases option here:

[tool.ruff.lint.flake8-import-conventions.extend-aliases]
"collections.abc.AsyncGenerator" = "AG"
"decimal.Decimal" = "D"
"fractions.Fraction" = "F"

@dhruvmanila
Copy link
Member

I think I'd suggest to use the configuration instead of adding special casing for certain imports. What do you think? @rdaysky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions especially welcome rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

3 participants