I know to never use built-in function names as variable identifiers.
But are there any reasons not to use them as attribute or method identifiers?
For example, is it safe to write my_object.id = 5
, or define an instance method dict
in my own class?
It won't confuse the interpreter but it may confuse people reading your code. Unnecessary use of builtin names for attributes and methods should be avoided.
Another ill-effect is that shadowing builtins confuses syntax highlighters in most python-aware editors (vi, emacs, pydev, idle, etc.) Also, some of the lint tools will warn about this practice.