Giter Site home page Giter Site logo

Comments (5)

Bouke avatar Bouke commented on May 20, 2024

I ran into the same issue today, did you manage to work around this issue?

from traits.

corranwebster avatar corranwebster commented on May 20, 2024

Related to this (not raising an error, but surprising):

from traits.api import HasTraits, Dict, Str, List, Int

class TestList(HasTraits):
    x = List(List(Int))

class TestDict(HasTraits):
    x = Dict(Str, List)

class TestDict2(HasTraits):
    x = Dict(Str, Dict(Str, Int))

def listener(obj, name, old, new):
    print obj, name, old, new.added

t1 = TestList(x=[[1, 2, 3]])
t1.on_trait_change(listener, name='x_items')
t1.x[0].append(4)  # listener fires with data from sub-list as if it were main list

t2 = TestDict(x={'a': [1, 2, 3]})
t2.on_trait_change(listener, name='x_items')
t2.x['a'].append(4)  # exception, as noted above

t3 = TestDict2(x={'a': {'b': 1}})
t3.on_trait_change(listener, name='x_items')
t3.x['a']['c'] = 2  # listener fires with data from sub-dict as if it were main dict

The root issue is with recursive calls to List.validate or Dict.validate when building the TraitListObject or TraitDictObject instances. This is non-trivial to fix: it's not even clear what the "right" behaviour should be.

from traits.

jonathanrocher avatar jonathanrocher commented on May 20, 2024

I ran into the same issue (in the Dict(Str, List) case). To work around it, @Bouke , I simplified my declaration to Dict(). @rkern also suggested offline to use Dict(Str, Instance(list)) if you need the typechecking.

from traits.

mdickinson avatar mdickinson commented on May 20, 2024

This is essentially the same issue as #281. We should close one or the other.

from traits.

mdickinson avatar mdickinson commented on May 20, 2024

Closed #281 as a duplicate of this issue; there's some useful discussion in comments on that issue.

from traits.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.