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
importasyncioclassWorkingExample:
asyncdef__aenter__(self) ->None: ...
asyncdef__aexit__(self, *dont_care: object) ->None: ...
def__enter__(self) ->None: ...
def__exit__(self, *dont_care: object) ->None: ...
classAsyncInvisiblyBrokenExample:
asyncdef__aenter__(self) ->None: ...
def__aexit__(self, *dont_care: object) ->None: ... # Ideally, this should be an error too, incompatible with data modeldef__enter__(self) ->None: ...
def__exit__(self) ->None: ... # Ideally, this should be an error too, incompatible with data modelclassVisiblyBrokenExample:
def__aenter__(self) ->None: ... # Ideally, this should be an error too, incompatible with data modeldef__aexit__(self, *dont_care: object) ->None: ... # Ideally, this should be an error too, incompatible with data modeldef__enter__(self) ->None: ...
def__exit__(self) ->None: ...
classAlsoInVisiblyBroken:
def__enter__(self) ->None: ...
if__name__=="__main__":
works=WorkingExample()
visibly_broken=VisiblyBrokenExample()
async_invisbly_broken=AsyncInvisiblyBrokenExample()
asyncdefamain() ->None:
asyncwithworks:
...
asyncwithvisibly_broken:
# pyright detects None is not Awaitable (correctly identified issue)# however the error message is incorrect, as it claims `__await__` isn't present
...
asyncwithasync_invisbly_broken:
# pyright does not detect that `__aexit__` has the wrong type
...
withworks:
withvisibly_broken: # pyright detects this, but the error message is misleading# claims AsyncInvisiblyBroken does not implement `__exit__`, when it does, just incorrectly# it does not satisfy the runtime requirements of being a context manager as a result,# so the error is correct, but the message doesn't identify the actual issue.withasync_invisbly_broken: # same as above# in addition though, this shows the asymmetery with the async with above# not being caught. asyncio.run(amain())
This was discovered while typing some previously private code for public use with N:M concurrency for use with freethreading python builds.
edit: ignore the definition of AlsoInVisiblyBroken, it was there to demonstrate things that ended up redundant and couldd have been removed.
The text was updated successfully, but these errors were encountered:
Describe the bug
Context manager handling is inconsistent, and where issues with it are detected, the error messages do not correctly identify the root cause
Code or Screenshots
Code sample in pyright playground
This was discovered while typing some previously private code for public use with N:M concurrency for use with freethreading python builds.
edit: ignore the definition of
AlsoInVisiblyBroken
, it was there to demonstrate things that ended up redundant and couldd have been removed.The text was updated successfully, but these errors were encountered: