gvwilson / sdxpy

Software Design by Example: a tool-based introduction with Python
https://third-bit.com/sdxpy/
Other
280 stars 49 forks source link

/persist possible typo when performing upcalls #268

Closed na50r closed 5 months ago

na50r commented 5 months ago

So we have this here in aliasing.py:

Note that we inherit from objects.py

....
def load_bool(self, ident, value):
        return super()._bool(value)

    def load_float(self, ident, value):
        return super()._float(value)

    def load_int(self, ident, value):
        return super()._int(value)

    def load_str(self, ident, value):
        return super()._str(value)
...

But this doesn't work because LoadObjects does not have methods that are called like this, you'd either need to rename them in LoadObjects or perform an upcall like:

def load_bool(self, ident, value):
        return super().load_bool(value)

In addition, is it possible for this to run something like this?

word = "word"
data = [word, word]
with open("FileX.txt", 'w') as file:
    Saver = SaveAlias(file)
    Saver.save(data)

with open("FileX.txt", 'r') as file:
    Loader = LoadAlias(file)
    Loaded = Loader.load()
print(Loaded)

In my implementation, it works if word is an integer but not if it's a string. I tried to figure out if I made a mistake somehow or if there is an issue in your code, so I cloned your repo and encountered another issue which is the one I described above.

gvwilson commented 5 months ago

thanks very much for the bug report - if you're comfortable doing so, please email me (gvwilson@third-bit.com) so that I can add your name to the acknowledgments. I'm building a fresh copy of the book to send to the publisher tomorrow and would like to include you.