(prop: Property, self_attribute: bool)
| 1347 | |
| 1348 | def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.FunctionDef): |
| 1349 | def create_statement(prop: Property, self_attribute: bool) -> cst.SimpleStatementLine: |
| 1350 | # turn a list of GithubClasses into the first element of the list |
| 1351 | if ( |
| 1352 | isinstance(prop.data_type, PythonType) |
| 1353 | and prop.data_type.type == "list" |
| 1354 | and isinstance(prop.data_type.inner_types[0], GithubClass) |
| 1355 | and prop.data_type.inner_types[0].ids |
| 1356 | ): |
| 1357 | prop = dataclasses.replace(prop, name=f"{prop.name}[0]", data_type=prop.data_type.inner_types[0]) |
| 1358 | |
| 1359 | if ( |
| 1360 | isinstance(prop.data_type, GithubClass) |
| 1361 | or isinstance(prop.data_type, PythonType) |
| 1362 | and prop.data_type.type == "union" |
| 1363 | and any(isinstance(inner, GithubClass) for inner in prop.data_type.inner_types) |
| 1364 | ): |
| 1365 | ids = [] |
| 1366 | if isinstance(prop.data_type, PythonType): |
| 1367 | ids_sets = [ |
| 1368 | set(inner.ids) for inner in prop.data_type.inner_types if isinstance(inner, GithubClass) |
| 1369 | ] |
| 1370 | if len(ids_sets) == 1: |
| 1371 | ids = list(ids_sets[0]) |
| 1372 | elif len(ids_sets) > 1: |
| 1373 | ids = ids_sets[0] |
| 1374 | for ids_set in ids_sets[1:]: |
| 1375 | ids = ids.intersection(ids_set) |
| 1376 | ids = list(ids) |
| 1377 | else: |
| 1378 | if prop.data_type.ids: |
| 1379 | ids = prop.data_type.ids |
| 1380 | |
| 1381 | if ids: |
| 1382 | id = ids[0] |
| 1383 | return cst.SimpleStatementLine( |
| 1384 | [ |
| 1385 | cst.Expr( |
| 1386 | cst.Call( |
| 1387 | func=self.create_attribute(["self", "assertEqual"]), |
| 1388 | args=[ |
| 1389 | cst.Arg( |
| 1390 | self.create_attribute( |
| 1391 | (["self"] if self_attribute else []) + [attribute, prop.name, id] |
| 1392 | ) |
| 1393 | ), |
| 1394 | cst.Arg(cst.SimpleString('""')), |
| 1395 | ], |
| 1396 | ) |
| 1397 | ) |
| 1398 | ] |
| 1399 | ) |
| 1400 | |
| 1401 | return cst.SimpleStatementLine( |
| 1402 | [ |
| 1403 | cst.Expr( |
| 1404 | cst.Call( |
| 1405 | func=self.create_attribute(["self", "assertEqual"]), |
| 1406 | args=[ |
nothing calls this directly
no test coverage detected