enthought / traits

Observable typed attributes for Python classes
Other
432 stars 85 forks source link

Sort takes at most 2 arguments #356

Closed kmader closed 7 years ago

kmader commented 7 years ago

It is a couple of layers deep coming originally from the mayavi package, but the issue appears to be wholly inside of traits. The platform is anaconda python 3.5.2 and traits 4.5.0 The most relevant portion of the message is


/Users/mader/anaconda/lib/python3.5/site-packages/traits/trait_handlers.py in sort(self, cmp, key, reverse)
   2565     def sort ( self, cmp = None, key = None, reverse = False ):
   2566         removed = self[:]
-> 2567         list.sort( self, cmp = cmp, key = key, reverse = reverse )
   2568 
   2569         if (getattr(self, 'name_items', None) is not None and

TypeError: sort() takes at most 2 arguments (3 given)

And this seems to map to the current repository here: https://github.com/enthought/traits/blob/master/traits/trait_handlers.py#L2606 or the permalink: https://github.com/enthought/traits/blob/089a031983de8545d2f91fce095d74aa30eb6487/traits/trait_handlers.py#L2606

The whole error was gotten while running

from mayavi import mlab
mlab.init_notebook()
import numpy as np
x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)
mlab.pipeline.volume(mlab.pipeline.scalar_field(s))

and goes through quite a few different layers

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-5b13d9042f90> in <module>()
----> 1 mlab.pipeline.volume(mlab.pipeline.scalar_field(s))

/Users/mader/anaconda/lib/python3.5/site-packages/mayavi/tools/pipe_base.py in the_function(*args, **kwargs)
     36 def make_function(factory_class):
     37     def the_function(*args, **kwargs):
---> 38         factory = factory_class(*args, **kwargs)
     39         return factory._target
     40 

/Users/mader/anaconda/lib/python3.5/site-packages/mayavi/tools/pipe_base.py in __init__(self, parent, **kwargs)
    144             self._do_redraw = not scene.disable_render
    145             scene.disable_render = True
--> 146         if issubclass(self._target.__class__, Filter):
    147             self._engine.add_filter(self._target, obj=parent)
    148         else:

/Users/mader/anaconda/lib/python3.5/site-packages/traits/trait_types.py in create_default_value(self, *args, **kw)
   2799                 raise TraitError('Unable to locate class: ' + args[0])
   2800 
-> 2801         return klass( *args[1:], **kw )
   2802 
   2803     #: fixme: Do we still need this method using the new style?...

/Users/mader/anaconda/lib/python3.5/site-packages/mayavi/core/module.py in __init__(self, **traits)
     56 
     57         # Let the module setup its pipeline.
---> 58         self.setup_pipeline()
     59 
     60     def __get_pure_state__(self):

/Users/mader/anaconda/lib/python3.5/site-packages/mayavi/modules/volume.py in setup_pipeline(self)
    305         vp = self._volume_property = tvtk.VolumeProperty()
    306 
--> 307         self._ctf = ctf = default_CTF(0, 255)
    308         self._otf = otf = default_OTF(0, 255)
    309         vp.set_color(ctf)

/Users/mader/anaconda/lib/python3.5/site-packages/mayavi/modules/volume.py in default_CTF(x1, x2)
    123                     val_range=(1.0, 1.0),
    124                     n=10,
--> 125                     mode='sqrt')
    126 
    127 

/Users/mader/anaconda/lib/python3.5/site-packages/mayavi/modules/volume.py in make_CTF(x1, x2, hue_range, sat_range, val_range, n, mode)
    101             v = val_range[0] + dval*x
    102             r, g, b, a = [sqrt(c) for c in hsva_to_rgba(h, s, v, 1.0)]
--> 103             ctf.add_rgb_point(mins+x*ds, r, g, b)
    104     elif mode == 'linear':
    105         for i in range(n+1):

/Users/mader/anaconda/lib/python3.5/site-packages/tvtk/util/ctf.py in add_rgb_point(self, *args)
    208         ret = super(ColorTransferFunction, self).add_rgb_point(*args)
    209         self.nodes.append(args[0])
--> 210         self.nodes.sort()
    211         return ret
    212 

/Users/mader/anaconda/lib/python3.5/site-packages/traits/trait_handlers.py in sort(self, cmp, key, reverse)
   2565     def sort ( self, cmp = None, key = None, reverse = False ):
   2566         removed = self[:]
-> 2567         list.sort( self, cmp = cmp, key = key, reverse = reverse )
   2568 
   2569         if (getattr(self, 'name_items', None) is not None and

TypeError: sort() takes at most 2 arguments (3 given)
mdickinson commented 7 years ago

Thanks for the report! This is indeed a bug in Traits 4.5.0, and was fixed in #176. The fix is present in the most recent release (4.6.0) of Traits.