示例#1
0
 def _update(self, obj):
     """
     Update the list of items. Returns a unioncache instance.
     """
     u = self.filter(obj)
     if self.upper == 1:
         assert len(u) <= 1, (
             "Derived union %s of item %s should have length 1 %s" %
             (self.name, obj.id, tuple(u)))
         uc = unioncache(u[0] if u else None, self.version)
     else:
         uc = unioncache(collectionlist(u), self.version)
     setattr(obj, self._name, uc)
     return uc
示例#2
0
    def _union(self, obj, exclude=None):
        """Returns a union of all values as a set."""
        u: Set[T] = set()
        for s in self.subsets:
            if s is exclude or not object_has_property(obj, s):
                continue

            tmp = s.__get__(obj)
            if tmp:
                try:
                    u.update(tmp)
                except TypeError:
                    # [0..1] property
                    u.add(tmp)
        return collectionlist(u)
示例#3
0
    def _update(self, obj):
        """Update the list of items.

        Returns a unioncache instance.
        """
        u = self.filter(obj)
        if self.upper == 1:
            assert (
                len(u) <= 1
            ), f"Derived union {self.name} of item {obj.id} should have length 1 {tuple(u)}"
            uc = unioncache(self, u[0] if u else None, self.version)
        else:
            uc = unioncache(self, collectionlist(u), self.version)
        setattr(obj, self._name, uc)
        return uc
示例#4
0
def test_listing():
    c: collectionlist[str] = collectionlist()
    c.append("a")
    c.append("b")
    c.append("c")
    assert str(c) == "['a', 'b', 'c']"