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

Function accepts callable, but a typeshed custom Protocol was passed #18239

Open
Andrew-Chen-Wang opened this issue Dec 4, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@Andrew-Chen-Wang
Copy link

Bug Report

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

To Reproduce

I have some code like:

await asyncio.to_thread(
    shutil.rmtree, connector_folder, ignore_errors=False, onerror=None
)

But I'm getting mypy errors like

Argument 1 to "to_thread" has incompatible type "_RmtreeType"; expected "Callable[[Path, bool, None], None]"  [arg-type]

Expected Behavior

I would assume this is fine this callable is fine and this is passing.

Actual Behavior

Argument 1 to "to_thread" has incompatible type "_RmtreeType"; expected "Callable[[Path, bool, None], None]"  [arg-type]

Your Environment

  • Mypy version used: 1.11.0
  • Mypy command-line flags: pointing to pyproject.toml config
  • Mypy configuration options from mypy.ini (and other config files): ignore_missing_imports = true
  • Python version used: 3.12

I do NOT have Typeshed installed in my pip list, but I saw in typeshed that it may be bundled with mypy? Again I don't see it installed, but curious to know why this wouldn't work.

@Andrew-Chen-Wang Andrew-Chen-Wang added the bug mypy got something wrong label Dec 4, 2024
@TeamSpen210
Copy link
Contributor

Indeed, mypy (and all other type checkers) bundle typeshed, since it’s where they get type definitions for everything in the standard library.

I can see the problem though: In 3.12, the stub specifies onerror as not accepting None. Though that’s the default anyway, so you could just omit it, or use the replacement onexc.

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