[ty] Fix more generics-related TODOs (#18062)

This commit is contained in:
Alex Waygood 2025-05-14 12:26:52 -04:00 committed by GitHub
parent 8104b1e83b
commit 0590b38214
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 21 deletions

View file

@ -22,9 +22,7 @@ except* BaseException as e:
try:
help()
except* OSError as e:
# TODO: more precise would be `ExceptionGroup[OSError]` --Alex
# (needs homogeneous tuples + generics)
reveal_type(e) # revealed: BaseExceptionGroup[BaseException]
reveal_type(e) # revealed: ExceptionGroup[OSError]
```
## `except*` with multiple exceptions
@ -33,9 +31,7 @@ except* OSError as e:
try:
help()
except* (TypeError, AttributeError) as e:
# TODO: more precise would be `ExceptionGroup[TypeError | AttributeError]` --Alex
# (needs homogeneous tuples + generics)
reveal_type(e) # revealed: BaseExceptionGroup[BaseException]
reveal_type(e) # revealed: ExceptionGroup[TypeError | AttributeError]
```
## `except*` with mix of `Exception`s and `BaseException`s
@ -44,8 +40,7 @@ except* (TypeError, AttributeError) as e:
try:
help()
except* (KeyboardInterrupt, AttributeError) as e:
# TODO: more precise would be `BaseExceptionGroup[KeyboardInterrupt | AttributeError]` --Alex
reveal_type(e) # revealed: BaseExceptionGroup[BaseException]
reveal_type(e) # revealed: BaseExceptionGroup[KeyboardInterrupt | AttributeError]
```
## Invalid `except*` handlers
@ -54,10 +49,10 @@ except* (KeyboardInterrupt, AttributeError) as e:
try:
help()
except* 3 as e: # error: [invalid-exception-caught]
reveal_type(e) # revealed: BaseExceptionGroup[BaseException]
reveal_type(e) # revealed: BaseExceptionGroup[Unknown]
try:
help()
except* (AttributeError, 42) as e: # error: [invalid-exception-caught]
reveal_type(e) # revealed: BaseExceptionGroup[BaseException]
reveal_type(e) # revealed: BaseExceptionGroup[AttributeError | Unknown]
```