The type 'Any'.
| 1264 | |
| 1265 | |
| 1266 | class AnyType(ProperType): |
| 1267 | """The type 'Any'.""" |
| 1268 | |
| 1269 | __slots__ = ("type_of_any", "source_any", "missing_import_name") |
| 1270 | |
| 1271 | def __init__( |
| 1272 | self, |
| 1273 | type_of_any: int, |
| 1274 | source_any: AnyType | None = None, |
| 1275 | missing_import_name: str | None = None, |
| 1276 | line: int = -1, |
| 1277 | column: int = -1, |
| 1278 | ) -> None: |
| 1279 | super().__init__(line, column) |
| 1280 | self.type_of_any = type_of_any |
| 1281 | # If this Any was created as a result of interacting with another 'Any', record the source |
| 1282 | # and use it in reports. |
| 1283 | self.source_any = source_any |
| 1284 | if source_any and source_any.source_any: |
| 1285 | self.source_any = source_any.source_any |
| 1286 | |
| 1287 | if source_any is None: |
| 1288 | self.missing_import_name = missing_import_name |
| 1289 | else: |
| 1290 | self.missing_import_name = source_any.missing_import_name |
| 1291 | |
| 1292 | # Only unimported type anys and anys from other anys should have an import name |
| 1293 | assert missing_import_name is None or type_of_any in ( |
| 1294 | TypeOfAny.from_unimported_type, |
| 1295 | TypeOfAny.from_another_any, |
| 1296 | ) |
| 1297 | # Only Anys that come from another Any can have source_any. |
| 1298 | assert type_of_any != TypeOfAny.from_another_any or source_any is not None |
| 1299 | # We should not have chains of Anys. |
| 1300 | assert not self.source_any or self.source_any.type_of_any != TypeOfAny.from_another_any |
| 1301 | |
| 1302 | @property |
| 1303 | def is_from_error(self) -> bool: |
| 1304 | return self.type_of_any == TypeOfAny.from_error |
| 1305 | |
| 1306 | def accept(self, visitor: TypeVisitor[T]) -> T: |
| 1307 | return visitor.visit_any(self) |
| 1308 | |
| 1309 | def copy_modified( |
| 1310 | self, |
| 1311 | # Mark with Bogus because _dummy is just an object (with type Any) |
| 1312 | type_of_any: int = _dummy_int, |
| 1313 | original_any: Bogus[AnyType | None] = _dummy, |
| 1314 | missing_import_name: Bogus[str | None] = _dummy, |
| 1315 | ) -> AnyType: |
| 1316 | if type_of_any == _dummy_int: |
| 1317 | type_of_any = self.type_of_any |
| 1318 | if original_any is _dummy: |
| 1319 | original_any = self.source_any |
| 1320 | if missing_import_name is _dummy: |
| 1321 | missing_import_name = self.missing_import_name |
| 1322 | return AnyType( |
| 1323 | type_of_any=type_of_any, |
no outgoing calls
searching dependent graphs…