QuantStack / py2vega

BSD 3-Clause "New" or "Revised" License
9 stars 4 forks source link

Fails on python3.9 #38

Closed gaborbernat closed 3 years ago

gaborbernat commented 3 years ago

When running https://github.com/bloomberg/ipydatagrid/blob/main/examples/ConditionalFormatting.ipynb on python3.9 the following error is raised:

File "/python3.9/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-5-d23227669e25>", line 28, in <module>
    background_color=Expr(format_based_on_other_column),

  File "/python3.9/site-packages/ipydatagrid/cellrenderer.py", line 25, in __init__
    super().__init__(value=value, **kwargs)

  File "/python3.9/site-packages/ipywidgets/widgets/widget.py", line 412, in __init__
    super(Widget, self).__init__(**kwargs)

  File "/python3.9/site-packages/traitlets/traitlets.py", line 1080, in __init__
    super_kwargs[key] = value

  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 124, in __exit__
    next(self.gen)

  File "/python3.9/site-packages/traitlets/traitlets.py", line 1191, in hold_trait_notifications
    value = trait._cross_validate(self, getattr(self, name))

  File "/python3.9/site-packages/traitlets/traitlets.py", line 618, in _cross_validate
    value = obj._trait_validators[self.name](obj, proposal)

  File "/python3.9/site-packages/traitlets/traitlets.py", line 975, in __call__
    return self.func(*args, **kwargs)

  File "/python3.9/site-packages/ipydatagrid/cellrenderer.py", line 33, in _validate_value
    return py2vega(

  File "/python3.9/site-packages/py2vega/main.py", line 354, in py2vega
    return VegaExpressionVisitor(whitelist, scope).visit(func.body[-1])

  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)

  File "/python3.9/site-packages/py2vega/main.py", line 133, in visit_Return
    return self.visit(node.value)

  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)

  File "/python3.9/site-packages/py2vega/main.py", line 251, in visit_IfExp
    self.visit(node.test),

  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)

  File "/python3.9/site-packages/py2vega/main.py", line 261, in visit_Compare
    left_operand = self._visit_binop_impl(left_operand, node.ops[idx], node.comparators[idx])

  File "/python3.9/site-packages/py2vega/main.py", line 227, in _visit_binop_impl
    left = left_node if isinstance(left_node, str) else self.visit(left_node)

  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ast.py", line 407, in visit
    return visitor(node)

  File "/python3.9/site-packages/py2vega/main.py", line 323, in visit_Subscript
    raise Py2VegaSyntaxError('Unsupported {} node'.format(node.slice.__class__.__name__))

  File "<string>", line unknown
Py2VegaSyntaxError: Unsupported Constant node, note that only a subset of Python is supported
gaborbernat commented 3 years ago

Duplicate of #37.