__exit__ with Exception instead of BaseException
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 516
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the Bug
Minimal repro:
```python
from types import TracebackType
class DeferredImport:
def __enter__(self) -> "DeferredImport":
return self
def __exit__(
self,
exc_type: type[Exception] | None,
exc_value: Exception | None,
traceback: TracebackType | None,
) -> bool | None:
return None
def try_import() -> DeferredImport:
ctx = DeferredImport()
with ctx: # Pyrefly: Cannot use DeferredImport as a context manager
pass
return ctx
```
Technically speaking Pyrefly is correct. But it seems like all other type checkers would not complain about this by default. Perhaps we should downgrade the severity to warning?
Also: async context manager's `__aexit__` shares the same issue
### Sandbox Link
https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcfHRDcbpQ3QCqWoAxjGxCA1r2YwAOulmzBUVHDh0AIjDAxKlGJgCSHLg0Sy65upk10A%2BjZjoG2uwAo4MKGACUdALQA%2BOmkQDS0dPUNObmDTdAt4ul0GAFdKOPdPeTiLKzBbe3wIBlczBPMMsAAaUrKYfEEbJhZERikAbQBRephiBghcdABdOgAfOgA5AZhq7Nr6mwA3VChkmBau4V7%2BuLHJ9GmahIYBYVFBMRb%2BIRFxSRZRiamZ%2BJ8AujxcKAe9tcP4pNScR%2BWVkuUYlFINnYUQYLlegVC2l0BiM3Fi8UEDHwdAAvOpNEiIqjYV5DgB3IoACzomPwLToAGI6AAFUi6MBQUgtADCGHQuB4yXc%2BLCyMixjoyklNIGTnwPBoGFQAHNtH8LMRlHBDgC0jSsSBKiBkn0oHASORECAmQBVU1FUh0MDJdCY7bauRYaxgLiK4roZI0bDaFx0tiOeF0ODHdEWXVxMDBcaB4OUFrAfAAX2CskNIDI7M5hAYtCgFCZrMLjrQWDw2MEA0gytSqD6A0IsiZAGUYDA6JSGAxiHBEAB6UcFzRFrjK0cOUeYXCCOCjhvoJsttvoUdOriSpbQVDYWAy9cQZsCLd0XBbAbm2RkBiUga%2BBbaODbXFBEAAZkIAEYACYc3QEBMyNIQ%2BjfAAxaAYAoGscAIC0wKAA
### (Only applicable for extension issues) IDE Information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.