(self, func: cst.FunctionDef)
| 1231 | return func.with_changes(body=func.body.with_changes(body=updated_statements)) |
| 1232 | |
| 1233 | def update_use_attrs(self, func: cst.FunctionDef) -> cst.FunctionDef: |
| 1234 | # adds only missing attributes, does not update existing ones |
| 1235 | statements = func.body.body |
| 1236 | new_statements = [ |
| 1237 | self.create_use_attr(p) |
| 1238 | for p in self.all_properties |
| 1239 | # list of data types not supported |
| 1240 | if not isinstance(p.data_type, list) |
| 1241 | ] |
| 1242 | updated_statements = [] |
| 1243 | |
| 1244 | for statement in statements: |
| 1245 | if not isinstance(statement, cst.If): |
| 1246 | updated_statements.append(statement) |
| 1247 | continue |
| 1248 | comparison = statement.test if isinstance(statement.test, cst.Comparison) else statement.test.left |
| 1249 | while new_statements and new_statements[0].test.left.value < comparison.left.value: |
| 1250 | updated_statements.append(new_statements.pop(0)) |
| 1251 | if new_statements and new_statements[0].test.left.value == comparison.left.value: |
| 1252 | updated_statements.append(statement) |
| 1253 | new_statements.pop(0) |
| 1254 | else: |
| 1255 | updated_statements.append(statement) |
| 1256 | while new_statements: |
| 1257 | updated_statements.append(new_statements.pop(0)) |
| 1258 | |
| 1259 | return func.with_changes(body=func.body.with_changes(body=updated_statements)) |
| 1260 | |
| 1261 | |
| 1262 | class ApplySchemaTestTransformer(ApplySchemaBaseTransformer): |
no test coverage detected