Compare commits

...

7 Commits

Author SHA1 Message Date
David Beazley
a55856bf89 Merge pull request #91 from mz0/PEP-667
fix ValueError in f_locals.pop('self') Python 3.13+
2025-12-22 12:14:42 -06:00
David Beazley
b63b7f6da1 Merge pull request #92 from mz0/typo6.4
typo: name way -> same way
2025-12-22 12:06:17 -06:00
David Beazley
510182cb39 Merge pull request #87 from pathcl/fix/reference-soln1-1
add reference for solution 1-1
2025-12-22 12:05:38 -06:00
David Beazley
7c771bd014 Fixed Issue #93 2025-12-22 12:02:43 -06:00
Mark Zhitomirski
2d7dfa6718 typo: name way -> same way 2025-11-02 13:25:08 +04:00
Mark Zhitomirski
0cfde115ff 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
2025-10-31 00:13:49 +04:00
Luis San Martin
9e290fd1a8 add reference for solution 2024-08-10 17:48:10 +00:00
8 changed files with 17 additions and 12 deletions

View File

@@ -61,8 +61,9 @@ and class definitions:
```python
>>> def _init(locs):
self = locs.pop('self')
self = locs['self']
for name, val in locs.items():
if name == 'self': continue
setattr(self, name, val)
>>> class Stock:
@@ -96,8 +97,9 @@ frame hacking. Try this variant of the `_init()` function:
>>> import sys
>>> def _init():
locs = sys._getframe(1).f_locals # Get callers local variables
self = locs.pop('self')
self = locs['self']
for name, val in locs.items():
if name == 'self': continue
setattr(self, name, val)
>>>
```
@@ -135,8 +137,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)
...
```

View File

@@ -84,7 +84,7 @@ class Stock(Structure):
Stock.create_init()
```
The resulting class should work exactly the name way as before:
The resulting class should work exactly the same way as before:
```python
>>> s = Stock(name='GOOG', shares=100, price=490.1)

View File

@@ -124,7 +124,7 @@ class Stock:
```
Note: This part doesn't involve a lot of code, but there are a lot of low-level
fiddly bits. The solution will look almost the same as for Exercise 6.6. Don't
fiddly bits. The solution will look almost the same as for Exercise 6.5. Don't
be shy about looking at solution code though.
\[ [Solution](soln7_1.md) | [Index](index.md) | [Exercise 6.5](ex6_5.md) | [Exercise 7.2](ex7_2.md) \]

View File

@@ -1,6 +1,4 @@
# Exercise 1.1 - Solution
Nothing here. Just follow along with the exercise.
Check [here](../Solutions/1_1/art.py)
[Back](ex1_1.md)

View File

@@ -11,8 +11,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

@@ -12,8 +12,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

@@ -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):