Closed carlos-avila closed 4 years ago
Hey @carlos-avila, can you send me an example to demonstrate how the original code wasn't working properly, and how with your fix, it is?
Ah. The iteration bug appears to surface when Python 3.8 is used.
Before the suggested change:
# Virtual Environment with Python 3.7.7
(tmdb-3.7.7) % python -m unittest tests.test_discover
...
----------------------------------------------------------------------
Ran 3 tests in 3.694s
OK
# Virtual Environment with Python 3.8.3
(tmdb-3.8.3) % python -m unittest tests.test_discover
..E
======================================================================
ERROR: test_discover_tv_underscore (tests.test_discover.DiscoverTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/celia/python/tmdbsimple/tests/test_discover.py", line 44, in test_discover_tv_underscore
response = discover.tv(page=2,
File "/Users/celia/python/tmdbsimple/tmdbsimple/discover.py", line 170, in tv
for param in kwargs:
RuntimeError: dictionary keys changed during iteration
----------------------------------------------------------------------
Ran 3 tests in 1.838s
FAILED (errors=1)
After the suggested change:
# Virtual Environment with Python 3.7.7
(tmdb-3.7.7) % python -m unittest tests.test_discover
...
----------------------------------------------------------------------
Ran 3 tests in 3.694s
OK
# Virtual Environment with Python 3.8.3
(tmdb-3.8.3) % python -m unittest tests.test_discover
...
----------------------------------------------------------------------
Ran 3 tests in 3.615s
OK
It's necessary to create a copy of kwargs before modifying it. It wasn't processing the arguments properly and was returning unpredictable results.