1.1 --- a/micropython/data.py Thu Mar 05 00:45:42 2009 +0100
1.2 +++ b/micropython/data.py Thu Mar 19 23:05:55 2009 +0100
1.3 @@ -298,6 +298,37 @@
1.4 else:
1.5 return 0
1.6
1.7 + def defined_outside_hierarchy(self):
1.8 +
1.9 + """
1.10 + Return whether the parent and context of the attribute never belong to
1.11 + the same class hierarchy.
1.12 + """
1.13 +
1.14 + # Must be defined within a class.
1.15 +
1.16 + if isinstance(self.parent, Class):
1.17 +
1.18 + # To be sure, all contexts must be classes and be the same as the
1.19 + # parent, or be a superclass of the parent, or be a subclass of the
1.20 + # parent.
1.21 +
1.22 + for context in self.get_contexts():
1.23 + if not (
1.24 + isinstance(context, Class) and not (
1.25 + context is self.parent or
1.26 + context.has_subclass(self.parent) or
1.27 + self.parent.has_subclass(context))
1.28 + ):
1.29 + return 0
1.30 +
1.31 + return 1
1.32 +
1.33 + # Instance attributes are not defined within a hierarchy.
1.34 +
1.35 + else:
1.36 + return 0
1.37 +
1.38 def __repr__(self):
1.39 return "Attr(%r, %s, %r) # [%s], %r" % (
1.40 self.position, shortrepr(self.parent), self.name,