(self, func: cst.FunctionDef)
| 1209 | ) |
| 1210 | |
| 1211 | def update_init_attrs(self, func: cst.FunctionDef) -> cst.FunctionDef: |
| 1212 | # adds only missing attributes, does not update existing ones |
| 1213 | statements = func.body.body |
| 1214 | new_statements = [self.create_init_attr(p) for p in self.all_properties] |
| 1215 | updated_statements = [] |
| 1216 | |
| 1217 | for statement in statements: |
| 1218 | if not isinstance(statement, cst.SimpleStatementLine) or not isinstance(statement.body[0], cst.AnnAssign): |
| 1219 | updated_statements.append(statement) |
| 1220 | continue |
| 1221 | while new_statements and new_statements[0].body[0].target.attr.value < statement.body[0].target.attr.value: |
| 1222 | updated_statements.append(new_statements.pop(0)) |
| 1223 | if new_statements and new_statements[0].body[0].target.attr.value == statement.body[0].target.attr.value: |
| 1224 | updated_statements.append(statement) |
| 1225 | new_statements.pop(0) |
| 1226 | else: |
| 1227 | updated_statements.append(statement) |
| 1228 | while new_statements: |
| 1229 | updated_statements.append(new_statements.pop(0)) |
| 1230 | |
| 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 |
no test coverage detected