Skip to content

Commit 4405c2c

Browse files
authored
Merge pull request #396 from alcrene/fix/recent-python/python-311
Fix: Fix logic in `project.save()` for Python 3.11+
2 parents 1be3e5d + 2032010 commit 4405c2c

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

sumatra/projects.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,14 @@ def save(self):
147147
else:
148148
# Default value for unrecognised parameters
149149
attr = None
150-
if hasattr(attr, "__getstate__"):
151-
state[name] = {'type': attr.__class__.__module__ + "." + attr.__class__.__name__}
152-
for key, value in attr.__getstate__().items():
153-
state[name][key] = value
150+
if hasattr(attr, "__getstate__"): # For Python 3.11+, all objects have __getstate__. Default return value is None.
151+
attr_state = attr.__getstate__()
152+
if attr_state is None:
153+
state[name] = attr
154+
else:
155+
state[name] = {'type': attr.__class__.__module__ + "." + attr.__class__.__name__}
156+
for key, value in attr.__getstate__().items():
157+
state[name][key] = value
154158
else:
155159
state[name] = attr
156160
f = open(_get_project_file(self.path), 'w') # should check if file exists?

0 commit comments

Comments
 (0)