(cls, prop: Property)
| 1183 | |
| 1184 | @classmethod |
| 1185 | def create_use_attr(cls, prop: Property) -> cst.BaseStatement: |
| 1186 | # we need to make the 'headers' attribute truly private, |
| 1187 | # otherwise it conflicts with GithubObject._headers |
| 1188 | attr_name = f"__{prop.name}" if prop.name == "headers" else f"_{prop.name}" |
| 1189 | return cst.If( |
| 1190 | test=cst.Comparison( |
| 1191 | left=cst.SimpleString(f'"{prop.name}"'), |
| 1192 | comparisons=[cst.ComparisonTarget(operator=cst.In(), comparator=cst.Name("attributes"))], |
| 1193 | ), |
| 1194 | body=cst.IndentedBlock( |
| 1195 | header=cst.TrailingWhitespace( |
| 1196 | whitespace=cst.SimpleWhitespace(" "), comment=cst.Comment("# pragma no branch") |
| 1197 | ), |
| 1198 | body=[ |
| 1199 | cst.SimpleStatementLine( |
| 1200 | [ |
| 1201 | cst.Assign( |
| 1202 | targets=[cst.AssignTarget(cls.create_attribute(["self", attr_name]))], |
| 1203 | value=cls.make_attribute(prop), |
| 1204 | ) |
| 1205 | ] |
| 1206 | ) |
| 1207 | ], |
| 1208 | ), |
| 1209 | ) |
| 1210 | |
| 1211 | def update_init_attrs(self, func: cst.FunctionDef) -> cst.FunctionDef: |
| 1212 | # adds only missing attributes, does not update existing ones |
no test coverage detected