This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
with-as should defer type to __enter__ #340
Comments
Is this blocking any with open('file.txt') as file:
file. |
Okay, maybe |
Ah, stops working with this full snippet: import contextlib
import typing
@contextlib.contextmanager
def cxt_manager() -> typing.Generator[str, None, None]:
yield "hello"
# with cxt_manager() as ob:
# ob
with open('a') as file:
file. |
B/c we don't specialize |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Take this example:
The type of
s
isstr
, becausenoop
yieldsx
, which isstr
.Another example (this one will raise AttributeError, but that's not important):
In both examples, we say that
s
is of typeContextManager
, which isn't the case. It would be better to determine the type of what comes afteras
via checking the context manager's__enter__
function return type: https://docs.python.org/3/reference/datamodel.html#object.__enter__The text was updated successfully, but these errors were encountered: