Open jakebailey opened 6 years ago
Is this blocking any with ... as ...
block working?
with open('file.txt') as file:
file.
Not from what I can tell:
But my original example with the contextmanager decorator doesn't work (probably because we don't handle how the decorator operates for some reason).
Okay, maybe open
isn't the best example, because we could be "cheating" and copy from the left to the right without looking at __enter__
, which would work for anything open
returns, but the code should have been written and working: https://github.com/microsoft/python-language-server/blob/master/src/Analysis/Ast/Impl/Analyzer/Handlers/WithHandler.cs
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 Generator
in typing. Typing
specializations are not complete, #535.
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__