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

DictStack: RecursionError: maximum recursion depth exceeded on pypy3 #7

Closed
mgorny opened this issue Aug 12, 2021 · 9 comments
Closed

Comments

@mgorny
Copy link

mgorny commented Aug 12, 2021

>>>> import jaraco.collections
>>>> foo={'a': 1}
>>>> bar={'b': 2}
>>>> d = jaraco.collections.DictStack([foo, bar])
>>>> d['a']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pypy3.7/site-packages/jaraco/collections.py", line 596, in __getitem__
    for scope in reversed(self):
  File "/usr/lib/pypy3.7/site-packages/jaraco/collections.py", line 596, in __getitem__
    for scope in reversed(self):
  File "/usr/lib/pypy3.7/site-packages/jaraco/collections.py", line 596, in __getitem__
    for scope in reversed(self):
  [Previous line repeated 995 more times]
RecursionError: maximum recursion depth exceeded

I'll submit a dumb-ish PR shortly.

@mgorny
Copy link
Author

mgorny commented Aug 12, 2021

That said, I can't figure out how to run doctests. Apparently the built-in doctest module gets confused and runs tests from the built-in collections module, and pytest just reports a patch mismatch:

$ pypy3 -m pytest --doctest-modules jaraco/collections.py 
========================================================= test session starts =========================================================
platform linux -- Python 3.7.10[pypy-7.3.5-final], pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /tmp/jaraco.collections, configfile: pytest.ini
plugins: timeout-1.4.2, case-1.5.3, mock-3.6.1, localserver-0.5.0, expect-1.1.0, asyncio-0.15.1, forked-1.3.0, freezegun-0.4.2, metadata-1.8.0, requests-mock-1.9.3, subtests-0.5.0, betamax-0.8.1, pyfakefs-4.5.0, httpbin-1.0.0, shutil-1.7.0, virtualenv-1.7.0, xdist-2.3.0, cov-2.12.1, rerunfailures-10.1, flaky-3.7.0, xprocess-0.18.1, aiohttp-0.3.0, hypothesis-6.14.6
collected 0 items / 2 errors                                                                                                          

=============================================================== ERRORS ================================================================
_______________________________________________ ERROR collecting jaraco/collections.py ________________________________________________
/usr/lib/pypy3.7/site-packages/_pytest/runner.py:311: in from_call
    result: Optional[TResult] = func()
/usr/lib/pypy3.7/site-packages/_pytest/runner.py:341: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
/usr/lib/pypy3.7/site-packages/_pytest/doctest.py:532: in collect
    module = import_path(self.fspath)
/usr/lib/pypy3.7/site-packages/_pytest/pathlib.py:544: in import_path
    raise ImportPathMismatchError(module_name, module_file, path)
E   _pytest.pathlib.ImportPathMismatchError: ('collections', '/usr/lib/pypy3.7/lib-python/3/collections', PosixPath('/tmp/jaraco.collections/jaraco/collections.py'))
_______________________________________________ ERROR collecting jaraco/collections.py ________________________________________________
import file mismatch:
imported module 'collections' has this __file__ attribute:
  /usr/lib/pypy3.7/lib-python/3/collections
which is not the same as the test file we want to collect:
  /tmp/jaraco.collections/jaraco/collections.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
======================================================= short test summary info =======================================================
ERROR jaraco/collections.py - _pytest.pathlib.ImportPathMismatchError: ('collections', '/usr/lib/pypy3.7/lib-python/3/collections', ...
ERROR jaraco/collections.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================== 2 errors in 0.56s ==========================================================

@mgorny
Copy link
Author

mgorny commented Aug 12, 2021

Ok, managed to run them via adding jaraco/__init__.py with pkgutil-style namespace magic. However, I don't think this is something to put in tox.ini ;-).

mgorny added a commit to mgorny/jaraco.collections that referenced this issue Aug 12, 2021
Fix DictStack RecursionError on PyPy3 via converting self to a list
before iterating over it.  Apparently, iterating over DictStack on PyPy3
causes it to call __getitem__, leading to infinite recursion.

Fixes jaraco#7
@abravalheri
Copy link
Contributor

This issue seems to be the same one causing the latest version of setuptools to fail the CI checks:

https://github.com/pypa/setuptools/runs/4693827902?check_suite_focus=true

@abravalheri
Copy link
Contributor

This seems to have been solved in the latest version....

@jaraco
Copy link
Owner

jaraco commented Jun 9, 2022

That said, I can't figure out how to run doctests.

Yes, there's a known issue in pytest that it can't test modules in an implicit namespace if the module name matches another module. Maybe pytest-dev/pytest#8059 or one of the related issues. It means that many of the jaraco.* packages lose their testability.

@jaraco
Copy link
Owner

jaraco commented Jun 9, 2022

Unfortunately, I don't have PyPy on my platform (macOS on ARM with homebrew), so I'm unable to test the issue.

It does look like the issue was addressed in 9d39238.

@jaraco jaraco closed this as completed Jun 9, 2022
@mgorny
Copy link
Author

mgorny commented Jun 10, 2022

You can always add it to GHA test matrix. PyPy is surprisingly well supported, with all alphas and betas getting early support (and no fancy 'alpha' required like in cpython), i.e. right now pypy-3.7, pypy-3.8 and pypy-3.9.

@benjaoming
Copy link

title of this issue 🙈

@mgorny mgorny changed the title DickStack: RecursionError: maximum recursion depth exceeded on pypy3 DictStack: RecursionError: maximum recursion depth exceeded on pypy3 Jun 10, 2022
@mgorny
Copy link
Author

mgorny commented Jun 10, 2022

title of this issue see_no_evil

Fixed now. You gotta ask Freud about this typo.

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

Successfully merging a pull request may close this issue.

4 participants