Prepare for the analysis of a class definition. Create an empty TypeInfo and store it in a symbol table, or if the 'info' argument is provided, store it instead (used for magic type definitions).
(
self, defn: ClassDef, info: TypeInfo | None = None, custom_names: bool = False
)
| 2514 | return tvar_defs |
| 2515 | |
| 2516 | def prepare_class_def( |
| 2517 | self, defn: ClassDef, info: TypeInfo | None = None, custom_names: bool = False |
| 2518 | ) -> None: |
| 2519 | """Prepare for the analysis of a class definition. |
| 2520 | |
| 2521 | Create an empty TypeInfo and store it in a symbol table, or if the 'info' |
| 2522 | argument is provided, store it instead (used for magic type definitions). |
| 2523 | """ |
| 2524 | if not defn.info: |
| 2525 | defn.fullname = self.qualified_name(defn.name) |
| 2526 | # TODO: Nested classes |
| 2527 | info = info or self.make_empty_type_info(defn) |
| 2528 | defn.info = info |
| 2529 | info.defn = defn |
| 2530 | if not custom_names: |
| 2531 | # Some special classes (in particular NamedTuples) use custom fullname logic. |
| 2532 | # Don't override it here (also see comment below, this needs cleanup). |
| 2533 | if not self.is_func_scope(): |
| 2534 | info._fullname = self.qualified_name(defn.name) |
| 2535 | else: |
| 2536 | info._fullname = info.name |
| 2537 | local_name = defn.name |
| 2538 | if "@" in local_name: |
| 2539 | local_name = local_name.split("@")[0] |
| 2540 | self.add_symbol(local_name, defn.info, defn) |
| 2541 | if self.is_nested_within_func_scope(): |
| 2542 | # We need to preserve local classes, let's store them |
| 2543 | # in globals under mangled unique names |
| 2544 | # |
| 2545 | # TODO: Putting local classes into globals breaks assumptions in fine-grained |
| 2546 | # incremental mode and we should avoid it. In general, this logic is too |
| 2547 | # ad-hoc and needs to be removed/refactored. |
| 2548 | if "@" not in defn.info._fullname: |
| 2549 | global_name = defn.info.name + "@" + str(defn.line) |
| 2550 | defn.info._fullname = self.cur_mod_id + "." + global_name |
| 2551 | else: |
| 2552 | # Preserve name from previous fine-grained incremental run. |
| 2553 | global_name = defn.info.name |
| 2554 | defn.fullname = defn.info._fullname |
| 2555 | if defn.info.is_named_tuple or defn.info.typeddict_type: |
| 2556 | # Named tuples and Typed dicts nested within a class are stored |
| 2557 | # in the class symbol table. |
| 2558 | self.add_symbol_skip_local(global_name, defn.info) |
| 2559 | else: |
| 2560 | self.globals[global_name] = SymbolTableNode(GDEF, defn.info) |
| 2561 | |
| 2562 | def make_empty_type_info(self, defn: ClassDef) -> TypeInfo: |
| 2563 | if ( |
no test coverage detected