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

A callable typed function is not recognised as a TypeVar-ed argument #17029

Closed
genglandaer opened this issue Mar 14, 2024 · 1 comment · Fixed by #17071
Closed

A callable typed function is not recognised as a TypeVar-ed argument #17029

genglandaer opened this issue Mar 14, 2024 · 1 comment · Fixed by #17071
Labels

Comments

@genglandaer
Copy link

genglandaer commented Mar 14, 2024

Bug Report

I give my function a typed Callable, I get an error:

To Reproduce

def type_guard(x: Any, type_check_func: Callable[[Any], TypeGuard[T]]) -> T:
      if not type_check_func(x):
              raise TypeError("failed type assetion")
          return x

def is_string(x: Any) -> TypeGuard[str]:
    return isinstance(x, str)

data = "helloworld"
val = type_guard(data, is_string)

Expected Behavior

Should not error

Actual Behavior

A function returning TypeVar should receive at least one argument containing the same TypeVar [type-var]
Your Environment

  • Mypy version used: 1.4.1
@genglandaer genglandaer added the bug mypy got something wrong label Mar 14, 2024
@JelleZijlstra
Copy link
Member

Still reproduces on 1.9.0: https://mypy-play.net/?mypy=latest&python=3.10&gist=bd80437034ccf2a3142a5dc74b1fb7b1

I imagine the code that produces that error doesn't know to look inside the TypeGuard. If so, this should be an easy fix.

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

Successfully merging a pull request may close this issue.

2 participants