shaise / FreeCAD_SheetMetal

A simple sheet metal workbench for FreeCAD
http://theseger.com/projects/2015/06/sheet-metal-addon-for-freecad/
GNU Lesser General Public License v2.1
193 stars 56 forks source link

[Sheetmetal] Python 3.11.x and above Json Fix #293

Closed Syres916 closed 8 months ago

Syres916 commented 8 months ago

In order to fix errors using Python 3.11.x and above while preserving ability for Python 3.10.x and below to still work correctly, example error:

  File "/usr/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type FeaturePython is not JSON serializable
17:04:02  PropertyPythonObject::toString(): failed for <class 'SheetMetalCmd.SMViewProviderFlat'>
17:04:02  pyException: Traceback (most recent call last):
  File "/usr/lib/python3.11/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^

@shaise Certainly worth testing with a Python 3.10 or below to ensure there's no regressions but I'm quite happy this should be good to go. Any questions, let me know.

shaise commented 8 months ago

Thanks!

I changes your solution a little bit, so instead of duplicating the code of setstate and loads, I just call loads from setstate,