[New-bugs-announce] [issue46930] Iterating over cls.__dict__ in classmethod causes RuntimeError when printing __annotations__

Fabian Zills report at bugs.python.org
Sat Mar 5 10:33:42 EST 2022


New submission from Fabian Zills <fabian.zills at web.de>:

When iterating over __dict__ inside a classmethod, accessing __annotations causses RuntimeError: dictionary changed size during iteration.
This only seems to affect Python 3.10.x on a Ubuntu system.

The following can be used to reproduce this issue:

class ExampleCls:
    @classmethod
    def iter_cls(cls):
        for name, val in cls.__dict__.items():
            print(cls.__annotations__)


This can be fixed for this Example by calling  _ = cls.__annotations__ before iterating over the __dict__

----------
messages: 414582
nosy: PythonF
priority: normal
severity: normal
status: open
title: Iterating over cls.__dict__ in classmethod causes RuntimeError when printing __annotations__
type: crash
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46930>
_______________________________________


More information about the New-bugs-announce mailing list