Commit a6a4ab23 authored by dboe's avatar dboe
Browse files

container can deal with itself:w

parent 015289f8
...@@ -2520,13 +2520,16 @@ class Container(AbstractNdarray): ...@@ -2520,13 +2520,16 @@ class Container(AbstractNdarray):
>>> sphere2 = sphere.copy() * 3 >>> sphere2 = sphere.copy() * 3
>>> c = tfields.Container([sphere, sphere2]) >>> c = tfields.Container([sphere, sphere2])
# >>> c.save("~/tmp/spheres.npz") >>> c.save("~/tmp/spheres.npz")
# >>> c1 = tfields.Container.load("~/tmp/spheres.npz") >>> c1 = tfields.Container.load("~/tmp/spheres.npz")
""" """
__slots__ = ["items", "labels"] __slots__ = ["items", "labels"]
def __new__(cls, items, **kwargs): def __new__(cls, items, **kwargs):
if issubclass(type(items), cls):
items = items.items
kwargs.setdefault(items.labels)
kwargs["items"] = items kwargs["items"] = items
cls._update_slot_kwargs(kwargs) cls._update_slot_kwargs(kwargs)
...@@ -2544,6 +2547,13 @@ class Container(AbstractNdarray): ...@@ -2544,6 +2547,13 @@ class Container(AbstractNdarray):
return obj return obj
class Maps(Container):
def __new__(cls, items, **kwargs):
if not issubclass(type(items), cls):
print("ASDF")
super().__new__(items, **kwargs)
if __name__ == "__main__": # pragma: no cover if __name__ == "__main__": # pragma: no cover
import doctest import doctest
doctest.testmod() doctest.testmod()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment