# HG changeset patch # User Paul Boddie # Date 1282515303 -7200 # Node ID aaf23d3b2bcd4c77c6e07154df4a1bdefbf08198 # Parent 023105a53af2999ef4893e4aefd6dcc64fdaaed4 Ensure attribute collection for all modules, thus making sure that any initialisation code can actually run. Added various method signatures to the builtins. diff -r 023105a53af2 -r aaf23d3b2bcd lib/builtins.py --- a/lib/builtins.py Sun Aug 22 20:35:20 2010 +0200 +++ b/lib/builtins.py Mon Aug 23 00:15:03 2010 +0200 @@ -26,6 +26,7 @@ class basestring(object): def __init__(self, x=None): pass + def __contains__(self, value): pass def __getitem__(self, index): # Note usage. @@ -49,6 +50,9 @@ def __str__(self): pass def __bool__(self): pass def join(self, l): pass + def split(self, s): pass + def startswith(self, s): pass + def endswith(self, s): pass class bool(object): def __bool__(self): pass @@ -71,7 +75,9 @@ KeyError class file(object): + def read(self, n=None): pass def write(self, s): pass + def close(self): pass class float(object): def __init__(self, number_or_string=None): pass @@ -160,8 +166,7 @@ self.__new__() if args is not None: - for arg in args: - self.append(arg) + self.extend(args) def __new__(self): # Reserve space for a fragment reference. @@ -171,10 +176,20 @@ # Note usage. IndexError + def __contains__(self, value): pass def __setitem__(self, index, value): pass def __getslice__(self, start, end=None): pass def __setslice__(self, start, end, slice): pass def append(self, value): pass + + def extend(self, iterable): + + "Extend the list with the contents of 'iterable'." + + for i in iterable: + self.append(i) + + def sort(self, cmp=None, key=None, reverse=0): pass def __len__(self): pass def __add__(self, other): pass def __iadd__(self, other): pass diff -r 023105a53af2 -r aaf23d3b2bcd micropython/__init__.py --- a/micropython/__init__.py Sun Aug 22 20:35:20 2010 +0200 +++ b/micropython/__init__.py Mon Aug 23 00:15:03 2010 +0200 @@ -513,10 +513,11 @@ self.add_attribute_to_visit(objname, attrname) - # Start with the "root" modules, finding referenced objects. + # Visit all modules, since some may employ initialisation code which has + # some kind of side-effect. - self._collect_attributes("__builtins__", objtable) - self._collect_attributes("__main__", objtable) + for name in self.modules.keys(): + self._collect_attributes(name, objtable) def add_attribute_to_visit(self, objname, attrname):