| 1260 | |
| 1261 | |
| 1262 | class ApplySchemaTestTransformer(ApplySchemaBaseTransformer): |
| 1263 | def __init__( |
| 1264 | self, |
| 1265 | ids: dict[str, list[str]], |
| 1266 | module_name: str, |
| 1267 | class_name: str, |
| 1268 | properties: dict[str, (str | dict | list | None, bool)], |
| 1269 | deprecate: bool, |
| 1270 | ): |
| 1271 | super().__init__(module_name, class_name, properties, deprecate) |
| 1272 | self.ids = ids |
| 1273 | |
| 1274 | def get_value(self, data_type: PythonType | GithubClass | None) -> Any: |
| 1275 | if data_type is None: |
| 1276 | return cst.Name("None") |
| 1277 | if isinstance(data_type, GithubClass): |
| 1278 | return cst.Name(data_type.name.split(".")[-1]) |
| 1279 | # data_type is PythonType |
| 1280 | if data_type.type == "bool": |
| 1281 | return cst.Name("False") |
| 1282 | if data_type.type == "int": |
| 1283 | return cst.Integer("0") |
| 1284 | if data_type.type == "float": |
| 1285 | return cst.Float("0.0") |
| 1286 | if data_type.type == "str": |
| 1287 | return cst.SimpleString('""') |
| 1288 | if data_type.type == "datetime": |
| 1289 | return cst.Call( |
| 1290 | func=cst.Name("datetime"), |
| 1291 | args=[ |
| 1292 | cst.Arg(cst.Integer("2020")), |
| 1293 | cst.Arg(cst.Integer("1")), |
| 1294 | cst.Arg(cst.Integer("2")), |
| 1295 | cst.Arg(cst.Integer("12")), |
| 1296 | cst.Arg(cst.Integer("34")), |
| 1297 | cst.Arg(cst.Integer("56")), |
| 1298 | cst.Arg( |
| 1299 | keyword=cst.Name("tzinfo"), |
| 1300 | equal=equal, |
| 1301 | value=self.create_attribute(["timezone", "utc"]), |
| 1302 | ), |
| 1303 | ], |
| 1304 | ) |
| 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 |
no outgoing calls
no test coverage detected
searching dependent graphs…