1+ from typing import Type , TypeVar , Any , Union , Dict
2+
13
24def is_model_object (o ):
35 from .model_object import ModelObject
@@ -7,7 +9,10 @@ def is_model_object(o):
79 return isinstance (o , ModelObject ) or isinstance (o , ModelCollection ) or isinstance (o , ModelDictionary )
810
911
10- def wrap_model_property (name , model_type ):
12+ T = TypeVar ('T' ) # Type variable for model objects
13+
14+
15+ def wrap_model_property (name : str , model_type : Type [T ]) -> Union [Type [T ], None ]:
1116 """
1217 Wrap a nullable model object property so that type checks can be performed during update
1318 :param name: Property of the derived class
@@ -18,11 +23,11 @@ def wrap_model_property(name, model_type):
1823 STORAGE_NAME = '_' + name
1924
2025 @property
21- def prop (self ):
26+ def prop (self ) -> Union [ Type [ T ], None ] :
2227 return getattr (self , STORAGE_NAME )
2328
2429 @prop .setter
25- def prop (self , value ):
30+ def prop (self , value : Union [ Type [ T ], str , Dict [ str , Any ], None ] ):
2631 if value is None or isinstance (value , model_type ):
2732 setattr (self , STORAGE_NAME , value )
2833 elif isinstance (value , dict ): # Update from JSON
0 commit comments