-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
crash caused by unimplemented code feature #8695
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
Comments
In the description the 'dunders' are missing for entry() and exit() |
Could you please paste the full content of |
Cannot reproduce on pylint 2.17.4 / astroid 2.15.5. Please also provide the output of |
I hope this gives you all information that you need.
#! 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()) |
I cannot reproduce on python 3.10 nor 3.11, it seems it's specific to 3.12. |
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() |
Thank you for your effort |
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 output
Expected behavior
something about unsupported code or that the variable is None
Pylint version
OS / Environment
Windows, using Pycharm 2023.1.1
Additional dependencies
none
pylint-crash-2023-05-17-14-01-33.txt
The text was updated successfully, but these errors were encountered: