Skip to content

Commit

Permalink
Stop repeat inference attempt causing a RuntimeError in Python3.7
Browse files Browse the repository at this point in the history
Empty generators and next calls within a generator without a default argument
now cause a cascade effect which results in a RuntimeError.

Raise InferenceError instead of return None to avoid the above problem.

Close pylint-dev/pylint#2317
  • Loading branch information
brycepg committed Jul 20, 2018
1 parent 32c96a6 commit 46a15e1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ What's New in astroid 2.0.2?

Release Date: |TBA|

* Stop repeat inference attempt causing a RuntimeError in Python3.7

Close PyCQA/pylint#2317


What's New in astroid 2.0.1?
============================
Expand Down
2 changes: 1 addition & 1 deletion astroid/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def wrapped(node, context=None, _func=func, **kwargs):
if context is None:
context = contextmod.InferenceContext()
if context.push(node):
return None
raise exceptions.InferenceError(node=node)

yielded = set()
generator = _func(node, context, **kwargs)
Expand Down
31 changes: 31 additions & 0 deletions astroid/tests/unittest_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,37 @@ def _(self):
call.inferred()
self.assertEqual(cdef.col_offset, orig_offset)

def test_no_runtime_error_in_repeat_inference(self):
""" Stop repeat inference attempt causing a RuntimeError in Python3.7
See https://github.com/PyCQA/pylint/issues/2317
"""
code = """
class ContextMixin:
def get_context_data(self, **kwargs):
return kwargs
class DVM(ContextMixin):
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
return ctx
class IFDVM(DVM):
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
ctx['bar'] = 'foo'
ctx #@
return ctx
"""
node = extract_node(code)
result = node.inferred()
assert len(result) == 2
assert isinstance(result[0], nodes.Dict)
assert result[1] is util.Uninferable


def test_python25_no_relative_import(self):
ast = resources.build_file('data/package/absimport.py')
self.assertTrue(ast.absolute_import_activated(), True)
Expand Down

0 comments on commit 46a15e1

Please sign in to comment.