SylvainDe / DidYouMean-Python

Module to have suggestions in case of errors (NameError, AttributeError, etc).
MIT License
120 stars 15 forks source link

`Maximum recursion depth exceeded` on Pypy #22

Closed SylvainDe closed 7 years ago

SylvainDe commented 7 years ago

I have the following error:

======================================================================
ERROR: test_unbound_global (didyoumean_sugg_tests.UnboundLocalErrorTests)
Should be global nb.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/SylvainDe/DidYouMean-Python/didyoumean/didyoumean_sugg_tests.py", line 700, in test_unbound_global
    self.throws(bad_code, UNBOUNDLOCAL)
  File "/home/travis/build/SylvainDe/DidYouMean-Python/didyoumean/didyoumean_sugg_tests.py", line 302, in throws
    get_suggestions_for_exception(value, traceback))
  File "/home/travis/build/SylvainDe/DidYouMean-Python/didyoumean/didyoumean_internal.py", line 302, in suggest_name_as_name_typo
    for name in get_close_matches(name, objdict.keys()):
  File "/home/travis/build/SylvainDe/DidYouMean-Python/didyoumean/didyoumean_internal.py", line 78, in get_close_matches
    for w in difflib.get_close_matches(word, possibilities, 3, 0.7)
  File "/opt/python/pypy-5.3.1/lib-python/2.7/difflib.py", line 738, in get_close_matches
    s.set_seq1(x)
  File "/opt/python/pypy-5.3.1/lib-python/2.7/difflib.py", line 256, in set_seq1
    self.a = a
RuntimeError: maximum recursion depth exceeded

when running the unit test on Travis. It does not seem related to the new changes performed.

This seems to affect:

$ python --version
Python 2.7.10 (7e8df3df9641, Jun 14 2016, 13:58:02)
[PyPy 5.3.1 with GCC 4.8.2]

$ python --version
Python 2.7.10 (7e8df3df9641, Jun 14 2016, 13:58:02)
[PyPy 5.3.1 with GCC 4.8.2]

but not:

$ python --version
Python 3.2.5 (b2091e973da6, Oct 19 2014, 18:29:55)
[PyPy 2.4.0 with GCC 4.6.3]

Looking for "pypy maximum recursion depth exceeded travis" in Google shows other similar looking errors. To be investigated.

ghost commented 7 years ago

@SylvainDe on PyPy 5.6 this works for me (no recursion error)

ghost commented 7 years ago

@SylvainDe you can use PyPy 5.6 on travis

SylvainDe commented 7 years ago

Hello @TiberiumPY , I have no idea how you stumbled open this issue but many thanks for your input :-D. I'll give it a try asap (do you reckon I should use pypy-5.6 as a Python version). In any case, I do not quite understand why this used to work but doesn't anymore...

ghost commented 7 years ago

@SylvainDe can you give example code which raises an error on PyPy 5.3 ? (yeah, I ran tests and everything is fine, just to be 100% sure)

SylvainDe commented 7 years ago

@TiberiumPY I haven't run the tests locally yet. However, I had setup the continuous integration on Travis to run on as many platforms as possible as my code relies on parts that are likely to fail from one implementation to another ("parsing" of error messages, code introspection, etc).

In any case, the failure can be observed on the job logs on https://travis-ci.org/SylvainDe/DidYouMean-Python . For instance:

SylvainDe commented 7 years ago

For the record, I had a similar issue a few days ago and restarting the job did fix it. I haven't managed to find the logs for that run/re-run yet.

SylvainDe commented 7 years ago

This is driving me crazy. Removing passing test cases makes the issue disappear...

ghost commented 7 years ago

@SylvainDe why are you doing this? PyPy 5.3 is an old version

SylvainDe commented 7 years ago

@TiberiumPY To be fair, I do not know much about the different PyPy versions. I've just set up my travis.yml file ( https://github.com/SylvainDe/DidYouMean-Python/blob/master/.travis.yml ) to run on all the versions I've found on https://docs.travis-ci.com/user/languages/python/ because I didn't know better... At the moment, I've changed the config to allow failures on the PyPy configs but I'd like to understand what's going on (and fix it and/or open an issue in the relevant project).

SylvainDe commented 7 years ago

I've tried (unsuccessfully) to add PyPy 5.6 in the Travis config :(

ghost commented 7 years ago

@SylvainDe you need to add manual config for latest pypy

ghost commented 7 years ago

@SylvainDe or use this: https://github.com/frol/flask-restplus-server-example/blob/master/.travis.yml

just change 5.4.1 with 5.6.0

SylvainDe commented 7 years ago

@TiberiumPY Thank you so much, I'll try this asap :-)

ghost commented 7 years ago

@SylvainDe https://travis-ci.org/SylvainDe/DidYouMean-Python/jobs/187717214

no recursion error anymore (seems just PyPy guys raised max depth from 100 to 1000)

SylvainDe commented 7 years ago

Indeed, thanks for your help! (It is surprising that adding/removing unrelated successful tests affects how deep we go into the calls)

ghost commented 7 years ago

@SylvainDe tests pass! BTW, maybe you can remove PyPy from allowed failures?

ghost commented 7 years ago

@SylvainDe and remove PyPy -5 3.1 completely

SylvainDe commented 7 years ago

@TiberiumPY Sure, will do! Btw, do you know if using the same technique I'd be able to run on multiple version of PyPy? The fact that changing from one version to another was useful to detect a new issue (cf https://github.com/SylvainDe/DidYouMean-Python/commit/2c040f9268a9feff249b263219bd005ecf14bc8f ) proves that it'd probably help me to run the code on most versions of PyPy released.

ghost commented 7 years ago

@SylvainDe probably - yes This script uses "pyenv", so you can use all versions supported by pyenv

ghost commented 7 years ago

@SylvainDe these are all pypy versions supported by pyenv

SylvainDe commented 7 years ago

@TiberiumPY Thanks! Did you forget a link or a list of versions ?

ghost commented 7 years ago

@SylvainDe ah, yes! https://paste.pound-python.org/show/s9ZtjUcXvaLSoigIFYhf/

SylvainDe commented 7 years ago

@TiberiumPY Wahoo, thank you again! I'll try to pick a relevant subset and put this in my travis.yml file.

SylvainDe commented 7 years ago

Also I've just realised the reason why the script maybe failing: a different test used to set a particular recursion limit in order to reach the limit easily. I would probably make sense to save the original value and reset it.

SylvainDe commented 7 years ago

@TiberiumPY I have the feeling I have solved the issue and thanks to your help gone a bit further so thanks again for the suggestions!

SylvainDe commented 7 years ago

Note to myself : this issue came back for no obvious reason.

https://travis-ci.org/SylvainDe/DidYouMean-Python/jobs/258923496 Job #807.13
$ python --version
Python 2.7.10 (7e8df3df9641, Jun 14 2016, 13:58:02)
[PyPy 5.3.1 with GCC 4.8.2]
OK

====================================================================================

https://travis-ci.org/SylvainDe/DidYouMean-Python/jobs/259141829 Job #808.13
$ python --version
Python 2.7.10 (7e8df3df9641, Jun 14 2016, 13:58:02)
[PyPy 5.3.1 with GCC 4.8.2]

It was fixed with an adaptation of the original fix : https://github.com/SylvainDe/DidYouMean-Python/commit/78c0ba07585daa52b87ccfbdd5ead2732efa11a7 .