MCPcopy
hub / github.com/beeware/toga / values

Method values

dummy/src/toga_dummy/utils.py:43–70  ·  view source on GitHub ↗

Return all values that an attribute on an instance has had. :param instance: The widget instance :param attr: The attribute name to inspect :return: A list of all values that have been assigned to the attribute. Raises AttributeError if the attribute has not been

(cls, instance, attr)

Source from the content-addressed store, hash-verified

41
42 @classmethod
43 def values(cls, instance, attr):
44 """Return all values that an attribute on an instance has had.
45
46 :param instance: The widget instance
47 :param attr: The attribute name to inspect
48 :return: A list of all values that have been assigned to the attribute.
49 Raises AttributeError if the attribute has not been set on the instance.
50 """
51 attrs = set()
52 values = []
53 for entry in cls._log:
54 if entry.logtype == cls.SET_VALUE and entry.instance == instance._impl:
55 if entry.context["attr"] == attr:
56 values.append(entry.context["value"])
57 else:
58 attrs.add(entry.context["attr"])
59
60 if values:
61 return values
62
63 if attrs:
64 known_attributes = ", ".join(f"{a!r}" for a in sorted(attrs))
65 raise AttributeError(
66 f"{instance} did not have the attribute {attr!r} set; "
67 f"known attributes were {known_attributes}."
68 )
69 else:
70 raise AttributeError(f"No attributes were set on {instance} ")
71
72 @classmethod
73 def value(cls, instance, attr):

Callers 2

attribute_valuesFunction · 0.45
assert_attribute_not_setFunction · 0.45

Calls 2

appendMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected