While others have pointed out that it's bad form to shadow python built-ins, this is only the case when either name a function or function parameter as type
, however -
It should be noted that the python built-in type
is not shadowed in any way if you were to name a class attribute as type
.
Even when referencing your class attribute, it would always be prefixed by the class instance self
or a custom instance variable - and the python built-in would not be hindered.
For example:
Okay:
>>> class SomeClass():
... type = 'foobar'
...
... def someFunction(self):
... return self.type
Not Okay:
>>> def type(): # Overrides python built-in in global scope
... pass
...
>>> def foobar(type):
... return type # Overrides python built-in within func
id
which is even more common. – Tatty