Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TryStar.ExceptHandler incorrectly infers types of caught exceptions #2400

Open
AI0867 opened this issue Mar 17, 2024 · 0 comments
Open

TryStar.ExceptHandler incorrectly infers types of caught exceptions #2400

AI0867 opened this issue Mar 17, 2024 · 0 comments

Comments

@AI0867
Copy link

AI0867 commented Mar 17, 2024

Steps to reproduce

I'm reproducing this using pylint, as that's how I encountered the issue, and I found that the issue originates in astroid.

  1. Create the following test script: (test.py)
try:
    raise ExceptionGroup("group", [TypeError("error")])
except* TypeError as eg:
    for exc in eg.exceptions:
        print(f"Caught TypeError {exc}")
print("Handled all exceptions")
  1. Run the script python test.py:
Caught TypeError error
Handled all exceptions
  1. Run pylint -E test.py:
************* Module test
test.py:5:15: E1101: Instance of 'TypeError' has no 'exceptions' member (no-member)

The cause of this is that:

Current behavior

ExceptHandler infers the type of eg to be TypeError.

Expected behavior

ExceptHandler infers the type of eg to be (something along the lines of): ExceptionGroup[UnionException[TypeError]] where UnionException[T] = Union[ExceptionGroup[UnionException[T]], T]

In English: The named variable in the except* handler is of type ExceptionGroup, and this group contains one or more members that match the except* clause, possibly nested in further ExceptionGroups.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants