@@ -38,7 +38,7 @@ def default(self) -> str | None:
3838 if self .proc_str == "%b" :
3939 return "false"
4040 elif self .proc_str == "%s" :
41- return ''
41+ return ""
4242 else :
4343 return None
4444
@@ -48,19 +48,16 @@ class ArgSettings(base.Base):
4848 """
4949 Contains whether the ids, names, and defaults of arguments in a mutation are None or not - i.e. the configuration of the arguments
5050 """
51+
5152 ids : bool
5253 names : bool
5354 defaults : bool
5455
5556 def __int__ (self ):
56- return (int (self .ids ) +
57- int (self .names ) +
58- int (self .defaults ))
57+ return int (self .ids ) + int (self .names ) + int (self .defaults )
5958
6059 def __eq__ (self , other ):
61- return (self .ids == other .ids and
62- self .names == other .names and
63- self .defaults == other .defaults )
60+ return self .ids == other .ids and self .names == other .names and self .defaults == other .defaults
6461
6562 def __gt__ (self , other ):
6663 return int (self ) > int (other )
@@ -72,7 +69,7 @@ def __lt__(self, other):
7269@dataclass
7370class Argument (base .MutationSubComponent ):
7471 name : str
75- default : str = ''
72+ default : str = ""
7673 _type : Optional [ArgumentType ] = None
7774
7875 _id : str = None
@@ -91,8 +88,9 @@ def index(self):
9188 def type (self ) -> Optional [ArgumentType ]:
9289 if not self ._type :
9390 if not self .mutation :
94- raise ValueError (f"Cannot infer 'type' of { self } when there is no mutation attached. "
95- f"Consider providing a type manually." )
91+ raise ValueError (
92+ f"Cannot infer 'type' of { self } when there is no mutation attached. Consider providing a type manually."
93+ )
9694
9795 i = 0
9896 goal = self .index
@@ -130,22 +128,22 @@ def parse_proc_code(_proc_code: str) -> Optional[list[str | ArgumentType]]:
130128
131129 if _proc_code is None :
132130 return None
133- token = ''
131+ token = ""
134132 tokens = []
135133
136- last_char = ''
134+ last_char = ""
137135 for char in _proc_code :
138- if last_char == '%' :
136+ if last_char == "%" :
139137 if char in "sb" :
140138 # If we've hit an %s or %b
141139 token = token [:- 1 ]
142140 # Clip the % sign off the token
143141
144- if token .endswith (' ' ):
142+ if token .endswith (" " ):
145143 # A space is required before params, but this should not be part of the parsed output
146144 token = token [:- 1 ]
147145
148- if token != '' :
146+ if token != "" :
149147 # Make sure not to append an empty token
150148 tokens .append (token )
151149
@@ -156,17 +154,18 @@ def parse_proc_code(_proc_code: str) -> Optional[list[str | ArgumentType]]:
156154 elif token == "%s" :
157155 tokens .append (ArgTypes .NUMBER_OR_TEXT .value .dcopy ())
158156
159- token = ''
157+ token = ""
160158 continue
161159
162160 token += char
163161 last_char = char
164162
165- if token != '' :
163+ if token != "" :
166164 tokens .append (token )
167165
168166 return tokens
169167
168+
170169def construct_proccode (* components : ArgumentType | ArgTypes | Argument | str ) -> str :
171170 """
172171 Create a proccode from strings/ArgumentType enum members/Argument instances
@@ -194,16 +193,24 @@ def construct_proccode(*components: ArgumentType | ArgTypes | Argument | str) ->
194193 else :
195194 raise TypeError (f"Unsupported component type: { type (comp )} " )
196195
197- result += ' '
196+ result += " "
198197
199198 return result
200199
201200
202201class Mutation (base .BlockSubComponent ):
203- def __init__ (self , _tag_name : str = "mutation" , _children : Optional [list ] = None , _proc_code : Optional [str ] = None ,
204- _is_warp : Optional [bool ] = None , _arguments : Optional [list [Argument ]] = None , _has_next : Optional [bool ] = None ,
205- _argument_settings : Optional [ArgSettings ] = None , * ,
206- _block : Optional [block .Block ] = None ):
202+ def __init__ (
203+ self ,
204+ _tag_name : str = "mutation" ,
205+ _children : Optional [list ] = None ,
206+ _proc_code : Optional [str ] = None ,
207+ _is_warp : Optional [bool ] = None ,
208+ _arguments : Optional [list [Argument ]] = None ,
209+ _has_next : Optional [bool ] = None ,
210+ _argument_settings : Optional [ArgSettings ] = None ,
211+ * ,
212+ _block : Optional [block .Block ] = None ,
213+ ):
207214 """
208215 Mutation for Control:stop block and procedures
209216 https://en.scratch-wiki.info/wiki/Scratch_File_Format#Mutations
@@ -215,9 +222,7 @@ def __init__(self, _tag_name: str = "mutation", _children: Optional[list] = None
215222 if _argument_settings is None :
216223 if _arguments :
217224 _argument_settings = ArgSettings (
218- _arguments [0 ]._id is None ,
219- _arguments [0 ].name is None ,
220- _arguments [0 ].default is None
225+ _arguments [0 ]._id is None , _arguments [0 ].name is None , _arguments [0 ].default is None
221226 )
222227 else :
223228 _argument_settings = ArgSettings (False , False , False )
@@ -263,9 +268,11 @@ def argument_defaults(self):
263268
264269 @property
265270 def argument_settings (self ) -> ArgSettings :
266- return ArgSettings (bool (commons .safe_get (self .argument_ids , 0 )),
267- bool (commons .safe_get (self .argument_names , 0 )),
268- bool (commons .safe_get (self .argument_defaults , 0 )))
271+ return ArgSettings (
272+ bool (commons .safe_get (self .argument_ids , 0 )),
273+ bool (commons .safe_get (self .argument_names , 0 )),
274+ bool (commons .safe_get (self .argument_defaults , 0 )),
275+ )
269276
270277 @property
271278 def parsed_proc_code (self ) -> list [str | ArgumentType ] | None :
@@ -275,7 +282,7 @@ def parsed_proc_code(self) -> list[str | ArgumentType] | None:
275282 return parse_proc_code (self .proc_code )
276283
277284 @staticmethod
278- def from_json (data : dict ) -> Mutation :
285+ def from_json (data : dict ) -> Mutation : # noqa: C901
279286 assert isinstance (data , dict )
280287
281288 _tag_name = data .get ("tagName" , "mutation" )
@@ -302,9 +309,9 @@ def from_json(data: dict) -> Mutation:
302309 if _argument_defaults is not None :
303310 assert isinstance (_argument_defaults , str )
304311 _argument_defaults = json .loads (_argument_defaults )
305- _argument_settings = ArgSettings (_argument_ids is not None ,
306- _argument_names is not None ,
307- _argument_defaults is not None )
312+ _argument_settings = ArgSettings (
313+ _argument_ids is not None , _argument_names is not None , _argument_defaults is not None
314+ )
308315
309316 # control_stop attrs
310317 _has_next = data .get ("hasnext" )
@@ -337,15 +344,17 @@ def to_json(self) -> dict | None:
337344 "tagName" : self .tag_name ,
338345 "children" : self .children ,
339346 }
340- commons .noneless_update (_json , {
341- "proccode" : self .proc_code ,
342- "warp" : commons .dumps_ifnn (self .is_warp ),
343- "argumentids" : commons .dumps_ifnn (self .argument_ids ),
344- "argumentnames" : commons .dumps_ifnn (self .argument_names ),
345- "argumentdefaults" : commons .dumps_ifnn (self .argument_defaults ),
346-
347- "hasNext" : commons .dumps_ifnn (self .has_next )
348- })
347+ commons .noneless_update (
348+ _json ,
349+ {
350+ "proccode" : self .proc_code ,
351+ "warp" : commons .dumps_ifnn (self .is_warp ),
352+ "argumentids" : commons .dumps_ifnn (self .argument_ids ),
353+ "argumentnames" : commons .dumps_ifnn (self .argument_names ),
354+ "argumentdefaults" : commons .dumps_ifnn (self .argument_defaults ),
355+ "hasNext" : commons .dumps_ifnn (self .has_next ),
356+ },
357+ )
349358
350359 return _json
351360
@@ -370,12 +379,10 @@ def link_arguments(self):
370379 # We can still work out argument defaults from parsing the proc code
371380 if self .arguments [0 ].default is None :
372381 _parsed = self .parsed_proc_code
373- _arg_phs : Iterable [ArgumentType ] = filter (lambda tkn : isinstance (tkn , ArgumentType ),
374- _parsed )
382+ _arg_phs : Iterable [ArgumentType ] = filter (lambda tkn : isinstance (tkn , ArgumentType ), _parsed )
375383 for i , _arg_ph in enumerate (_arg_phs ):
376384 self .arguments [i ].default = _arg_ph .default
377385
378386 for _argument in self .arguments :
379387 _argument .mutation = self
380388 _argument .link_using_mutation ()
381-
0 commit comments