Summary
Narrowing with callable() gives you a Top[(...) -> object] object. Calling it should return object, but if you intersect with some other nominal type you get Unknown instead.
from collections.abc import Callable
from typing import reveal_type
def resolve(value: str):
if callable(value):
reveal_type(value) # str & Top[(...) -> object]
value2 = value() # call-top-callable error
reveal_type(value2) # Unknown
def f(x: object):
if callable(x):
reveal_type(x) # Top[(...) -> object]
x2 = x() # call-top-callable error
reveal_type(x2) # object
https://play.ty.dev/e6030d22-2e5e-48af-9f3b-01b8e3532a22
Version
No response
Summary
Narrowing with
callable()gives you aTop[(...) -> object]object. Calling it should returnobject, but if you intersect with some other nominal type you getUnknowninstead.https://play.ty.dev/e6030d22-2e5e-48af-9f3b-01b8e3532a22
Version
No response