Open gszabo opened 1 year ago
+1
pylint 3.2.5
astroid 3.2.2
Python 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 14.0.1 20240411 (Red Hat 14.0.1-0)]
def main():
try:
raise ExceptionGroup()
except ExceptionGroup as exc_group:
for exc in exc_group.exceptions:
print(exc)
repro.py:5:19: E1133: Non-iterable value exc_group.exceptions is used in an iterating context (not-an-iterable)
Not clear on root cause; mypy seems to tolerate this construct. Should I go digging?
If you have the time to do so, yes please! I think this is clearly a bug.
It's a tuple...
>>> try:
... raise ExceptionGroup('', [TypeError(), TypeError()])
... except ExceptionGroup as eg:
... print(type(eg.exceptions))
...
<class 'tuple'>
But astroid think's it's a class:
>>> from astroid import extract_node
>>> exc = extract_node("""
... try:
... raise ExceptionGroup('', [TypeError(), TypeError()])
... except ExceptionGroup as eg:
... eg.exceptions #@
...
... """)
>>> exc
<Attribute.exceptions l.5 at 0x102675090>
>>> exc.inferred()
[<ClassDef.exceptions l.0 at 0x1015b57c0>]
@jnsnow you might want to look into #2333.
My guess is that here we need to instantiate a new ExceptionGroupInstance
.
Bug description
hello.py
Configuration
No response
Command used
Pylint output
Expected behavior
I would expect pylint to accept this code as correct.
ExceptionGroup.exceptions
is a tuple, which is an iterable type.If I run the code with
python hello.py
, I get no errors and the messages of the two exception instances:Pylint version
OS / Environment
Ubuntu 22.04
Additional dependencies