def __init__(self, name, lazy_attributes): types.ModuleType.__init__(self, name) for k, v in lazy_attributes.items(): base.itk_base_global_lazy_attributes.setdefault(k, _builtin_set()).update(v) self.__belong_lazy_attributes = dict( (k, v[0]) for k, v in lazy_attributes.items() if len(v) > 0 ) for k in lazy_attributes: setattr(self, k, not_loaded) # use default known value # For PEP 366 setattr(self, "__package__", "itk") setattr(self, "itk_base_global_lazy_attributes", lazy_attributes) setattr(self, "loaded_lazy_modules", _builtin_set())
def dir2(obj): attrs = _builtin_set() if not hasattr(obj, "__bases__"): # obj is an instance if not hasattr(obj, "__class__"): # slots return sorted(get_attrs(obj)) klass = obj.__class__ attrs.update(get_attrs(klass)) else: # obj is a class klass = obj for cls in klass.__bases__: attrs.update(get_attrs(cls)) attrs.update(dir2(cls)) attrs.update(get_attrs(obj)) return list(attrs)
def _dedup(seq): seen = _builtin_set() seen_add = seen.add return [x for x in seq if not (x in seen or seen_add(x))]