-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix "dictionary changed size during iteration" #6612
Conversation
Pull Request Test Coverage Report for Build 2340977036
π - Coveralls |
Hi @nyabkun, In order to review the change I first want to reproduce the crash, as I want to understand why this happens in the first place. The versions I tried this with are:
And
Can you give me the output of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add to what @DudeNr33 said, we would need a regression test before merging.
@DudeNr33 san, @Pierre-Sassoulas san, Thank you for the responseπ I'm running this command on Windows 10 Home - Powershell 7.2. C:\Ws\+python\manim-tutorials [main +10 ~0 -0 !]> pylint --version
pylint 2.13.8
astroid 2.11.5
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)]
C:\Ws\+python\manim-tutorials [main +10 ~0 -0 !]> $PSVersionTable
Name Value
---- -----
PSVersion 7.2.0
PSEdition Core
GitCommitId 7.2.0
OS Microsoft Windows 10.0.19044
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0β¦}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
C:\Ws\+python\manim-tutorials [main +10 ~0 -0 !]> pip list
Package Version
------------------- ---------
astroid 2.11.5
black 22.3.0
certifi 2021.10.8
charset-normalizer 2.0.12
click 8.1.3
click-default-group 1.2.2
cloup 0.13.1
colorama 0.4.4
colour 0.1.5
commonmark 0.9.1
cycler 0.11.0
decorator 5.1.1
dill 0.3.4
docutils 0.18.1
flake8 4.0.1
fonttools 4.33.3
glcontext 2.3.6
idna 3.3
isort 5.10.1
isosurfaces 0.1.0
kiwisolver 1.4.2
lazy-object-proxy 1.7.1
logilab-common 1.9.5
manim 0.15.2
ManimPango 0.4.1
mapbox-earcut 0.12.11
matplotlib 3.5.2
mccabe 0.6.1
moderngl 5.6.4
moderngl-window 2.4.1
multipledispatch 0.6.0
mypy-extensions 0.4.3
networkx 2.8
numpy 1.22.3
packaging 21.3
pathspec 0.9.0
Pillow 9.1.0
pip 22.1
plantweb 1.2.1
platformdirs 2.5.2
pycairo 1.21.0
pycodestyle 2.8.0
pydub 0.25.1
pyflakes 2.4.0
pyglet 1.5.23
Pygments 2.12.0
pylint 2.13.8
pyparsing 3.0.9
pyrr 0.10.3
python-dateutil 2.8.2
requests 2.27.1
rich 12.4.1
scipy 1.8.0
screeninfo 0.8
setuptools 58.1.0
six 1.16.0
skia-pathops 0.7.2
srt 3.5.2
tomli 2.0.1
tqdm 4.64.0
typing_extensions 4.2.0
urllib3 1.26.9
watchdog 2.1.7
wrapt 1.14.1
C:\Ws\+python\manim-tutorials [main +10 ~0 -0 !]> pyreverse -k -m y -o puml -p manim.camera manim.camera
parsing C:\ScoopG\apps\python\current\lib\site-packages\manim\camera\__init__.py...
parsing C:\ScoopG\apps\python\current\lib\site-packages\manim\camera\camera.py...
parsing C:\ScoopG\apps\python\current\lib\site-packages\manim\camera\mapping_camera.py...
parsing C:\ScoopG\apps\python\current\lib\site-packages\manim\camera\moving_camera.py...
parsing C:\ScoopG\apps\python\current\lib\site-packages\manim\camera\multi_camera.py...
parsing C:\ScoopG\apps\python\current\lib\site-packages\manim\camera\three_d_camera.py...
parsing C:\ScoopG\apps\python\current\lib\site-packages\manim\camera\__init__.py...
Traceback (most recent call last):
File "C:\ScoopG\apps\python\current\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\ScoopG\apps\python\current\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\ScoopG\apps\python\current\Scripts\pyreverse.exe\__main__.py", line 7, in <module>
File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\__init__.py", line 44, in run_pyreverse
PyreverseRun(argv or sys.argv[1:])
File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\pyreverse\main.py", line 213, in __init__
sys.exit(self.run(args))
File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\pyreverse\main.py", line 228, in run
diadefs = handler.get_diadefs(project, linker)
File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\pyreverse\diadefslib.py", line 219, in get_diadefs
diagrams = DefaultDiadefGenerator(linker, self).visit(project)
File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\pyreverse\utils.py", line 205, in visit
self.visit(local_node)
File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\pyreverse\utils.py", line 202, in visit
methods[0](node)
File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\pyreverse\diadefslib.py", line 151, in visit_module
self.linker.visit(node)
File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\pyreverse\utils.py", line 205, in visit
self.visit(local_node)
File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\pyreverse\utils.py", line 202, in visit
methods[0](node)
File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\pyreverse\inspector.py", line 177, in visit_classdef
for assignattrs in node.instance_attrs.values():
RuntimeError: dictionary changed size during iteration |
I did a little debugging and it seems that while looping through attributes, one more attribute was added to the I haven't looked that closely into the manim library, so I don't know how it's being added at this point. |
Thank you for the detailed response! I could reproduce this issue on my Windows laptop with
However, with Python 3.10.4 and pylint 2.13.8 I was not able to.
I have to dig a little deeper to see what is going on. |
Nevermind, could also reproduce it with the current pylint version when installing |
I will use this answer to note down what I could find out during debugging - will update it when I find out more.
In conclusion: I haven't succeeded to come up with a minimal example yet, though. |
Ok, I have a minimal example to reproduce the crash: Given two files in the same directory: # File tree.py
from monkey import Monkey
class Tree:
def __init__(self):
self.number_of_bananas = 5
self.inhabitant = Monkey("Steve") # This will trigger the evaluation of `monkey.py` # File monkey.py
class Monkey:
def __init__(self, name):
from tree import Tree
self.name = name
self.tree = Tree()
self.tree.has_tasty_bananas = True # This monkey patching will increase the number of items in instance_attrs for `Tree` When I run
After applying your fix, it works as intended. In order to use this as a functional test for |
Huge thanks for the detailed review, and the research π |
You're welcome! Once #6617 is merged, you can rebase and add a functional test for your issue:
It would also be great if you can add a |
Huge thanks again, @DudeNr33 san. I truly appreciate your kindness! I have followed the instructions for creating a Functional Test and a ChangeLog Entry. I did |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also looks good from my side! |
`pyreverse -k -m y -o puml -p manim.camera manim.camera` This command produced the following error. > File "C:\ScoopG\apps\python\current\lib\site-packages\pylint\pyreverse\inspector.py", line 177, in visit_classdef > for assignattrs in node.instance_attrs.values(): > RuntimeError: dictionary changed size during iteration --- ManimCE https://github.com/ManimCommunity/manim --- I'm new here and I don't fully understand the structure of the library. But at any rate, with this change, I could fix the problem.
@DudeNr33 san, Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Thank you for the contribution!
Thank you for examining the source code and presenting the test code! |
Type of Changes
Description
pyreverse -k -m y -o puml -p manim.camera manim.camera
This command produced the following error.
ManimCE
https://github.com/ManimCommunity/manim
manim 0.15.2
pylint 2.13.8
I'm new here and I don't fully understand the structure of the library.
But at any rate, with this change, I could fix the problem.