File tree Expand file tree Collapse file tree 3 files changed +35
-7
lines changed Expand file tree Collapse file tree 3 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 22
22
"ReferenceSearchingAccessor" ,
23
23
"ElementListCouplingMixin" ,
24
24
"RoleTagAccessor" ,
25
+ "InvalidChangeRequest" ,
25
26
]
26
27
27
28
import abc
46
47
_C = t .TypeVar ("_C" , bound = "ElementListCouplingMixin" )
47
48
48
49
50
+ class InvalidChangeRequest (Exception ):
51
+ """Raised when a change request is invalid."""
52
+
53
+
49
54
class NonUniqueMemberError (ValueError ):
50
55
"""Raised when a duplicate member is inserted into a list."""
51
56
Original file line number Diff line number Diff line change @@ -211,17 +211,20 @@ def __init__(
211
211
parent .append (self ._element )
212
212
try :
213
213
for key , val in kw .items ():
214
+ prop = getattr (type (self ), key )
215
+ is_acc_or_attr_prop = isinstance (
216
+ prop , (accessors .Accessor , properties .AttributeProperty )
217
+ )
214
218
if key == "xtype" :
215
219
self ._element .set (helpers .ATT_XT , val )
216
- elif not isinstance (
217
- getattr (type (self ), key ),
218
- (accessors .Accessor , properties .AttributeProperty ),
220
+ elif is_acc_or_attr_prop or (
221
+ isinstance (prop , property ) and not self ._constructed
219
222
):
223
+ setattr (self , key , val )
224
+ else :
220
225
raise TypeError (
221
226
f"Cannot set { key !r} on { type (self ).__name__ } "
222
227
)
223
- else :
224
- setattr (self , key , val )
225
228
self ._model ._loader .idcache_index (self ._element )
226
229
except BaseException :
227
230
parent .remove (self ._element )
Original file line number Diff line number Diff line change @@ -38,10 +38,30 @@ class Part(c.GenericElement):
38
38
39
39
deployed_parts : c .Accessor
40
40
41
- @property
42
- def name (self ) -> str : # type: ignore[override]
41
+ @property # type: ignore[override]
42
+ def name (self ) -> str :
43
+ """Return the name of the Part."""
43
44
return self .type .name
44
45
46
+ @name .setter
47
+ def name (self , value : str ) -> None :
48
+ if not isinstance (value , str ):
49
+ raise TypeError ("Name has to be a string" )
50
+
51
+ if self ._constructed :
52
+ raise c .InvalidChangeRequest (
53
+ "This won't have any effect. The name is inferred from "
54
+ "`.type`."
55
+ )
56
+
57
+ if not value :
58
+ try :
59
+ del self ._element .attrib ["name" ]
60
+ except KeyError :
61
+ pass
62
+ else :
63
+ self ._element .attrib ["name" ] = value
64
+
45
65
46
66
@c .xtype_handler (None )
47
67
class ExchangeItemAllocation (c .GenericElement ):
You can’t perform that action at this time.
0 commit comments