pep8-naming icon indicating copy to clipboard operation
pep8-naming copied to clipboard

N806 - false positive for class

Open PaszaVonPomiot opened this issue 7 years ago • 4 comments

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?

PaszaVonPomiot avatar Jan 04 '19 18:01 PaszaVonPomiot

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).

jparise avatar Apr 12 '20 01:04 jparise

@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.

sigmavirus24 avatar Apr 12 '20 15:04 sigmavirus24

@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.

jparise avatar Apr 12 '20 18:04 jparise

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.

Asday avatar Sep 26 '22 05:09 Asday