I just got bit by a bug that would have been prevented if list
were a reserved word in Python. (Dumbery on my part, to be sure.)
So why isn't list (or dict or float or any of the types) a reserved word? It seems easier to add an interpreter error than to try and remember a rule.
(I also know Eclipse/PyDev has a setting that will remind you of this rule, which can be useful.)
Only keywords are reserved.
list
is not a keyword but a built-in type, as are str
, set
, dict
, unicode
, int
, float
, etc.
There is no point in reserving each and every possible built-in type; python is a dynamic language and if you want to replace the built-in types with a local name that shadows it, you should be able to.
Think of list
and the other types as a pre-imported library of object types; you wouldn't expect defaultdict
from collections
to be reserved either?
Use a static code analyzer to catch errors like these; most IDEs let you integrate one with ease.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With