@@ -103,7 +103,7 @@ def __init__(self):
103103
104104 def __getitem__ (
105105 self , index : Union [int , str ]
106- ) -> Union ["Array " , "Record " , "Variable " ]:
106+ ) -> Union ["ODArray " , "ODRecord " , "ODVariable " ]:
107107 """Get object from object dictionary by name or index."""
108108 item = self .names .get (index ) or self .indices .get (index )
109109 if item is None :
@@ -112,7 +112,7 @@ def __getitem__(
112112 return item
113113
114114 def __setitem__ (
115- self , index : Union [int , str ], obj : Union ["Array " , "Record " , "Variable " ]
115+ self , index : Union [int , str ], obj : Union ["ODArray " , "ODRecord " , "ODVariable " ]
116116 ):
117117 assert index == obj .index or index == obj .name
118118 self .add_object (obj )
@@ -131,35 +131,35 @@ def __len__(self) -> int:
131131 def __contains__ (self , index : Union [int , str ]):
132132 return index in self .names or index in self .indices
133133
134- def add_object (self , obj : Union ["Array " , "Record " , "Variable " ]) -> None :
134+ def add_object (self , obj : Union ["ODArray " , "ODRecord " , "ODVariable " ]) -> None :
135135 """Add object to the object dictionary.
136136
137137 :param obj:
138138 Should be either one of
139- :class:`~canopen.objectdictionary.Variable `,
140- :class:`~canopen.objectdictionary.Record `, or
141- :class:`~canopen.objectdictionary.Array `.
139+ :class:`~canopen.objectdictionary.ODVariable `,
140+ :class:`~canopen.objectdictionary.ODRecord `, or
141+ :class:`~canopen.objectdictionary.ODArray `.
142142 """
143143 obj .parent = self
144144 self .indices [obj .index ] = obj
145145 self .names [obj .name ] = obj
146146
147147 def get_variable (
148148 self , index : Union [int , str ], subindex : int = 0
149- ) -> Optional ["Variable " ]:
149+ ) -> Optional ["ODVariable " ]:
150150 """Get the variable object at specified index (and subindex if applicable).
151151
152- :return: Variable if found, else `None`
152+ :return: ODVariable if found, else `None`
153153 """
154154 obj = self .get (index )
155- if isinstance (obj , Variable ):
155+ if isinstance (obj , ODVariable ):
156156 return obj
157- elif isinstance (obj , (Record , Array )):
157+ elif isinstance (obj , (ODRecord , ODArray )):
158158 return obj .get (subindex )
159159
160160
161- class Record (MutableMapping ):
162- """Groups multiple :class:`~canopen.objectdictionary.Variable ` objects using
161+ class ODRecord (MutableMapping ):
162+ """Groups multiple :class:`~canopen.objectdictionary.ODVariable ` objects using
163163 subindices.
164164 """
165165
@@ -178,13 +178,13 @@ def __init__(self, name: str, index: int):
178178 self .subindices = {}
179179 self .names = {}
180180
181- def __getitem__ (self , subindex : Union [int , str ]) -> "Variable " :
181+ def __getitem__ (self , subindex : Union [int , str ]) -> "ODVariable " :
182182 item = self .names .get (subindex ) or self .subindices .get (subindex )
183183 if item is None :
184184 raise KeyError ("Subindex %s was not found" % subindex )
185185 return item
186186
187- def __setitem__ (self , subindex : Union [int , str ], var : "Variable " ):
187+ def __setitem__ (self , subindex : Union [int , str ], var : "ODVariable " ):
188188 assert subindex == var .subindex
189189 self .add_member (var )
190190
@@ -202,18 +202,18 @@ def __iter__(self) -> Iterable[int]:
202202 def __contains__ (self , subindex : Union [int , str ]) -> bool :
203203 return subindex in self .names or subindex in self .subindices
204204
205- def __eq__ (self , other : "Record " ) -> bool :
205+ def __eq__ (self , other : "ODRecord " ) -> bool :
206206 return self .index == other .index
207207
208- def add_member (self , variable : "Variable " ) -> None :
209- """Adds a :class:`~canopen.objectdictionary.Variable ` to the record."""
208+ def add_member (self , variable : "ODVariable " ) -> None :
209+ """Adds a :class:`~canopen.objectdictionary.ODVariable ` to the record."""
210210 variable .parent = self
211211 self .subindices [variable .subindex ] = variable
212212 self .names [variable .name ] = variable
213213
214214
215- class Array (Mapping ):
216- """An array of :class:`~canopen.objectdictionary.Variable ` objects using
215+ class ODArray (Mapping ):
216+ """An array of :class:`~canopen.objectdictionary.ODVariable ` objects using
217217 subindices.
218218
219219 Actual length of array must be read from the node using SDO.
@@ -234,7 +234,7 @@ def __init__(self, name: str, index: int):
234234 self .subindices = {}
235235 self .names = {}
236236
237- def __getitem__ (self , subindex : Union [int , str ]) -> "Variable " :
237+ def __getitem__ (self , subindex : Union [int , str ]) -> "ODVariable " :
238238 var = self .names .get (subindex ) or self .subindices .get (subindex )
239239 if var is not None :
240240 # This subindex is defined
@@ -243,7 +243,7 @@ def __getitem__(self, subindex: Union[int, str]) -> "Variable":
243243 # Create a new variable based on first array item
244244 template = self .subindices [1 ]
245245 name = "%s_%x" % (template .name , subindex )
246- var = Variable (name , self .index , subindex )
246+ var = ODVariable (name , self .index , subindex )
247247 var .parent = self
248248 for attr in ("data_type" , "unit" , "factor" , "min" , "max" , "default" ,
249249 "access_type" , "description" , "value_descriptions" ,
@@ -260,17 +260,17 @@ def __len__(self) -> int:
260260 def __iter__ (self ) -> Iterable [int ]:
261261 return iter (sorted (self .subindices ))
262262
263- def __eq__ (self , other : "Array " ) -> bool :
263+ def __eq__ (self , other : "ODArray " ) -> bool :
264264 return self .index == other .index
265265
266- def add_member (self , variable : "Variable " ) -> None :
267- """Adds a :class:`~canopen.objectdictionary.Variable ` to the record."""
266+ def add_member (self , variable : "ODVariable " ) -> None :
267+ """Adds a :class:`~canopen.objectdictionary.ODVariable ` to the record."""
268268 variable .parent = self
269269 self .subindices [variable .subindex ] = variable
270270 self .names [variable .name ] = variable
271271
272272
273- class Variable :
273+ class ODVariable :
274274 """Simple variable."""
275275
276276 STRUCT_TYPES = {
@@ -289,8 +289,8 @@ class Variable:
289289
290290 def __init__ (self , name : str , index : int , subindex : int = 0 ):
291291 #: The :class:`~canopen.ObjectDictionary`,
292- #: :class:`~canopen.objectdictionary.Record ` or
293- #: :class:`~canopen.objectdictionary.Array ` owning the variable
292+ #: :class:`~canopen.objectdictionary.ODRecord ` or
293+ #: :class:`~canopen.objectdictionary.ODArray ` owning the variable
294294 self .parent = None
295295 #: 16-bit address of the object in the dictionary
296296 self .index = index
@@ -328,7 +328,7 @@ def __init__(self, name: str, index: int, subindex: int = 0):
328328 self .pdo_mappable = False
329329
330330
331- def __eq__ (self , other : "Variable " ) -> bool :
331+ def __eq__ (self , other : "ODVariable " ) -> bool :
332332 return (self .index == other .index and
333333 self .subindex == other .subindex )
334334
@@ -486,3 +486,9 @@ def __init__(self):
486486
487487class ObjectDictionaryError (Exception ):
488488 """Unsupported operation with the current Object Dictionary."""
489+
490+
491+ # Compatibility for old names
492+ Record = ODRecord
493+ Array = ODArray
494+ Variable = ODVariable
0 commit comments