From: Ryan Davis Date: 2010-11-10T09:24:26+09:00 Subject: Re: Analyzer for errors in code ? On Nov 9, 2010, at 14:56 , David Unric wrote: > Unfortunately none of above mentioned or linked tools detected the use > of unassigned variable. For an illustration what does pylint for the > equivalent code in python: > > _____ snip ________________________________________ > import sys > > if __name__ == "__main__": > my_msg = 'Hello' > if sys.argv[-1] == 'doit': > print mymsg > else: > print 'Nope' > > ~$ pylint -E test.py > No config file found, using default configuration > ************* Module test > E: 6: Undefined variable 'mymsg' In python, 'mymsg' _has_ to be a variable. This isn't true in ruby. It can be a variable OR a method call. In the case of the latter, we don't know if it is valid or not without evaluating. in ruby, 'def x; mymsg; end' (the most boiled down version of your example) looks like this internally: % echo 'def x; mymsg; end' | parse_tree_show s(:defn, :x, s(:args), s(:scope, s(:block, s(:call, nil, :mymsg, s(:arglist))))) Ruby parsed the code and decided that mymsg must be a method call. It is determined at runtime (since everything is late bound) who (if anyone) implemented the method and if not, it goes to method_missing. Python simply doesn't have this flexibility. 'x' is a variable and 'x()' is a call. AFAIK, there is no "__" hook equivalent to method_missing in python... But it has been a while for me.