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.
listis not a keyword but a built-in type, as arestr,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
listand the other types as a pre-imported library of object types; you wouldn’t expectdefaultdictfromcollectionsto be reserved either?Use a static code analyzer to catch errors like these; most IDEs let you integrate one with ease.