My question arises from this question, in which a user got himself confused by unknowingly rebinding the built-in global set
. Is there a straightforward way to get python to warn you when you attempt to override a built-in?
I'm thinking more specifically of Mathematica. In Mathematica all built-ins have attribute Protected
. If you try to redefine Set
, it will tell you that Set
is Protected
and leave it unchanged, possibly saving you from massive confusion later on when things that ought to work stop doing so for no obvious reason. If you really seriously want to redefine Set
you can still do it -- you just have to Unprotect
it first. And you can Protect
your own symbols, too, to protect them from accidental redefinition.
Perhaps experienced pythoners don't need this, but it would be nice if there were something like this for newbies like me. (Come to think of it, I've been programming Mathematica for 15 years and Protected
still occasionally saves my bacon.)
Use http://www.pylint.org/
def set():
pass
Will generate this warning:
[W0622, set] Redefining built-in 'set'
You can run it over your files after you write them, or use it in e.g. Vim as you go. Most IDE's will also generate this sort of information
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