Add certain special-cased definitions to the builtins module. Some definitions are too special or fundamental to be processed normally from the AST.
(self, file_node: MypyFile)
| 639 | helper(file_node.defs) |
| 640 | |
| 641 | def prepare_builtins_namespace(self, file_node: MypyFile) -> None: |
| 642 | """Add certain special-cased definitions to the builtins module. |
| 643 | |
| 644 | Some definitions are too special or fundamental to be processed |
| 645 | normally from the AST. |
| 646 | """ |
| 647 | names = file_node.names |
| 648 | |
| 649 | # Add empty definition for core built-in classes, since they are required for basic |
| 650 | # operation. These will be completed later on. |
| 651 | for name in CORE_BUILTIN_CLASSES: |
| 652 | cdef = ClassDef(name, Block([])) # Dummy ClassDef, will be replaced later |
| 653 | info = TypeInfo(SymbolTable(), cdef, "builtins") |
| 654 | info._fullname = f"builtins.{name}" |
| 655 | names[name] = SymbolTableNode(GDEF, info) |
| 656 | |
| 657 | bool_info = names["bool"].node |
| 658 | assert isinstance(bool_info, TypeInfo) |
| 659 | bool_type = Instance(bool_info, []) |
| 660 | |
| 661 | special_var_types: list[tuple[str, Type]] = [ |
| 662 | ("None", NoneType()), |
| 663 | # reveal_type is a mypy-only function that gives an error with |
| 664 | # the type of its arg. |
| 665 | ("reveal_type", AnyType(TypeOfAny.special_form)), |
| 666 | # reveal_locals is a mypy-only function that gives an error with the types of |
| 667 | # locals |
| 668 | ("reveal_locals", AnyType(TypeOfAny.special_form)), |
| 669 | ("True", bool_type), |
| 670 | ("False", bool_type), |
| 671 | ("__debug__", bool_type), |
| 672 | ] |
| 673 | |
| 674 | for name, typ in special_var_types: |
| 675 | v = Var(name, typ) |
| 676 | v._fullname = f"builtins.{name}" |
| 677 | file_node.names[name] = SymbolTableNode(GDEF, v) |
| 678 | |
| 679 | # |
| 680 | # Analyzing a target |
no test coverage detected