File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,13 +57,43 @@ class Expando(dict):
5757 ...
5858 AttributeError: foo
5959
60+ And copied:
61+
62+ >>> o = Expando(foo=42)
63+ >>> p = o.copy()
64+ >>> isinstance(p,Expando)
65+ True
66+ >>> o == p
67+ True
68+ >>> o is p
69+ False
70+
71+ Same with MagicExpando ...
72+
73+ >>> o = MagicExpando()
74+ >>> o.foo.bar = 42
75+ >>> p = o.copy()
76+ >>> isinstance(p,MagicExpando)
77+ True
78+ >>> o == p
79+ True
80+ >>> o is p
81+ False
82+
83+ ... but the copy is shallow:
84+
85+ >>> o.foo is p.foo
86+ True
6087 """
6188
6289 def __init__ ( self , * args , ** kwargs ):
6390 super ( Expando , self ).__init__ ( * args , ** kwargs )
6491 self .__slots__ = None
6592 self .__dict__ = self
6693
94+ def copy (self ):
95+ return type (self )(self )
96+
6797class MagicExpando (Expando ):
6898 """
6999 Use MagicExpando for chained attribute access. The first time a missing attribute is
You can’t perform that action at this time.
0 commit comments