1.1 --- a/micropython/data.py Sat Nov 16 15:53:25 2013 +0100
1.2 +++ b/micropython/data.py Sat Nov 16 20:04:15 2013 +0100
1.3 @@ -388,6 +388,12 @@
1.4
1.5 # Program data structures.
1.6
1.7 +def only(s):
1.8 + if len(s) == 1:
1.9 + for i in s:
1.10 + return i
1.11 + return None
1.12 +
1.13 class BaseAttr:
1.14
1.15 "A basic attribute entry."
1.16 @@ -418,8 +424,9 @@
1.17
1.18 "Get the context referenced by the attribute."
1.19
1.20 - if self.get_assignments() == 1 and len(self.get_context_values()) == 1:
1.21 - return self.get_contexts()[0]
1.22 + if self.get_assignments() == 1:
1.23 + context_value = only(self.get_context_values())
1.24 + return context_value and context_value[0]
1.25 else:
1.26 return None
1.27
1.28 @@ -427,8 +434,9 @@
1.29
1.30 "Get the value referenced by the attribute."
1.31
1.32 - if self.get_assignments() == 1 and len(self.get_context_values()) == 1:
1.33 - return self.get_values()[0]
1.34 + if self.get_assignments() == 1:
1.35 + context_value = only(self.get_context_values())
1.36 + return context_value and context_value[1]
1.37 else:
1.38 return None
1.39