Pylint: RecursionError: maximum recursion depth exceeded while calling a Python object

Created on 23 Dec 2019  路  11Comments  路  Source: PyCQA/pylint

Steps to reproduce


  1. demo.py:
import pandas as pd

def _postprocess_recorded_data(psu_gun_imon_df):
    ab = pd.to_datetime(psu_gun_imon_df['Date UTC'])
    date_utc = ab.dt #.round('S')
    return date_utc.round('S')

2.
used a lintme.sh script to lint it:

#!/bin/bash
set -e
set -x

pylint \
       --rcfile=${PYLINTRC:-${CONDA_PREFIX}/share/ims/pylintrc} \
       --load-plugins=site_python.pylint_checkers,pylint.extensions.check_docs,pylint.extensions.mccabe \
       demo.py'

Current behavior

./lintme.sh
RecursionError: maximum recursion depth exceeded while calling a Python object

Expected behavior

No linting issues

pylint --version output

pylint 2.4.4
astroid 2.3.3
Python 3.7.3

Most helpful comment

Having maximum recursions with pylint 2.3.1, 2.4.4. and also 2.6. Any suggestions on what I can do are greatly appreciated.

All 11 comments

I think this one is a duplicate of #3245.

Nope, #3245 didn't fix this issue.

The shell script provided by @ema-ava is not really needed to reproduce the issue.
I've just verified that the issue still persists with the master branches of astroid & pylint.

import pandas as pd

def get_date(data):
    date_utc = pd.to_datetime(data['Date UTC']).dt
    return date_utc.round('S')
$  pylint --version                                                                                                                                                    
pylint 2.5.0-dev1
astroid 2.4.0
Python 3.7.6 | packaged by conda-forge | (default, Jan  7 2020, 22:33:48) 
[GCC 7.3.0]

stderr of pylint issue3318.py:

Traceback (most recent call last):
  File "/home/thomas/miniconda/envs/py37/bin/pylint", line 7, in <module>
    exec(compile(f.read(), __file__, 'exec'))
  File "/home/thomas/gitrepos/pylint/bin/pylint", line 4, in <module>
    run_pylint()
  File "/home/thomas/gitrepos/pylint/pylint/__init__.py", line 23, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/thomas/gitrepos/pylint/pylint/lint.py", line 1770, in __init__
    linter.check(args)
  File "/home/thomas/gitrepos/pylint/pylint/lint.py", line 980, in check
    self._check_files(self.get_ast, self._iterate_file_descrs(files_or_modules))
  File "/home/thomas/gitrepos/pylint/pylint/lint.py", line 1009, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/home/thomas/gitrepos/pylint/pylint/lint.py", line 1035, in _check_file
    check_astroid_module(ast_node)
  File "/home/thomas/gitrepos/pylint/pylint/lint.py", line 1168, in check_astroid_module
    ast_node, walker, rawcheckers, tokencheckers
  File "/home/thomas/gitrepos/pylint/pylint/lint.py", line 1212, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/thomas/gitrepos/pylint/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/thomas/gitrepos/pylint/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/thomas/gitrepos/pylint/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/thomas/gitrepos/pylint/pylint/utils/ast_walker.py", line 74, in walk
    callback(astroid)
  File "/home/thomas/gitrepos/pylint/pylint/checkers/typecheck.py", line 895, in visit_attribute
    inferred = list(node.expr.infer())
  File "/home/thomas/gitrepos/astroid/astroid/decorators.py", line 141, in raise_if_nothing_inferred
    yield from generator
  File "/home/thomas/gitrepos/astroid/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/thomas/gitrepos/astroid/astroid/inference.py", line 229, in infer_call
    yield from callee.infer_call_result(caller=self, context=callcontext)
  File "/home/thomas/gitrepos/astroid/astroid/scoped_nodes.py", line 1681, in infer_call_result
    yield from returnnode.value.infer(context)
  File "/home/thomas/gitrepos/astroid/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/thomas/gitrepos/astroid/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/thomas/gitrepos/astroid/astroid/decorators.py", line 141, in raise_if_nothing_inferred
    yield from generator
....
RecursionError: maximum recursion depth exceeded

Hey Dear all,

I think this is a regression problem on Astroid side. It does not make recursion error when using astroid 2.2.5 as @netoarmando mentioned in #3245

Tested file: /tmp/pylint_error.py

import pandas as pd

def get_date(data):
    date_utc = pd.to_datetime(data['Date UTC']).dt
    return date_utc.round('S')

I get the same recursion error as you @thisch with that set-up:

# pylint --version
pylint 2.4.4
astroid 2.3.3
Python 3.7.4 (default, Aug 13 2019, 20:35:49) 
[GCC 7.3.0]

Also with that following set-up (previous version of pylint):

# pylint --version
pylint 2.3.1
astroid 2.3.3
Python 3.7.4 (default, Aug 13 2019, 20:35:49) 
[GCC 7.3.0]

But recursion error does not occur with previous version of astroid 2.2.5:

#  pylint --version
pylint 2.3.1
astroid 2.2.5
Python 3.7.4 (default, Aug 13 2019, 20:35:49) 
[GCC 7.3.0]

For which I happily get:

# pylint /tmp/pylint_error.py
************* Module pylint_error
/tmp/pylint_error.py:1:0: C0111: Missing module docstring (missing-docstring)
/tmp/pylint_error.py:3:0: C0111: Missing function docstring (missing-docstring)

-----------------------------------
Your code has been rated at 5.00/10

Thx @redsharpbyte for triaging this issue.
Sry, I should have mentioned in my previous comment that I already knew that downgrading astroid solved the problem. IMO the next step is to bisect the commit in astroid that lead to this regression. I guess that I have to write a simple script for this that does not depend on pylint but only the astroid API. Can someone help me with writing this script?

Hello @thisch, that regression started after https://github.com/PyCQA/astroid/commit/79d5a3a783cf0b5a729e4e467508e955a0cca55f and it was already fixed by this PR: https://github.com/PyCQA/astroid/pull/733.

Thanks for the details. That's advanced :)

Is the next release/tag of Astroid already planned ?
That would be _astroid-2.3.4_ I suppose
The first of this Happy New Year ! :)

This seems to have been fixed by PyCQA/astroid#733.

Having maximum recursions with pylint 2.3.1, 2.4.4. and also 2.6. Any suggestions on what I can do are greatly appreciated.

@dickreuter while waiting the bug are fixed, you may try to rise the value of the python recursion limit.

I'm really interested in https://github.com/PyCQA/pylint/issues/3318#issuecomment-597000767 .

Are new astroid and pylint releases expected?

@b-long yes new releases are expected soon. I can't tell more precisely when though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glmdgrielson picture glmdgrielson  路  3Comments

PCManticore picture PCManticore  路  3Comments

elirnm picture elirnm  路  3Comments

DGalt picture DGalt  路  3Comments

Hubro picture Hubro  路  3Comments