1313]
1414
1515
16- class AttributeView (object ):
17- """Mixin for attribute dict views."""
16+ class AttributeView (MutableMapping ):
17+ """Base class for attribute dict views."""
1818
1919 def __init__ (self , defaults , attr , custom_only = False ):
2020 super (AttributeView , self ).__init__ ()
@@ -29,7 +29,7 @@ def __str__(self):
2929 return "{" + ", " .join (s ) + "}"
3030
3131 def __len__ (self ):
32- return len (self .defaults )
32+ return len (set ( self .defaults ). union ( self . attr ) )
3333
3434 def __getitem__ (self , name ):
3535 if name not in self .attr :
@@ -48,43 +48,44 @@ def __iter__(self):
4848 for name in self .attr :
4949 yield name
5050 else :
51- for name in self .defaults :
51+ names = set (self .defaults ).union (self .attr )
52+ for name in names :
5253 yield name
5354
5455
55- class NodeAttributeView (AttributeView , MutableMapping ):
56+ class NodeAttributeView (AttributeView ):
5657 """Mutable Mapping that provides a read/write view of the custom attributes of a node
5758 combined with the default attributes of all nodes."""
5859
5960 def __init__ (self , defaults , attr , custom_only = False ):
6061 super (NodeAttributeView , self ).__init__ (defaults , attr , custom_only )
6162
6263
63- class VertexAttributeView (AttributeView , MutableMapping ):
64+ class VertexAttributeView (AttributeView ):
6465 """Mutable Mapping that provides a read/write view of the custom attributes of a vertex
6566 combined with the default attributes of all vertices."""
6667
6768 def __init__ (self , defaults , attr , custom_only = False ):
6869 super (VertexAttributeView , self ).__init__ (defaults , attr , custom_only )
6970
7071
71- class EdgeAttributeView (AttributeView , MutableMapping ):
72+ class EdgeAttributeView (AttributeView ):
7273 """Mutable Mapping that provides a read/write view of the custom attributes of an edge
7374 combined with the default attributes of all edges."""
7475
7576 def __init__ (self , defaults , attr , custom_only = False ):
7677 super (EdgeAttributeView , self ).__init__ (defaults , attr , custom_only )
7778
7879
79- class FaceAttributeView (AttributeView , MutableMapping ):
80+ class FaceAttributeView (AttributeView ):
8081 """Mutable Mapping that provides a read/write view of the custom attributes of a face
8182 combined with the default attributes of all faces."""
8283
8384 def __init__ (self , defaults , attr , custom_only = False ):
8485 super (FaceAttributeView , self ).__init__ (defaults , attr , custom_only )
8586
8687
87- class CellAttributeView (AttributeView , MutableMapping ):
88+ class CellAttributeView (AttributeView ):
8889 """Mutable Mapping that provides a read/write view of the custom attributes of a cell
8990 combined with the default attributes of all faces."""
9091
0 commit comments