Create a dummy variable using module-level __getattr__ return type. If not possible, return None. Note that multiple Var nodes can be created for a single name. We can use the from_module_getattr and the fullname attributes to check if two dummy Var nodes refer to t
(
self, getattr_defn: SymbolTableNode, name: str, fullname: str
)
| 6864 | return SymbolTableNode(GDEF, var) |
| 6865 | |
| 6866 | def create_getattr_var( |
| 6867 | self, getattr_defn: SymbolTableNode, name: str, fullname: str |
| 6868 | ) -> Var | None: |
| 6869 | """Create a dummy variable using module-level __getattr__ return type. |
| 6870 | |
| 6871 | If not possible, return None. |
| 6872 | |
| 6873 | Note that multiple Var nodes can be created for a single name. We |
| 6874 | can use the from_module_getattr and the fullname attributes to |
| 6875 | check if two dummy Var nodes refer to the same thing. Reusing Var |
| 6876 | nodes would require non-local mutable state, which we prefer to |
| 6877 | avoid. |
| 6878 | """ |
| 6879 | if isinstance(getattr_defn.node, (FuncDef, Var)): |
| 6880 | node_type = get_proper_type(getattr_defn.node.type) |
| 6881 | if isinstance(node_type, CallableType): |
| 6882 | typ = node_type.ret_type |
| 6883 | else: |
| 6884 | typ = AnyType(TypeOfAny.from_error) |
| 6885 | v = Var(name, type=typ) |
| 6886 | v._fullname = fullname |
| 6887 | v.from_module_getattr = True |
| 6888 | return v |
| 6889 | return None |
| 6890 | |
| 6891 | def lookup_fully_qualified(self, fullname: str) -> SymbolTableNode: |
| 6892 | ret = self.lookup_fully_qualified_or_none(fullname) |
no test coverage detected