Home > Net >  No pylint warning "Redefining built-in" for a class local variable
No pylint warning "Redefining built-in" for a class local variable

Time:10-13

I came across a Django model like this:

class Car(models.Model):
    type = CharField()
    ...

However, pylint does not issue any warnings about redefining the built-in function type. It is only when I move it out of the class to the global scope pylint warns about this, but not within the class. Is this the expected behavior? If so, how can I override it to show warnings within classes or functions as well?

VSCode 1.61.0
Ubuntu 20.04
Python 3.8.10

CodePudding user response:

I would say this is a normal behaviour as you don't hide type here since you need to write something like my_car.type to access the type attribute so there is no risk.

If you still want pylint to warn you about that you can add type to the list bad-names in your pylintrc file. It will raise a C0104: disallowed-name message.

CodePudding user response:

It doesn't matter, even you redefining the built-in functions such as type out of the class to the global scope, you still can access it through builtins.type in Py3 and __builtin__.type in Py2.

  • Related