Merge pull request #91 from mz0/PEP-667
fix ValueError in f_locals.pop('self') Python 3.13+
This commit is contained in:
commit
a55856bf89
@ -61,8 +61,9 @@ and class definitions:
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
>>> def _init(locs):
|
>>> def _init(locs):
|
||||||
self = locs.pop('self')
|
self = locs['self']
|
||||||
for name, val in locs.items():
|
for name, val in locs.items():
|
||||||
|
if name == 'self': continue
|
||||||
setattr(self, name, val)
|
setattr(self, name, val)
|
||||||
|
|
||||||
>>> class Stock:
|
>>> class Stock:
|
||||||
@ -96,8 +97,9 @@ frame hacking. Try this variant of the `_init()` function:
|
|||||||
>>> import sys
|
>>> import sys
|
||||||
>>> def _init():
|
>>> def _init():
|
||||||
locs = sys._getframe(1).f_locals # Get callers local variables
|
locs = sys._getframe(1).f_locals # Get callers local variables
|
||||||
self = locs.pop('self')
|
self = locs['self']
|
||||||
for name, val in locs.items():
|
for name, val in locs.items():
|
||||||
|
if name == 'self': continue
|
||||||
setattr(self, name, val)
|
setattr(self, name, val)
|
||||||
>>>
|
>>>
|
||||||
```
|
```
|
||||||
@ -135,8 +137,9 @@ class Structure:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _init():
|
def _init():
|
||||||
locs = sys._getframe(1).f_locals
|
locs = sys._getframe(1).f_locals
|
||||||
self = locs.pop('self')
|
self = locs['self']
|
||||||
for name, val in locs.items():
|
for name, val in locs.items():
|
||||||
|
if name == 'self': continue
|
||||||
setattr(self, name, val)
|
setattr(self, name, val)
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|||||||
@ -11,8 +11,9 @@ class Structure:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _init():
|
def _init():
|
||||||
locs = sys._getframe(1).f_locals
|
locs = sys._getframe(1).f_locals
|
||||||
self = locs.pop('self')
|
self = locs['self']
|
||||||
for name, val in locs.items():
|
for name, val in locs.items():
|
||||||
|
if name == 'self': continue
|
||||||
setattr(self, name, val)
|
setattr(self, name, val)
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
|
|||||||
@ -12,8 +12,9 @@ class Structure:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _init():
|
def _init():
|
||||||
locs = sys._getframe(1).f_locals
|
locs = sys._getframe(1).f_locals
|
||||||
self = locs.pop('self')
|
self = locs['self']
|
||||||
for name, val in locs.items():
|
for name, val in locs.items():
|
||||||
|
if name == 'self': continue
|
||||||
setattr(self, name, val)
|
setattr(self, name, val)
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
|
|||||||
@ -8,8 +8,9 @@ class Structure:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _init():
|
def _init():
|
||||||
locs = sys._getframe(1).f_locals
|
locs = sys._getframe(1).f_locals
|
||||||
self = locs.pop('self')
|
self = locs['self']
|
||||||
for name, val in locs.items():
|
for name, val in locs.items():
|
||||||
|
if name == 'self': continue
|
||||||
setattr(self, name, val)
|
setattr(self, name, val)
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
|
|||||||
@ -9,8 +9,9 @@ class Structure:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _init():
|
def _init():
|
||||||
locs = sys._getframe(1).f_locals
|
locs = sys._getframe(1).f_locals
|
||||||
self = locs.pop('self')
|
self = locs['self']
|
||||||
for name, val in locs.items():
|
for name, val in locs.items():
|
||||||
|
if name == 'self': continue
|
||||||
setattr(self, name, val)
|
setattr(self, name, val)
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user