1.1 --- a/micropython/inspect.py Wed Nov 21 01:30:12 2007 +0100
1.2 +++ b/micropython/inspect.py Tue Dec 11 00:55:23 2007 +0100
1.3 @@ -17,6 +17,32 @@
1.4
1.5 You should have received a copy of the GNU General Public License along with
1.6 this program. If not, see <http://www.gnu.org/licenses/>.
1.7 +
1.8 +--------
1.9 +
1.10 +The central classes in this module are the following:
1.11 +
1.12 + * Class
1.13 + * Function
1.14 + * Module
1.15 + * InspectedModule (derived from Module)
1.16 +
1.17 +All of the above support the Naming interface either explicitly or through
1.18 +general conformance, meaning that all can be asked to provide their 'full_name'
1.19 +using the method of that name.
1.20 +
1.21 +Additionally, all of the above also support a dictionary interface in order to
1.22 +access names within their defined scopes. Specific methods also exist in order
1.23 +to distinguish between certain kinds of attributes:
1.24 +
1.25 + * Class: (class|all_class|instance|all)_attributes
1.26 + * Function: parameters, locals
1.27 + * Module: module_attributes
1.28 +
1.29 +These specific methods are useful in certain situations.
1.30 +
1.31 +The above classes also provide a 'node' attribute, indicating the AST node where
1.32 +each such object is defined.
1.33 """
1.34
1.35 import compiler.ast
1.36 @@ -332,6 +358,8 @@
1.37
1.38 class Module(NamespaceDict):
1.39
1.40 + "An inspected module's core details."
1.41 +
1.42 def __init__(self, name):
1.43 NamespaceDict.__init__(self)
1.44 self.name = name
1.45 @@ -350,6 +378,10 @@
1.46 self.location = None
1.47 self.code_location = None
1.48
1.49 + # Original location details.
1.50 +
1.51 + self.node = None
1.52 +
1.53 def full_name(self):
1.54 return self.name
1.55
1.56 @@ -380,7 +412,10 @@
1.57
1.58 class InspectedModule(ASTVisitor, Module):
1.59
1.60 - "An inspected module."
1.61 + """
1.62 + An inspected module, providing core details via the Module superclass, but
1.63 + capable of being used as an AST visitor.
1.64 + """
1.65
1.66 def __init__(self, name, importer=None):
1.67 ASTVisitor.__init__(self)
1.68 @@ -411,7 +446,7 @@
1.69
1.70 "Process the given 'module'."
1.71
1.72 - self.module = module
1.73 + self.node = self.module = module
1.74 processed = self.dispatch(module)
1.75 if self.has_key("__all__"):
1.76 all = self["__all__"]