MCPcopy Create free account
hub / github.com/python/mypy / always_returns_none

Method always_returns_none

mypy/checkexpr.py:710–730  ·  view source on GitHub ↗

Check if `node` refers to something explicitly annotated as only returning None.

(self, node: Expression)

Source from the content-addressed store, hash-verified

708 return None
709
710 def always_returns_none(self, node: Expression) -> bool:
711 """Check if `node` refers to something explicitly annotated as only returning None."""
712 if isinstance(node, RefExpr):
713 if self.defn_returns_none(node.node):
714 return True
715 if isinstance(node, MemberExpr) and node.node is None: # instance or class attribute
716 typ = get_proper_type(self.chk.lookup_type(node.expr))
717 if isinstance(typ, Instance):
718 info = typ.type
719 elif isinstance(typ, CallableType) and typ.is_type_obj():
720 ret_type = get_proper_type(typ.ret_type)
721 if isinstance(ret_type, Instance):
722 info = ret_type.type
723 else:
724 return False
725 else:
726 return False
727 sym = info.get(node.name)
728 if sym and self.defn_returns_none(sym.node):
729 return True
730 return False
731
732 def defn_returns_none(self, defn: SymbolNode | None) -> bool:
733 """Check if `defn` can _only_ return None."""

Callers 1

visit_call_expr_innerMethod · 0.95

Calls 6

defn_returns_noneMethod · 0.95
get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
lookup_typeMethod · 0.45
is_type_objMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected