fix ValueError in f_locals.pop('self') Python 3.13+

The error
ValueError: cannot remove local variables from FrameLocalsProxy

is caused by PEP 667 – Consistent views of namespaces
peps.python.org/pep-0667
implemented in Python 3.13
This commit is contained in:
Mark Zhitomirski
2025-10-31 00:13:17 +04:00
parent bc3b595cc3
commit 0cfde115ff
5 changed files with 14 additions and 7 deletions

View File

@@ -8,8 +8,9 @@ class Structure:
@staticmethod
def _init():
locs = sys._getframe(1).f_locals
self = locs.pop('self')
self = locs['self']
for name, val in locs.items():
if name == 'self': continue
setattr(self, name, val)
def __setattr__(self, name, value):

View File

@@ -9,8 +9,9 @@ class Structure:
@staticmethod
def _init():
locs = sys._getframe(1).f_locals
self = locs.pop('self')
self = locs['self']
for name, val in locs.items():
if name == 'self': continue
setattr(self, name, val)
def __setattr__(self, name, value):