You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mypy 0.930: regression: no longer keeping contextmanager generic return value #11852
@sobolevn I think it was a misunderstanding about send type in that PR -- there's no meaning of send types for @contextmanager since it only uses the yield type -- removing detach_callable fixes my snippet above
let me know if you want me to turn this into a patch:
diff --git a/mypy/plugins/default.py b/mypy/plugins/default.py
index 67587090e..c57c5f9a1 100644
--- a/mypy/plugins/default.py+++ b/mypy/plugins/default.py@@ -15,7 +15,6 @@ from mypy.types import (
from mypy.subtypes import is_subtype
from mypy.typeops import make_simplified_union
from mypy.checkexpr import is_literal_type_like
-from mypy.checker import detach_callable
class DefaultPlugin(Plugin):
@@ -192,12 +191,12 @@ def contextmanager_callback(ctx: FunctionContext) -> Type:
and isinstance(default_return, CallableType)):
# The stub signature doesn't preserve information about arguments so
# add them back here.
- return detach_callable(default_return.copy_modified(+ return default_return.copy_modified(
arg_types=arg_type.arg_types,
arg_kinds=arg_type.arg_kinds,
arg_names=arg_type.arg_names,
variables=arg_type.variables,
- is_ellipsis_args=arg_type.is_ellipsis_args))+ is_ellipsis_args=arg_type.is_ellipsis_args)
return ctx.default_return_type
diff --git a/test-data/unit/check-default-plugin.test b/test-data/unit/check-default-plugin.test
index fc9f132ab..6a89aa266 100644
--- a/test-data/unit/check-default-plugin.test+++ b/test-data/unit/check-default-plugin.test@@ -29,10 +29,9 @@ from contextlib import contextmanager
from typing import TypeVar, Generator
T = TypeVar('T')
-S = TypeVar('S')
@contextmanager
-def yield_id(item: T) -> Generator[T, S, None]:+def yield_id(item: T) -> Generator[T, None, None]:
yield item
reveal_type(yield_id) # N: Revealed type is "def [T] (item: T`-1) -> contextlib.GeneratorContextManager[T`-1]"
@@ -70,10 +69,9 @@ from contextlib import asynccontextmanager
from typing import TypeVar, AsyncGenerator
T = TypeVar('T')
-S = TypeVar('S')
@asynccontextmanager
-async def yield_id(item: T) -> AsyncGenerator[T, S]:+async def yield_id(item: T) -> AsyncGenerator[T, None]:
yield item
reveal_type(yield_id) # N: Revealed type is "def [T] (item: T`-1) -> typing.AsyncContextManager[T`-1]"
Activity
sobolevn commentedon Dec 27, 2021
Thanks, I will have a look! 👍
asottile commentedon Dec 27, 2021
@sobolevn I think it was a misunderstanding about send type in that PR -- there's no meaning of send types for
@contextmanagersince it only uses the yield type -- removingdetach_callablefixes my snippet abovelet me know if you want me to turn this into a patch:
work around python/mypy#11852
fix mypy errors and work around python/mypy#11852
sobolevn commentedon Dec 29, 2021
@asottile please, go ahead. Let's try this solution.
Can you also attach the failing case as a test?
asottile commentedon Dec 29, 2021
@sobolevn yep! done -- #11870
Fix regression when a contextmanager yields a generic (#11870)
Fix regression when a contextmanager yields a generic (#11870)
Revert "work around python/mypy#11852"
Revert "fix mypy errors and work around python/mypy#11852"
Fix regression when a contextmanager yields a generic (python#11870)
pypi-pre_commit: Autospec creation for update from version 2.16.0 to …
work around python/mypy#11852
Revert "work around python/mypy#11852"