Bridge
Bridge

Reputation: 229

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

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

Upvotes: 3

Views: 968

Answers (2)

Steven-MSFT
Steven-MSFT

Reputation: 8411

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.

Upvotes: 0

qouify
qouify

Reputation: 3900

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.

Upvotes: 3

Related Questions