Is it bad practice to use a built-in function name as an attribute or method identifier?

max picture max · Feb 2, 2012 · Viewed 15.9k times · Source

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?

Answer

Raymond Hettinger picture Raymond Hettinger · Feb 2, 2012

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.