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

N806 - false positive for class #89

Open
PaszaVonPomiot opened this issue Jan 4, 2019 · 4 comments
Open

N806 - false positive for class #89

PaszaVonPomiot opened this issue Jan 4, 2019 · 4 comments

Comments

@PaszaVonPomiot
Copy link

Regarding N806 (variable in function should be lowercase)
In Django I have a class that I create alias for which should be uppercase because it's still a class:

if a=1:
    AliasMyClass = MyClass1
if a=2:
    AliasMyClass = MyClass2

AliasMyClass.objects.create......

So it's clearly a false positive to me. Can you fix it?

@jparise
Copy link
Member

jparise commented Apr 12, 2020

We could consider changing the rule to allow a mixed-case variable name (left-hand side) if its being assigned to a mixed-case name (right-hand side).

@sigmavirus24
Copy link
Member

@jparise I'm not confident in how necessary or common this is. It hasn't seen a lot of support or requests for help and I'm not certain relaxing this with no way to constrict it is the right choice.

@jparise
Copy link
Member

jparise commented Apr 12, 2020

@sigmavirus24 I think that's a fine position to take, too. I imagine these cases are rare in practice, so it's reasonable to ask users to annotate them with # noqa.

@Asday
Copy link

Asday commented Sep 26, 2022

ModelName = apps.get_model("app_name.ModelName") and ModelNameFormSet = modelformset_factory(ModelName, ...) are perfectly sane patterns in Django projects. I'm not particularly familiar with AST inner workings, so I don't imagine it can be done thanks to Python's typing, but if a variable holds a type instance it shouldn't trigger N806.

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

No branches or pull requests

4 participants