Skip to content

Commit

Permalink
Merge pull request #85 from kytos-ng/fix/unpack_dict_changed_size
Browse files Browse the repository at this point in the history
fix: `RuntimeError: dictionary changed size` when yielding class attributes
  • Loading branch information
viniarck authored May 25, 2023
2 parents c7de458 + 2fed7f7 commit 8242742
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Removed

Fixed
=====
- Made a shallow copy of ``__dict__`` when iterating over class attributes to fix potential ``RuntimeError``

Security

Expand Down
4 changes: 2 additions & 2 deletions pyof/foundation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def get_class_attributes(cls):
"""
#: see this method docstring for a important notice about the use of
#: cls.__dict__
for name, value in cls.__dict__.items():
for name, value in cls.__dict__.copy().items():
# gets only our (pyof) attributes. this ignores methods, dunder
# methods and attributes, and common python type attributes.
if GenericStruct._is_pyof_attribute(value):
Expand All @@ -605,7 +605,7 @@ def _get_instance_attributes(self):
generator: tuples with attribute name and value.
"""
for name, value in self.__dict__.items():
for name, value in self.__dict__.copy().items():
if name in map((lambda x: x[0]), self.get_class_attributes()):
yield (name, value)

Expand Down

0 comments on commit 8242742

Please sign in to comment.