Fix compatibility with Python 2
This PR fixes a compatibility issue with Python 2: decorating with just @widgets.register will transform the decorated class into a function, whereas using @widgets.register() will correctly return a class. This fixes the following error:
TypeError: Error when calling the metaclass bases function() argument 1 must be code, not str
With this fix I could successfully run the following simple example:
import ipyvolume
ipyvolume.examples.ball(rmax=3, rmin=2.5, shape=64, lighting=True)
BTW it would be nice I think to add the mybinder examples in the doc directly, or even the readme, so that new users can easily test out the widget for themselves :-) Otherwise in the doc there is no other example that does not require a 3rd-party library (bokeh etc).
Coverage remained the same at 61.763% when pulling 2f1f89af93a810ca32ad4058d23a654ae9049cd8 on lrq3000:py2fix into 6e1f088a94c60ff85f87cb9c66a996e1facd6745 on maartenbreddels:master.
Also for reference (about the decorator):
- https://bugs.python.org/issue6829
Hi there, thanks for your contribution! I cannot reproduce this actually. The decorator might be a bit confusing, since going from ipywidget 6 to 7 it does not take a name anymore, but a widget instead. If you installed ipyvolume with ipywidget 6 this may happen actually!. A binder link in the docs would be great, I saw some auto generated once, I'll look into it.
@maartenbreddels mmm that's weird, did you try with Python >= 2.7.13 ? Because it's known to work with Python >= 3 since the class management changed, so this issue affects only Python 2. I have ipywidget v7.1.1, I had to update else the widget would not even load with the time old issue of "javascript can't be loaded" or something like that.
it's 2.7.14, on OSX, using miniconda, and ipyvolume works with that. I'm almost sure it is ipywidget 6 you are using, maybe you have it installed in ~/.local?
can you check the output of python -c "import ipywidgets as w; print(w.__version__, w.__file__)" ?
Hey @maartenbreddels , thank you for your suggestion, here is the output:
('7.1.1', 'C:\\Anaconda2\\lib\\site-packages\\ipywidgets\\__init__.pyc')
The path is where I initially applied my patch to make ipyvolume works. Also my Python version is 2.7.12, maybe there was an update between .12 and .14 that renders Py2 compatible with such decorator?
Ok, I need to check this on windows, I only have OSX and Linux now, but I'll try to boot up a virtual machine soon!