Skip to content

False type inference: no-member in except* #9056

@rkupke

Description

@rkupke

Bug description

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 30 11:15:39 2023
"""

# pylint: disable=W0104,W0107,C0115,C0199,C0116,C0103,W0106

import typing


try:
    try:
        ex_list = [ValueError("a"), ValueError("b"),  Exception("c")]
        raise ExceptionGroup("exceptions!", ex_list)
    except* ValueError as exc:
        print(repr(exc))

        typing.reveal_type(exc)
        assert isinstance(exc, ExceptionGroup)
        assert hasattr(exc, "message")
        assert hasattr(exc, "exceptions")

        # E1101:no-member: 25,8: Instance of 'ValueError' has no 'message' member
        exc.message

        # E1101:no-member: 28,8: Instance of 'ValueError' has no 'exceptions' member
        exc.exceptions

        # E1101:no-member: 31,8: Instance of 'ValueError' has no 'message' member
        typing.cast(ExceptionGroup, exc).message

        pass
except ExceptionGroup as exc:
    print(repr(exc))
    exc.message  # this works
    exc.exceptions
    pass

Configuration

No response

Command used

pylint Schreibtisch/test.py

Pylint output

************* Module test
Schreibtisch/test.py:25:8: E1101: Instance of 'ValueError' has no 'message' member (no-member)
Schreibtisch/test.py:28:8: E1101: Instance of 'ValueError' has no 'exceptions' member (no-member)
Schreibtisch/test.py:31:8: E1101: Instance of 'ValueError' has no 'message' member (no-member)

------------------------------------------------------------------
Your code has been rated at 2.50/10 (previous run: 2.50/10, +0.00)

Expected behavior

Type of exc should be inferred as ExceptionGroup

Pylint version

pylint 2.17.4
astroid 2.15.6
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]

OS / Environment

uname -a
Linux odysseus 6.1.0-12-arm64 #1 SMP Debian 6.1.52-1 (2023-09-07) aarch64 GNU/Linux

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the codeNeeds astroid updateNeeds an astroid update (probably a release too) before being mergableinferencepython 3.11

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions