(self, original_node: Module, updated_node: Module)
| 1305 | return cst.SimpleString(f'"{data_type}"') |
| 1306 | |
| 1307 | def leave_Module(self, original_node: Module, updated_node: Module) -> Module: |
| 1308 | # add from __future__ import annotations if not the first import |
| 1309 | updated_node = self.add_future_import(updated_node) |
| 1310 | |
| 1311 | needs_datetime_import = any( |
| 1312 | p.data_type.type == "datetime" for p in self.all_properties if isinstance(p.data_type, PythonType) |
| 1313 | ) |
| 1314 | |
| 1315 | if not needs_datetime_import: |
| 1316 | return updated_node |
| 1317 | |
| 1318 | i = 0 |
| 1319 | node = updated_node |
| 1320 | datetime_exists = False |
| 1321 | in_github_imports = False |
| 1322 | while ( |
| 1323 | i < len(node.body) |
| 1324 | and isinstance(node.body[i], cst.SimpleStatementLine) |
| 1325 | and isinstance(node.body[i].body[0], (cst.Import, cst.ImportFrom)) |
| 1326 | ): |
| 1327 | import_stmt = node.body[i].body[0] |
| 1328 | if self.is_datetime_import(import_stmt): |
| 1329 | datetime_exists = True |
| 1330 | |
| 1331 | if not in_github_imports and self.is_github_import(import_stmt): |
| 1332 | in_github_imports = True |
| 1333 | |
| 1334 | # emit datetime import if needed |
| 1335 | if needs_datetime_import and not datetime_exists: |
| 1336 | node = self.add_datetime_import(node, i) |
| 1337 | datetime_exists = True |
| 1338 | i = i + 1 |
| 1339 | |
| 1340 | i = i + 1 |
| 1341 | |
| 1342 | # emit datetime import if needed |
| 1343 | if needs_datetime_import and not datetime_exists: |
| 1344 | node = self.add_datetime_import(node, i) |
| 1345 | |
| 1346 | return node |
| 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: |
nothing calls this directly
no test coverage detected