Skip to content

Call to str & Top[Callable[..., object]] results in Unknown instead of object #3617

@jelle-openai

Description

@jelle-openai

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions