Skip to content

Commit 083e185

Browse files
read out class.__dict__ to avoid concurrent modification (#310)
Fix `RuntimeError: dictionary changed size during iteration` in `ParserDispatchMixin._iter_class_members` when handling a class whose `__dict__` is updated by `getattr`. Fix is to read out `__dict__` keys into a list then iter. Resolves #309. --------- Signed-off-by: htruscott <harrison@harriscott.net> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 89b3b9c commit 083e185

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

pybind11_stubgen/parser/mixins/parse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def _iter_class_members(self, class_: type):
7777
# Iterate __dict__ keys for definition order, but resolve values
7878
# through getattr() so descriptors (staticmethod, properties, etc.)
7979
# are properly unwrapped — matching inspect.getmembers() semantics.
80-
for name in class_.__dict__:
80+
names = list(class_.__dict__)
81+
for name in names:
8182
seen.add(name)
8283
try:
8384
value = getattr(class_, name)

0 commit comments

Comments
 (0)