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

ParamSpec appears to get lost with mock.patch() #18595

Closed
Dreamsorcerer opened this issue Feb 3, 2025 · 2 comments
Closed

ParamSpec appears to get lost with mock.patch() #18595

Dreamsorcerer opened this issue Feb 3, 2025 · 2 comments
Labels
bug mypy got something wrong topic-disallow-any The disallow-any-* family of flags

Comments

@Dreamsorcerer
Copy link
Contributor

Dreamsorcerer commented Feb 3, 2025

Bug Report

It appears that ParamSpec is used in typeshed (python/typeshed#10325), but when using --disallow-any-decorated it seems to be complaining that the parameters are gone.

To Reproduce

from unittest import mock

@mock.patch("aiohttp.connector.ClientRequest")
def test_connect(foo: int) -> None:
    ...

Actual Behavior

error: Type of decorated function contains type "Any"
("Callable[..., None]")  [misc]
    def test_connect(foo: int) -> None:

Your Environment

  • Mypy version used: 1.14.1
  • Mypy command-line flags: --disallow-any-decorated
  • Python version used: 3.9
@Dreamsorcerer Dreamsorcerer added the bug mypy got something wrong label Feb 3, 2025
@sterliakov sterliakov added topic-paramspec PEP 612, ParamSpec, Concatenate topic-disallow-any The disallow-any-* family of flags labels Feb 4, 2025
@sterliakov
Copy link
Collaborator

For reference, the patch signature without new= argument does not use ParamSpec. However, this error should likely be improved indeed, as there's nothing end users can do about it...

Resolution site:

@overload
def __call__(
self,
target: str,
*,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch_default_new: ...

Definition site with explanatory comment:

class _patch_default_new(_patch[MagicMock | AsyncMock]):
@overload
def __call__(self, func: _TT) -> _TT: ...
# Can't use the following as ParamSpec is only allowed as last parameter:
# def __call__(self, func: Callable[_P, _R]) -> Callable[Concatenate[_P, MagicMock], _R]: ...
@overload
def __call__(self, func: Callable[..., _R]) -> Callable[..., _R]: ...

@sterliakov sterliakov removed the topic-paramspec PEP 612, ParamSpec, Concatenate label Feb 4, 2025
@Dreamsorcerer
Copy link
Contributor Author

Ah, I see. Not going to work then.

@Dreamsorcerer Dreamsorcerer closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2025
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-disallow-any The disallow-any-* family of flags
Projects
None yet
Development

No branches or pull requests

2 participants