Protocol with property returning ContextManager fails validation #4034
Labels
addressed in next version
Issue is fixed and will appear in next published version
bug
Something isn't working
Describe the bug
When defining a Protocol with a
@property
that returns aContextManager
referencing the protocol itself, a concrete implementation fails to validate against this. If no@property
is involved, the issue goes away.To Reproduce
The error produced is:
Expected behavior
FooProp()
should be accepted as a valid argument foraccepts_fooprop_protocol()
VS Code extension or command-line
Tested with VS Code extension v1.1.274
Additional context
The real-world project is the SQLAlchemy typing stubs, where the following code fails to validate:
TypingAsyncSessionProtocol.no_autoflush
is a property returning a context manager.The work-around is to use
Self
from PEP 673 instead ofTypeVar()
s with bounds. However, PEP 673 support is not yet available in mypy.Another work-around is to drop the bounds from the typevars for
_FooPropProtocol
and_FooProp
.The text was updated successfully, but these errors were encountered: