@@ -13,48 +13,52 @@ def __new__(mcs, name: typing.AnyStr, bases: typing.Tuple, class_dict: typing.Di
1313 class_dict_copy = class_dict .copy ()
1414
1515 _instance_id = Field (
16- verbose_name = ' Instance ID' ,
17- data_type = ' string' ,
16+ verbose_name = " Instance ID" ,
17+ data_type = " string" ,
1818 required = True ,
1919 default = None ,
2020 )
2121 _create_ts = Field (
22- verbose_name = ' Creation Timestamp' ,
23- data_type = ' int' ,
22+ verbose_name = " Creation Timestamp" ,
23+ data_type = " int" ,
2424 required = True ,
2525 default = None ,
2626 )
2727
28- class_dict_copy .update ({
29- '_instance_id' : _instance_id ,
30- '_create_ts' : _create_ts ,
31- })
28+ class_dict_copy .update (
29+ {
30+ "_instance_id" : _instance_id ,
31+ "_create_ts" : _create_ts ,
32+ }
33+ )
3234
3335 for k , v in class_dict_copy .items ():
3436 if isinstance (v , Field ):
3537 v .name = k
36- v .fullname = f' { name .lower ()} .{ k } '
37- v .internal_name = f' field__{ k } '
38+ v .fullname = f" { name .lower ()} .{ k } "
39+ v .internal_name = f" field__{ k } "
3840 if v .verbose_name is None :
3941 v .verbose_name = v .name
4042
4143 meta_context : typing .Dict = {}
42- meta_class = class_dict .get (' Meta' )
44+ meta_class = class_dict .get (" Meta" )
4345 if meta_class :
4446 assert isinstance (meta_class , type )
4547 m_dict : typing .Dict = meta_class .__dict__
4648 for mk , mv in m_dict .items ():
47- if not mk .startswith ('__' ):
49+ if not mk .startswith ("__" ):
4850 meta_context .update ({mk : mv })
49- class_dict_copy .update ({' meta_context' : meta_context })
51+ class_dict_copy .update ({" meta_context" : meta_context })
5052
5153 def _random_string (self ):
52- return '' .join (random .sample (string .ascii_letters + string .digits , 6 ))
53- class_dict_copy .update ({'random_string' : property (_random_string )})
54+ return "" .join (random .sample (string .ascii_letters + string .digits , 6 ))
55+
56+ class_dict_copy .update ({"random_string" : property (_random_string )})
5457
5558 def _config (self ):
5659 pass
57- class_dict_copy .update ({'config' : property (_config )})
60+
61+ class_dict_copy .update ({"config" : property (_config )})
5862
5963 def initialize_instance (self , init_data : typing .Dict ) -> typing .NoReturn :
6064 cls_dict : typing .Dict = self .__class__ .__dict__
@@ -70,10 +74,7 @@ def initialize_instance(self, init_data: typing.Dict) -> typing.NoReturn:
7074 assert isinstance (sk_v , list )
7175 if isinstance (data_type , BluePrintMeta ):
7276 if issubclass (data_type , BluePrint ):
73- v_deserialized = [
74- data_type (** d )
75- for d in sk_v
76- ]
77+ v_deserialized = [data_type (** d ) for d in sk_v ]
7778 else :
7879 v_deserialized = sk_v
7980 else :
@@ -94,29 +95,33 @@ def initialize_instance(self, init_data: typing.Dict) -> typing.NoReturn:
9495 self ._create_ts = int (time .time ())
9596
9697 # Generate `self._instance_id` according to this format template
97- instance_id_template = self .meta_context .get (' instance_id_template' )
98+ instance_id_template = self .meta_context .get (" instance_id_template" )
9899 if not instance_id_template :
99- raise BluePrintInitException (msg = f'instance_id_template not configured for <{ self .__class__ .__name__ } >' )
100+ raise BluePrintInitException (
101+ msg = f"instance_id_template not configured for <{ self .__class__ .__name__ } >"
102+ )
100103 self .instance_id_template = instance_id_template
101104
102105 # Can be saved to backend at this level ?
103- is_top = self .meta_context .get (' is_top' , False )
106+ is_top = self .meta_context .get (" is_top" , False )
104107 self .is_top = is_top
105108
106109 # Check instance state (without _instance_id)
107110 # And build instance id render context
108111 self .instance_id_render_context = {}
109112
110113 for sk , sv in cls_dict .items ():
111- if sk == ' _instance_id' :
114+ if sk == " _instance_id" :
112115 continue
113116
114117 if isinstance (sv , Field ):
115118 sk_v = getattr (self , sk , None )
116119 self .instance_id_render_context .update ({sk : sk_v })
117120 if sv .required and sv .default is None :
118121 if sk_v is None :
119- raise BluePrintInitException (msg = f'Please specify value for { sv .fullname } ' )
122+ raise BluePrintInitException (
123+ msg = f"Please specify value for { sv .fullname } "
124+ )
120125
121126 self ._backend = Backend () # Redis ?
122127
@@ -127,8 +132,7 @@ def init(self, **kwargs) -> typing.NoReturn:
127132 pass
128133 else :
129134 self ._instance_id = self .instance_id_template .format (
130- random_string = self .random_string ,
131- ** self .instance_id_render_context
135+ random_string = self .random_string , ** self .instance_id_render_context
132136 )
133137
134138 def serialize (self ) -> typing .Dict :
@@ -145,7 +149,9 @@ def serialize(self) -> typing.Dict:
145149 assert isinstance (sk_v , list )
146150 if isinstance (data_type , BluePrintMeta ):
147151 if issubclass (data_type , BluePrint ):
148- serialized .update ({sk : [item .serialize () for item in sk_v ]})
152+ serialized .update (
153+ {sk : [item .serialize () for item in sk_v ]}
154+ )
149155 else :
150156 serialized .update ({sk : sk_v })
151157 else :
@@ -157,11 +163,13 @@ def serialize(self) -> typing.Dict:
157163 serialized .update ({sk : sk_v })
158164 return serialized
159165
160- class_dict_copy .update ({
161- '__init__' : init ,
162- 'initialize_instance' : initialize_instance ,
163- 'serialize' : serialize ,
164- })
166+ class_dict_copy .update (
167+ {
168+ "__init__" : init ,
169+ "initialize_instance" : initialize_instance ,
170+ "serialize" : serialize ,
171+ }
172+ )
165173
166174 cls = type .__new__ (mcs , name , bases , class_dict_copy )
167175 return cls
@@ -170,5 +178,4 @@ def serialize(self) -> typing.Dict:
170178class BluePrint (metaclass = BluePrintMeta ):
171179 def save (self ):
172180 assert self .is_top
173- self ._backend .set ('x' , 'y' )
174-
181+ self ._backend .set ("x" , "y" )
0 commit comments