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

crash caused by unimplemented code feature #8695

Closed
Pippin555 opened this issue May 17, 2023 · 7 comments
Closed

crash caused by unimplemented code feature #8695

Pippin555 opened this issue May 17, 2023 · 7 comments
Labels
Crash 💥 A bug that makes pylint crash python 3.12 Upstream Bug 🪲 Bug in a dependency of pylint that is not astroid

Comments

@Pippin555
Copy link

Bug description

I created a python class EntryExit that implements enter(...) and exit(...).
when I use
with EntryExit() as e_e:

I would assume that the variable e_e is instantiated, but that does not happen, e_e remains None

pylint crashes on this code
python causes an AttributeError

see also the uploaded file

Configuration

No response

Command used

.../pylint.exe tester.py

Pylint output

Exception on node <Call l.44 at 0x1fd8c99fc80> in file 'C:\Users\hsalo\source\repos\Buku Pintar\2020\Python_312\tester\tester.py'
Traceback (most recent call last):
  File "C:\Users\hsalo\source\repos\Buku Pintar\2020\Python_312\tester\venv\Lib\site-packages\astroid\decorators.py", line 143, in raise_if_nothing_inferred
    yield next(generator)
          ^^^^^^^^^^^^^^^
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\hsalo\source\repos\Buku Pintar\2020\Python_312\tester\venv\Lib\site-packages\pylint\utils\ast_walker.py", line 91, in walk
    callback(astroid)
  File "C:\Users\hsalo\source\repos\Buku Pintar\2020\Python_312\tester\venv\Lib\site-packages\pylint\checkers\base\basic_checker.py", line 713, in visit_call
    if utils.is_terminating_func(node):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hsalo\source\repos\Buku Pintar\2020\Python_312\tester\venv\Lib\site-packages\pylint\checkers\utils.py", line 2202, in is_terminating_func
    return True
           ^^^^
  File "C:\Users\hsalo\source\repos\Buku Pintar\2020\Python_312\tester\venv\Lib\site-packages\astroid\nodes\node_ng.py", line 171, in infer
    yield from self._infer(context=context, **kwargs)
  File "C:\Users\hsalo\source\repos\Buku Pintar\2020\Python_312\tester\venv\Lib\site-packages\astroid\decorators.py", line 149, in raise_if_nothing_inferred
    raise InferenceError(
astroid.exceptions.InferenceError: StopIteration raised without any error information.

Expected behavior

something about unsupported code or that the variable is None

Pylint version

python 3.12 (also on version 3.11)

OS / Environment

Windows, using Pycharm 2023.1.1

Additional dependencies

none
pylint-crash-2023-05-17-14-01-33.txt

@Pippin555 Pippin555 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 17, 2023
@Pippin555
Copy link
Author

In the description the 'dunders' are missing for entry() and exit()

@DanielNoord
Copy link
Collaborator

DanielNoord commented May 17, 2023

Could you please paste the full content of tester.py wihtin a code block?
You can open one with "```" and close it with the same tag. You'll need to remove the ".

@jacobtylerwalls
Copy link
Member

Cannot reproduce on pylint 2.17.4 / astroid 2.15.5.

Please also provide the output of pylint --version as requested in the bug template. Thanks.

@jacobtylerwalls jacobtylerwalls added Waiting on author Indicate that maintainers are waiting for a message of the author and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels May 17, 2023
@Pippin555
Copy link
Author

Pippin555 commented May 17, 2023

I hope this gives you all information that you need.
Environment: Pycharm 2023.1.2

pylint 2.17.4
astroid 2.15.5
Python 3.12.0a7 (tags/v3.12.0a7:b861ba4, Apr  4 2023, 16:33:41) [MSC v.1934 64 bit (AMD64)]
#! python3.12
# coding: utf8

""" try out some python code """

__author__ = 'Sihir'  # noqa
__copyright__ = "© Sihir 2023-2023 all rights reserved"  # noqa

from sys import exit as _exit
from sys import version


class EntryExit:
    """ example class that can be used in a 'with' construction """

    def __init__(self):
        """ initialize the class """
        print("__init__")

    def __enter__(self):
        """ with is used"""
        print("__enter__")

    def function(self) -> str:
        """ example function """
        assert self
        return "I am alive!"

    def __exit__(self, e_type, e_value, t_back):
        """ class is disposed """
        print(e_type)
        print(e_value)
        print(t_back)
        print("__exit__")


def test_1():
    """ first test """
    print('1 ----')
    try:
        with EntryExit() as e_e:
            # this fails because e_e is None
            # message from code inspection: 'cannot find reference 'function' in 'None'
            print(e_e.function())
            pass
        e_e = None
        assert e_e is None
    except AttributeError as exc:
        print(f'Exception: {str(exc)}')


def test_2():
    """ second test """
    print('2 ----')
    # this succeeds:
    with (e_e := EntryExit()):
        print(e_e.function())

    e_e = None
    assert e_e is None


def test_3():
    """ third test """
    print('3 ----')
    e_e = EntryExit()
    with e_e:
        print(e_e.function())

    e_e = None
    assert e_e is None


def main() -> int:
    """ main entry """
    print(version)

    test_1()
    test_2()
    test_3()

    return 0


if __name__ == '__main__':
    _exit(main())

@Pierre-Sassoulas Pierre-Sassoulas added Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine python 3.12 and removed Waiting on author Indicate that maintainers are waiting for a message of the author labels May 18, 2023
@Pierre-Sassoulas
Copy link
Member

I cannot reproduce on python 3.10 nor 3.11, it seems it's specific to 3.12.

@jacobtylerwalls jacobtylerwalls added Crash 💥 A bug that makes pylint crash Astroid Related to astroid Needs PR This issue is accepted, sufficiently specified and now needs an implementation Upstream Bug 🪲 Bug in a dependency of pylint that is not astroid and removed Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine Astroid Related to astroid Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels May 18, 2023
@jacobtylerwalls
Copy link
Member

This is an upstream issue in Python 3.12.0a7 and was fixed in python/cpython#103502.

Reproducer without pylint:

def reraise_stop_iteration():
    try:
        yield 0
        yield next(iter(range(0)))
    except StopIteration as si:
        raise ValueError from si

gen = reraise_stop_iteration()

def run():
    try:
        for _ in gen:
            return True
    except ValueError:
        print('Caught!')

    return False

run()
run()

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale May 18, 2023
@Pippin555
Copy link
Author

Thank you for your effort

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash python 3.12 Upstream Bug 🪲 Bug in a dependency of pylint that is not astroid
Projects
None yet
Development

No branches or pull requests

4 participants