pytest-dev / py

Python development support library (note: maintenance only)
MIT License
67 stars 106 forks source link

Please update apipkg to avoid iterating over a changing dictionary #218

Closed sinecode closed 3 years ago

sinecode commented 5 years ago

Using the bpython REPL when I import py I get the following error:

>>> import py
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    import py
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "/home/ceccoemi/Development/git/bpython/bpython/curtsiesfrontend/repl.py", line
 243, in load_module
    module = self.loader.load_module(name)
  File "/home/ceccoemi/Development/pyvenvs/venv3.7/lib/python3.7/site-packages/py/__in
it__.py", line 153, in <module>
    'Syslog'             : '._log.log:Syslog',
  File "/home/ceccoemi/Development/pyvenvs/venv3.7/lib/python3.7/site-packages/py/_ven
dored_packages/apipkg.py", line 63, in initpkg
    for module in sys.modules.values():
RuntimeError: dictionary changed size during iteration

In the py/_vendored_packages/apikpg.py module there is a loop over a dictionary that breaks the import mechanism in bpython using Python 3:

https://github.com/pytest-dev/py/blob/60f50bdcbca0ad3b66960d2bf6bb488f13e5c5fa/py/_vendored_packages/apipkg.py#L61-L65

The fix for this bug is very simple: simply convert the iterable sys.modules.values() in a list with list(sys.modules.values()) This bug was already fixed in the apipkg package with this pull request.

I didn't understand how you manage the apipkg module in this package, but I'd like to have this bug fixed because it makes pytest and py unusable in bpython.

I'm available to work on this changes, so please let me know.

blueyed commented 5 years ago

I assume it is handled through https://github.com/blueyed/py/blob/74e8a7191aec981a2bf6826b6519499359fb3b6e/tasks/vendoring.py - not sure how invoke works though myself.

blueyed commented 5 years ago

Maybe it should also not be vendored after all?!

Trevor16gordon commented 5 years ago

I am having this same issue. What is the status on this?

NeuroWinter commented 5 years ago

I am still getting this issue as well, is there any update on a fix?

christiantillich commented 4 years ago

I also see this issue. An update would be appreciated. Thanks.

zachliu commented 4 years ago

since pytest is also using py, same issue on pytest:

$ bpython
bpython version 0.19 on top of Python 3.7.4 /home/test/sandbox/.venv/bin/python
>>> import pytest
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    import pytest
  File "/home/test/sandbox/.venv/lib/python3.7/site-packages/pytest/__init__.py", line 6, in <module>
    from _pytest.assertion import register_assert_rewrite
  File "/home/test/sandbox/.venv/lib/python3.7/site-packages/_pytest/assertion/__init__.py", line 9, in <module>
    from _pytest.assertion import rewrite
  File "/home/test/sandbox/.venv/lib/python3.7/site-packages/_pytest/assertion/rewrite.py", line 22, in <module>
    from _pytest._io.saferepr import saferepr
  File "/home/test/sandbox/.venv/lib/python3.7/site-packages/_pytest/_io/__init__.py", line 4, in <module>
    from py.io import TerminalWriter as BaseTerminalWriter  # noqa: F401
  File "/home/test/sandbox/.venv/lib/python3.7/site-packages/py/_vendored_packages/apipkg.py", line 148, in __makeattr
    result = importobj(modpath, attrname)
  File "/home/test/sandbox/.venv/lib/python3.7/site-packages/py/_vendored_packages/apipkg.py", line 69, in importobj
    module = __import__(modpath, None, None, ['__doc__'])
  File "/home/test/sandbox/.venv/lib/python3.7/site-packages/py/__init__.py", line 153, in <module>
    'Syslog'             : '._log.log:Syslog',
  File "/home/test/sandbox/.venv/lib/python3.7/site-packages/py/_vendored_packages/apipkg.py", line 63, in initpkg
    for module in sys.modules.values():
RuntimeError: dictionary changed size during iteration
aristidebm commented 4 years ago

have the same issue. fix it please. thanks