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

Method defn_returns_none

mypy/checkexpr.py:732–752  ·  view source on GitHub ↗

Check if `defn` can _only_ return None.

(self, defn: SymbolNode | None)

Source from the content-addressed store, hash-verified

730 return False
731
732 def defn_returns_none(self, defn: SymbolNode | None) -> bool:
733 """Check if `defn` can _only_ return None."""
734 if isinstance(defn, FuncDef):
735 return isinstance(defn.type, CallableType) and isinstance(
736 get_proper_type(defn.type.ret_type), NoneType
737 )
738 if isinstance(defn, OverloadedFuncDef):
739 return all(self.defn_returns_none(item) for item in defn.items)
740 if isinstance(defn, Var):
741 typ = get_proper_type(defn.type)
742 if (
743 not defn.is_inferred
744 and isinstance(typ, CallableType)
745 and isinstance(get_proper_type(typ.ret_type), NoneType)
746 ):
747 return True
748 if isinstance(typ, Instance):
749 sym = typ.type.get("__call__")
750 if sym and self.defn_returns_none(sym.node):
751 return True
752 return False
753
754 def check_runtime_protocol_test(self, e: CallExpr) -> None:
755 for expr in mypy.checker.flatten(e.args[1]):

Callers 1

always_returns_noneMethod · 0.95

Calls 4

get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
allFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected