Determining types of variables and function params by parsing the source code

Stefan Schwarzer sschwarzer at sschwarzer.net
Sat Aug 24 07:00:20 EDT 2002


Stefan Schwarzer wrote:
 > -----
 > # Module a.py
 >
 > _type = int
 >
 > def return_value():
 >     return _type()
 >
 > print return_type()  # gives 0 (int)
 > -----
 >
 > Analyzing module "a" might make you think that return_type returns an
 > int ...
 >
 > -----
 > # Module b.py
 >
 > import a
 >
 > print return_type()  # gives 0 (int)
 > a._type = str
 > print return_type()  # gives '' (str)
 > -----

"return_type" should have been the function "return_value", of course.

Stefan




More information about the Python-list mailing list