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

Python 3.7.2 StopIteration with custom context #663

Closed
hardmooth opened this issue Apr 9, 2019 · 2 comments
Closed

Python 3.7.2 StopIteration with custom context #663

hardmooth opened this issue Apr 9, 2019 · 2 comments

Comments

@hardmooth
Copy link

Steps to reproduce

  1. unzip pylint_exc_stop_iteration.zip
  2. run pylint in python 3.7.2:
    python37 -m pylint pylint_exc_stop_iteration.py

Current behavior

me@the-host /some_path
$ python37 -m pylint pylint_exc_stop_iteration.py
Traceback (most recent call last):
  File "D:\Program Files\Python37\lib\site-packages\astroid\protocols.py", line 492, in _infer_context_manager
    enter = next(inferred.igetattr("__enter__", context=context))
StopIteration

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

Traceback (most recent call last):
  File "D:\Program Files\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "D:\Program Files\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Program Files\Python37\lib\site-packages\pylint\__main__.py", line 8, in <module>
    pylint.run_pylint()
  File "D:\Program Files\Python37\lib\site-packages\pylint\__init__.py", line 20, in run_pylint
    Run(sys.argv[1:])
  File "D:\Program Files\Python37\lib\site-packages\pylint\lint.py", line 1628, in __init__
    linter.check(args)
  File "D:\Program Files\Python37\lib\site-packages\pylint\lint.py", line 943, in check
    self._do_check(files_or_modules)
  File "D:\Program Files\Python37\lib\site-packages\pylint\lint.py", line 1075, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "D:\Program Files\Python37\lib\site-packages\pylint\lint.py", line 1158, in check_astroid_module
    walker.walk(ast_node)
  File "D:\Program Files\Python37\lib\site-packages\pylint\utils.py", line 1303, in walk
    self.walk(child)
  File "D:\Program Files\Python37\lib\site-packages\pylint\utils.py", line 1303, in walk
    self.walk(child)
  File "D:\Program Files\Python37\lib\site-packages\pylint\utils.py", line 1303, in walk
    self.walk(child)
  [Previous line repeated 2 more times]
  File "D:\Program Files\Python37\lib\site-packages\pylint\utils.py", line 1300, in walk
    cb(astroid)
  File "D:\Program Files\Python37\lib\site-packages\pylint\checkers\typecheck.py", line 844, in visit_attribute
    inferred = list(node.expr.infer())
  File "D:\Program Files\Python37\lib\site-packages\astroid\decorators.py", line 141, in raise_if_nothing_inferred
    yield from generator
  File "D:\Program Files\Python37\lib\site-packages\astroid\decorators.py", line 95, in wrapped
    res = next(generator)
  File "D:\Program Files\Python37\lib\site-packages\astroid\bases.py", line 137, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "D:\Program Files\Python37\lib\site-packages\astroid\util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "D:\Program Files\Python37\lib\site-packages\astroid\context.py", line 113, in cache_generator
    for result in generator:
  File "D:\Program Files\Python37\lib\site-packages\astroid\decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
  File "D:\Program Files\Python37\lib\site-packages\astroid\decorators.py", line 92, in wrapped
    generator = _func(node, context, **kwargs)
  File "D:\Program Files\Python37\lib\site-packages\astroid\inference.py", line 832, in infer_assign
    stmts = list(self.assigned_stmts(context=context))
  File "D:\Program Files\Python37\lib\site-packages\astroid\decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
  File "D:\Program Files\Python37\lib\site-packages\astroid\protocols.py", line 537, in with_assigned_stmts
    yield from _infer_context_manager(self, mgr, context)
RuntimeError: generator raised StopIteration

Expected behavior

me@the-host /some_path
$ python36 -m pylint pylint_exc_stop_iteration.py

-------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 9.33/10, +0.67)

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

$ python37 -c "from astroid import __pkginfo__; print(__pkginfo__.version)" 2.2.5

more Version information

me@the-host /some_path
$ python37 -m pip freeze | egrep "astroid|pylint"
astroid==2.2.5
pylint==2.3.1

me@the-host /some_path
$ python37 --version
Python 3.7.2
  • im on Windows 7
  • Error comes in Windows CMD as well
@hardmooth
Copy link
Author

thanks for the quick fix. Works as expected.

When is this going to be released?

@PCManticore
Copy link
Contributor

Thanks for testing! Probably around start or May as a final minor release. It won't be part of 1.9.x line though.

nelfin added a commit to nelfin/astroid that referenced this issue May 1, 2021
Ref pylint-dev#663. This test did not actually check for regression of the issue
fixed in 55076ca (i.e. it also passed on c87bea1 before the fix was
applied). Additionally, it over-specified the behaviour it was
attempting to check: whether the value returned from the context manager
was Uninferable was not directly relevant to the test, so when this
value changed due to unrelated fixes in inference, this test failed.
nelfin added a commit to nelfin/astroid that referenced this issue May 1, 2021
Ref pylint-dev#663. This test did not actually check for regression of the issue
fixed in 55076ca (i.e. it also passed on c87bea1 before the fix was
applied). Additionally, it over-specified the behaviour it was
attempting to check: whether the value returned from the context manager
was Uninferable was not directly relevant to the test, so when this
value changed due to unrelated fixes in inference, this test failed.
nelfin added a commit to nelfin/astroid that referenced this issue May 2, 2021
Ref pylint-dev#663. This test did not actually check for regression of the issue
fixed in 55076ca (i.e. it also passed on c87bea1 before the fix was
applied). Additionally, it over-specified the behaviour it was
attempting to check: whether the value returned from the context manager
was Uninferable was not directly relevant to the test, so when this
value changed due to unrelated fixes in inference, this test failed.
cdce8p added a commit to cdce8p/astroid that referenced this issue May 15, 2021
…h no returns

Squashed commit of the following:

commit 7ec6a68
Author: Andrew Haigh <hello@nelf.in>
Date:   Mon May 3 09:09:17 2021 +1000

    Update changelog

commit b50a7dd
Author: Andrew Haigh <hello@nelf.in>
Date:   Mon May 3 09:02:29 2021 +1000

    Update check of implicit return to ignore abstract methods

    Ref pylint-dev#485. To avoid additional breakage, we optionally extend is_abstract
    to consider functions whose body is any raise statement (not just raise
    NotImplementedError)

commit ff719c8
Author: Andrew Haigh <hello@nelf.in>
Date:   Sat May 1 12:19:52 2021 +1000

    Add check of __getitem__ signature to instance_getitem

commit 427d422
Author: Andrew Haigh <hello@nelf.in>
Date:   Sat May 1 11:45:27 2021 +1000

    Fix test definition of igetattr recursion and context_manager_inference

    Ref pylint-dev#663. This test did not actually check for regression of the issue
    fixed in 55076ca (i.e. it also passed on c87bea1 before the fix was
    applied). Additionally, it over-specified the behaviour it was
    attempting to check: whether the value returned from the context manager
    was Uninferable was not directly relevant to the test, so when this
    value changed due to unrelated fixes in inference, this test failed.

commit 8ec2b47
Author: Andrew Haigh <hello@nelf.in>
Date:   Sat Apr 24 09:16:16 2021 +1000

    Update FunctionDef.infer_call_result to infer None with no Returns

    Ref pylint-dev#485. If the function was inferred (unlike many compiler-builtins)
    and it contains no Return nodes, then the implicit return value is None.
nelfin added a commit to nelfin/astroid that referenced this issue May 24, 2021
Ref pylint-dev#663. This test did not actually check for regression of the issue
fixed in 55076ca (i.e. it also passed on c87bea1 before the fix was
applied). Additionally, it over-specified the behaviour it was
attempting to check: whether the value returned from the context manager
was Uninferable was not directly relevant to the test, so when this
value changed due to unrelated fixes in inference, this test failed.
nelfin added a commit to nelfin/astroid that referenced this issue May 24, 2021
Ref pylint-dev#663. This test did not actually check for regression of the issue
fixed in 55076ca (i.e. it also passed on c87bea1 before the fix was
applied). Additionally, it over-specified the behaviour it was
attempting to check: whether the value returned from the context manager
was Uninferable was not directly relevant to the test, so when this
value changed due to unrelated fixes in inference, this test failed.
nelfin added a commit to nelfin/astroid that referenced this issue May 24, 2021
Ref pylint-dev#663. This test did not actually check for regression of the issue
fixed in 55076ca (i.e. it also passed on c87bea1 before the fix was
applied). Additionally, it over-specified the behaviour it was
attempting to check: whether the value returned from the context manager
was Uninferable was not directly relevant to the test, so when this
value changed due to unrelated fixes in inference, this test failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants