Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isinstance(_, Callable) reports [arg-type] #18796

Open
jorenham opened this issue Mar 12, 2025 · 2 comments
Open

isinstance(_, Callable) reports [arg-type] #18796

jorenham opened this issue Mar 12, 2025 · 2 comments
Labels
bug mypy got something wrong

Comments

@jorenham
Copy link

Bug Report

isinstance(_, collections.abc.Callable) is allowed at runtime, but is reported

(A clear and concise description of what the bug is.)

To Reproduce

from collections.abc import Callable
assert isinstance(int, Callable)

Expected Behavior

for isinstance(_, collections.abc.Callable) to behave identically to callable(_):

  • no error
  • _: T is narrowed to _: <callable subtype of T>

Actual Behavior

main.py:2: error: Argument 2 to "isinstance" has incompatible type "<typing special form>"; expected "_ClassInfo"  [arg-type]

https://mypy-play.net/?mypy=latest&python=3.13&gist=463e1edfbfc8cefc268fce8544b0b49b

@jorenham jorenham added the bug mypy got something wrong label Mar 12, 2025
@A5rocks
Copy link
Collaborator

A5rocks commented Mar 13, 2025

As a work around the callable builtin narrows. (You're probably aware though)

@jorenham
Copy link
Author

As a work around the callable builtin narrows. (You're probably aware though)

I'm indeed aware, but others might not, so it's good that you mention it 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants