-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotationstopic-protocols
Description
Bug Report
Regression on type inference found in aiohttp:master.
Seems like the regression may be related to inheriting from Any (which mypy complains about, but is done in typeshed regardless, and has been for many years).
To Reproduce
This is a fairly minimal reproducer of the issue:
from typing import Any, Generic, Protocol, TypeVar
#from unittest.mock import Mock
_T = TypeVar("_T", covariant=True)
class Mock(Any):
def __init__(self, **kwargs: Any) -> None: ...
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
class _Factory(Protocol[_T]):
def __call__(self, **kwargs: Any) -> _T: ...
class TraceConfig(Generic[_T]):
def __init__(self, trace_config_ctx_factory: _Factory[_T]) -> None:
...
t = TraceConfig(Mock(return_value="foo"))
1.15 Behavior
(First error disappears if we actually import Mock.)
test.py:6: error: Class cannot subclass "Any" (has type "Any") [misc]
Found 1 error in 1 file (checked 1 source file)
1.16 Behavior
test.py:6: error: Class cannot subclass "Any" (has type "Any") [misc]
test.py:19: error: Need type annotation for "t" [var-annotated]
Found 2 errors in 1 file (checked 1 source file)
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotationstopic-protocols