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

Mypy: Argument 3 to "to_thread" has incompatible type "Path"; expected "_StrOrBytesPathT" #13193

Closed
helltraitor opened this issue Jul 19, 2022 · 2 comments
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@helltraitor
Copy link

Bug Report

I was trying to make async wrapper over shutil.copyfile and met a problem:
Mypy: Argument 3 to "to_thread" has incompatible type "Path"; expected "_StrOrBytesPathT"

To Reproduce

import asyncio
import shutil

from pathlib import Path


async def aiocopy_file(src: Path, dst: Path) -> None:
    await asyncio.to_thread(shutil.copyfile, src, dst, follow_symlinks=False)
    #                                             ~~~

Expected Behavior

dst argument is acceptable for using (At least I didn't see any problems in code below and while using copyfile in console).
But this code passes check:

def copy(src: Path, dst: Path) -> None:
    shutil.copyfile(src, dst)

Actual Behavior

For some reason, MyPy says that third argument (which is second for shutil.copyfile) is wrong type.

Your Environment

  • Mypy version used: 0.971
  • Mypy command-line flags: I use external tool but doesn't provide any special arguments
  • Mypy configuration options from mypy.ini (and other config files): no file
  • Python version used: 3.10.4
  • Operating system and version: Windows 10 Pro (19044.1826 21H1)
  • PyCharm CE:
    • PyCharm 2022.1.3 (Community Edition)
    • Build #PC-221.5921.27, built on June 22, 2022
    • Runtime version: 11.0.15+10-b2043.56 amd64
    • VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

Warning
I'm not pro with mypy, so try to reproduce this bug and text me if you cannot for some reasons.

@helltraitor helltraitor added the bug mypy got something wrong label Jul 19, 2022
@AlexWaygood AlexWaygood added the topic-paramspec PEP 612, ParamSpec, Concatenate label Jul 20, 2022
@AlexWaygood
Copy link
Member

Here's a minimal repro of this problem (which reproduces on the master branch) that doesn't depend on the typeshed stubs for asyncio.to_thread or shutil.copyfile:

from typing import Callable, TypeVar
from typing_extensions import ParamSpec

P = ParamSpec("P")
T = TypeVar("T")

def higher_order(func: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T: ...
def identity(arg: T) -> T: ...
higher_order(identity, 'foo')  # error: Argument 2 to "higher_order" has incompatible type "str"; expected "T"

@AlexWaygood
Copy link
Member

Duplicate of #12278

@AlexWaygood AlexWaygood marked this as a duplicate of #12278 Jul 20, 2022
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
Development

No branches or pull requests

2 participants