Skip to content

Python3 Compatability #4

@dpwrussell

Description

@dpwrussell

Hi,

Branch: https://github.com/dpwrussell/pyflot/tree/python3-test

I tried to use pyflot in a python3 project, but it's obviously not ported yet. I thought I'd have a quick go.

Some basic 2to3 changes were made no problem (I haven't given any thought to backwards compatibility yet as I wanted to get it working first), but there is still a problem with JSON Serialization.

This is not a list, so any one of a bunch of errors can occur, e.g.

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    my_graph = MyGraph()
  File "/Users/dpwrussell/.virtualenvs/flot-test/lib/python3.3/site-packages/flot/__init__.py", line 248, in __init__
    attr = getattr(self, attr_name)
  File "/Users/dpwrussell/.virtualenvs/flot-test/lib/python3.3/site-packages/flot/__init__.py", line 289, in json_data
    return json.dumps(self._series)
  File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/json/__init__.py", line 236, in dumps
    return _default_encoder.encode(obj)
  File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/json/encoder.py", line 191, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/json/encoder.py", line 249, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <slot wrapper '__setattr__' of 'object' objects> is not JSON serializable

I added a small diagnostic to print the types of the attributes in a _series. This is where the problem is as JSON is trying to serialize all this stuff. I'm not sure how to deal with this as obviously you really don't want to be trying to serializing all that stuff in python3 as it fails.

Python3

<class 'NoneType'>
<class 'list'>
<class 'wrapper_descriptor'>
<class 'wrapper_descriptor'>
<class 'type'>
<class 'builtin_function_or_method'>
<class 'wrapper_descriptor'>
<class 'wrapper_descriptor'>
<class 'wrapper_descriptor'>
<class 'method_descriptor'>
<class 'method_descriptor'>
<class 'wrapper_descriptor'>
<class 'wrapper_descriptor'>
<class 'wrapper_descriptor'>
<class 'wrapper_descriptor'>
<class 'mappingproxy'>
<class 'method_descriptor'>
<class 'wrapper_descriptor'>
<class 'method_descriptor'>
<class 'str'>
<class 'wrapper_descriptor'>
<class 'builtin_function_or_method'>
<class 'wrapper_descriptor'>
<class 'wrapper_descriptor'>
<class 'method_descriptor'>
<class 'getset_descriptor'>

Python2

<type 'str'>
<type 'list'>
<type 'NoneType'>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions