mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
1.1 KiB
1.1 KiB
except*
except*
is only available in Python 3.11 and later:
[environment]
python-version = "3.11"
except*
with BaseException
try:
help()
except* BaseException as e:
reveal_type(e) # revealed: BaseExceptionGroup[BaseException]
except*
with specific exception
try:
help()
except* OSError as e:
reveal_type(e) # revealed: ExceptionGroup[OSError]
except*
with multiple exceptions
try:
help()
except* (TypeError, AttributeError) as e:
reveal_type(e) # revealed: ExceptionGroup[TypeError | AttributeError]
except*
with mix of Exception
s and BaseException
s
try:
help()
except* (KeyboardInterrupt, AttributeError) as e:
reveal_type(e) # revealed: BaseExceptionGroup[KeyboardInterrupt | AttributeError]
Invalid except*
handlers
try:
help()
except* 3 as e: # error: [invalid-exception-caught]
reveal_type(e) # revealed: BaseExceptionGroup[Unknown]
try:
help()
except* (AttributeError, 42) as e: # error: [invalid-exception-caught]
reveal_type(e) # revealed: BaseExceptionGroup[AttributeError | Unknown]