From 535d8779006036dd307cd5b60b460c7392f74544 2010-04-15 18:06:07 From: Dav Clark Date: 2010-04-15 18:06:07 Subject: [PATCH] Merging Dav's traitlets rename branch. --- diff --git a/IPython/__init__.py b/IPython/__init__.py index 759f958..ff3156b 100755 --- a/IPython/__init__.py +++ b/IPython/__init__.py @@ -5,7 +5,6 @@ IPython. IPython is a set of tools for interactive and exploratory computing in Python. """ - #----------------------------------------------------------------------------- # Copyright (C) 2008-2009 The IPython Development Team # diff --git a/IPython/core/application.py b/IPython/core/application.py index d53fc6d..7fdea83 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -224,7 +224,7 @@ class Application(object): For the most part, we try to set default in the class attributes of Components. But, defaults the top-level Application (which is - not a HasTraitlets or Component) are not set in this way. Instead + not a HasTraits or Component) are not set in this way. Instead we set them here. The Global section is for variables like this that don't belong to a particular component. """ diff --git a/IPython/core/component.py b/IPython/core/component.py old mode 100644 new mode 100755 index 1ee9509..98b6508 --- a/IPython/core/component.py +++ b/IPython/core/component.py @@ -27,7 +27,7 @@ from weakref import WeakValueDictionary from IPython.utils.importstring import import_item from IPython.config.loader import Config from IPython.utils.traitlets import ( - HasTraitlets, MetaHasTraitlets, Instance, This + HasTraits, MetaHasTraits, Instance, This ) @@ -173,7 +173,7 @@ class __ComponentNameGenerator(object): ComponentNameGenerator = __ComponentNameGenerator('ipython.component') -class MetaComponent(MetaHasTraitlets, MetaComponentTracker): +class MetaComponent(MetaHasTraits, MetaComponentTracker): pass @@ -182,11 +182,11 @@ class MetaComponent(MetaHasTraitlets, MetaComponentTracker): #----------------------------------------------------------------------------- -class Component(HasTraitlets): +class Component(HasTraits): __metaclass__ = MetaComponent - # Traitlets are fun! + # Traits are fun! config = Instance(Config,(),{}) parent = This() root = This() @@ -256,7 +256,7 @@ class Component(HasTraitlets): self.created = datetime.datetime.now() #------------------------------------------------------------------------- - # Static traitlet notifiations + # Static trait notifiations #------------------------------------------------------------------------- def _parent_changed(self, name, old, new): @@ -282,12 +282,12 @@ class Component(HasTraitlets): def _config_changed(self, name, old, new): """Update all the class traits having ``config=True`` as metadata. - For any class traitlet with a ``config`` metadata attribute that is - ``True``, we update the traitlet with the value of the corresponding + For any class trait with a ``config`` metadata attribute that is + ``True``, we update the trait with the value of the corresponding config entry. """ - # Get all traitlets with a config metadata entry that is True - traitlets = self.traitlets(config=True) + # Get all traits with a config metadata entry that is True + traits = self.traits(config=True) # We auto-load config section for this class as well as any parent # classes that are Component subclasses. This starts with Component @@ -301,7 +301,7 @@ class Component(HasTraitlets): # dynamically create the section with name self.__class__.__name__. if new._has_section(sname): my_config = new[sname] - for k, v in traitlets.items(): + for k, v in traits.items(): # Don't allow traitlets with config=True to start with # uppercase. Otherwise, they are confused with Config # subsections. But, developers shouldn't have uppercase diff --git a/IPython/core/iplib.py b/IPython/core/iplib.py index c75b404..72200d9 100644 --- a/IPython/core/iplib.py +++ b/IPython/core/iplib.py @@ -182,7 +182,7 @@ def get_default_colors(): class SeparateStr(Str): """A Str subclass to validate separate_in, separate_out, etc. - This is a Str based traitlet that converts '0'->'' and '\\n'->'\n'. + This is a Str based trait that converts '0'->'' and '\\n'->'\n'. """ def validate(self, obj, value): @@ -263,7 +263,7 @@ class InteractiveShell(Component, Magic): screen_length = Int(0, config=True) - # Use custom TraitletTypes that convert '0'->'' and '\\n'->'\n' + # Use custom TraitTypes that convert '0'->'' and '\\n'->'\n' separate_in = SeparateStr('\n', config=True) separate_out = SeparateStr('', config=True) separate_out2 = SeparateStr('', config=True) @@ -286,7 +286,7 @@ class InteractiveShell(Component, Magic): banner1=None, banner2=None, display_banner=None, custom_exceptions=((),None)): - # This is where traitlets with a config_key argument are updated + # This is where traits with a config_key argument are updated # from the values on config. super(InteractiveShell, self).__init__(parent, config=config) @@ -341,7 +341,7 @@ class InteractiveShell(Component, Magic): return self #------------------------------------------------------------------------- - # Traitlet changed handlers + # Trait changed handlers #------------------------------------------------------------------------- def _banner1_changed(self): diff --git a/IPython/core/tests/test_component.py b/IPython/core/tests/test_component.py index 9774320..5ffb169 100644 --- a/IPython/core/tests/test_component.py +++ b/IPython/core/tests/test_component.py @@ -24,7 +24,7 @@ from unittest import TestCase from IPython.core.component import Component, ComponentError from IPython.utils.traitlets import ( - TraitletError, Int, Float, Str + TraitError, Int, Float, Str ) from IPython.config.loader import Config @@ -109,7 +109,7 @@ class TestComponent(TestCase): def test_subclass_parent(self): c1 = Component(None) - self.assertRaises(TraitletError, setattr, c1, 'parent', 10) + self.assertRaises(TraitError, setattr, c1, 'parent', 10) class MyComponent(Component): pass diff --git a/IPython/utils/tests/test_traitlets.py b/IPython/utils/tests/test_traitlets.py old mode 100644 new mode 100755 index 20a05f4..fbf13c2 --- a/IPython/utils/tests/test_traitlets.py +++ b/IPython/utils/tests/test_traitlets.py @@ -25,8 +25,8 @@ Authors: from unittest import TestCase from IPython.utils.traitlets import ( - HasTraitlets, MetaHasTraitlets, TraitletType, Any, - Int, Long, Float, Complex, Str, Unicode, TraitletError, + HasTraits, MetaHasTraits, TraitType, Any, + Int, Long, Float, Complex, Str, Unicode, TraitError, Undefined, Type, This, Instance ) @@ -36,9 +36,9 @@ from IPython.utils.traitlets import ( #----------------------------------------------------------------------------- -class HasTraitletsStub(HasTraitlets): +class HasTraitsStub(HasTraits): - def _notify_traitlet(self, name, old, new): + def _notify_trait(self, name, old, new): self._notify_name = name self._notify_old = old self._notify_new = new @@ -49,17 +49,17 @@ class HasTraitletsStub(HasTraitlets): #----------------------------------------------------------------------------- -class TestTraitletType(TestCase): +class TestTraitType(TestCase): def test_get_undefined(self): - class A(HasTraitlets): - a = TraitletType + class A(HasTraits): + a = TraitType a = A() self.assertEquals(a.a, Undefined) def test_set(self): - class A(HasTraitletsStub): - a = TraitletType + class A(HasTraitsStub): + a = TraitType a = A() a.a = 10 @@ -69,10 +69,10 @@ class TestTraitletType(TestCase): self.assertEquals(a._notify_new, 10) def test_validate(self): - class MyTT(TraitletType): + class MyTT(TraitType): def validate(self, inst, value): return -1 - class A(HasTraitletsStub): + class A(HasTraitsStub): tt = MyTT a = A() @@ -80,26 +80,26 @@ class TestTraitletType(TestCase): self.assertEquals(a.tt, -1) def test_default_validate(self): - class MyIntTT(TraitletType): + class MyIntTT(TraitType): def validate(self, obj, value): if isinstance(value, int): return value self.error(obj, value) - class A(HasTraitlets): + class A(HasTraits): tt = MyIntTT(10) a = A() self.assertEquals(a.tt, 10) - # Defaults are validated when the HasTraitlets is instantiated - class B(HasTraitlets): + # Defaults are validated when the HasTraits is instantiated + class B(HasTraits): tt = MyIntTT('bad default') - self.assertRaises(TraitletError, B) + self.assertRaises(TraitError, B) def test_is_valid_for(self): - class MyTT(TraitletType): + class MyTT(TraitType): def is_valid_for(self, value): return True - class A(HasTraitlets): + class A(HasTraits): tt = MyTT a = A() @@ -107,10 +107,10 @@ class TestTraitletType(TestCase): self.assertEquals(a.tt, 10) def test_value_for(self): - class MyTT(TraitletType): + class MyTT(TraitType): def value_for(self, value): return 20 - class A(HasTraitlets): + class A(HasTraits): tt = MyTT a = A() @@ -118,33 +118,33 @@ class TestTraitletType(TestCase): self.assertEquals(a.tt, 20) def test_info(self): - class A(HasTraitlets): - tt = TraitletType + class A(HasTraits): + tt = TraitType a = A() self.assertEquals(A.tt.info(), 'any value') def test_error(self): - class A(HasTraitlets): - tt = TraitletType + class A(HasTraits): + tt = TraitType a = A() - self.assertRaises(TraitletError, A.tt.error, a, 10) + self.assertRaises(TraitError, A.tt.error, a, 10) -class TestHasTraitletsMeta(TestCase): +class TestHasTraitsMeta(TestCase): def test_metaclass(self): - self.assertEquals(type(HasTraitlets), MetaHasTraitlets) + self.assertEquals(type(HasTraits), MetaHasTraits) - class A(HasTraitlets): + class A(HasTraits): a = Int a = A() - self.assertEquals(type(a.__class__), MetaHasTraitlets) + self.assertEquals(type(a.__class__), MetaHasTraits) self.assertEquals(a.a,0) a.a = 10 self.assertEquals(a.a,10) - class B(HasTraitlets): + class B(HasTraits): b = Int() b = B() @@ -152,7 +152,7 @@ class TestHasTraitletsMeta(TestCase): b.b = 10 self.assertEquals(b.b,10) - class C(HasTraitlets): + class C(HasTraits): c = Int(30) c = C() @@ -161,7 +161,7 @@ class TestHasTraitletsMeta(TestCase): self.assertEquals(c.c,10) def test_this_class(self): - class A(HasTraitlets): + class A(HasTraits): t = This() tt = This() class B(A): @@ -172,7 +172,7 @@ class TestHasTraitletsMeta(TestCase): self.assertEquals(B.tt.this_class, B) self.assertEquals(B.ttt.this_class, B) -class TestHasTraitletsNotify(TestCase): +class TestHasTraitsNotify(TestCase): def setUp(self): self._notify1 = [] @@ -186,12 +186,12 @@ class TestHasTraitletsNotify(TestCase): def test_notify_all(self): - class A(HasTraitlets): + class A(HasTraits): a = Int b = Float a = A() - a.on_traitlet_change(self.notify1) + a.on_trait_change(self.notify1) a.a = 0 self.assertEquals(len(self._notify1),0) a.b = 0.0 @@ -200,31 +200,31 @@ class TestHasTraitletsNotify(TestCase): self.assert_(('a',0,10) in self._notify1) a.b = 10.0 self.assert_(('b',0.0,10.0) in self._notify1) - self.assertRaises(TraitletError,setattr,a,'a','bad string') - self.assertRaises(TraitletError,setattr,a,'b','bad string') + self.assertRaises(TraitError,setattr,a,'a','bad string') + self.assertRaises(TraitError,setattr,a,'b','bad string') self._notify1 = [] - a.on_traitlet_change(self.notify1,remove=True) + a.on_trait_change(self.notify1,remove=True) a.a = 20 a.b = 20.0 self.assertEquals(len(self._notify1),0) def test_notify_one(self): - class A(HasTraitlets): + class A(HasTraits): a = Int b = Float a = A() - a.on_traitlet_change(self.notify1, 'a') + a.on_trait_change(self.notify1, 'a') a.a = 0 self.assertEquals(len(self._notify1),0) a.a = 10 self.assert_(('a',0,10) in self._notify1) - self.assertRaises(TraitletError,setattr,a,'a','bad string') + self.assertRaises(TraitError,setattr,a,'a','bad string') def test_subclass(self): - class A(HasTraitlets): + class A(HasTraits): a = Int class B(A): @@ -240,15 +240,15 @@ class TestHasTraitletsNotify(TestCase): def test_notify_subclass(self): - class A(HasTraitlets): + class A(HasTraits): a = Int class B(A): b = Float b = B() - b.on_traitlet_change(self.notify1, 'a') - b.on_traitlet_change(self.notify2, 'b') + b.on_trait_change(self.notify1, 'a') + b.on_trait_change(self.notify2, 'b') b.a = 0 b.b = 0.0 self.assertEquals(len(self._notify1),0) @@ -260,7 +260,7 @@ class TestHasTraitletsNotify(TestCase): def test_static_notify(self): - class A(HasTraitlets): + class A(HasTraits): a = Int _notify1 = [] def _a_changed(self, name, old, new): @@ -296,73 +296,73 @@ class TestHasTraitletsNotify(TestCase): def callback3(name, old, new): self.cb = (name, old, new) - class A(HasTraitlets): + class A(HasTraits): a = Int a = A() - a.on_traitlet_change(callback0, 'a') + a.on_trait_change(callback0, 'a') a.a = 10 self.assertEquals(self.cb,()) - a.on_traitlet_change(callback0, 'a', remove=True) + a.on_trait_change(callback0, 'a', remove=True) - a.on_traitlet_change(callback1, 'a') + a.on_trait_change(callback1, 'a') a.a = 100 self.assertEquals(self.cb,('a',)) - a.on_traitlet_change(callback1, 'a', remove=True) + a.on_trait_change(callback1, 'a', remove=True) - a.on_traitlet_change(callback2, 'a') + a.on_trait_change(callback2, 'a') a.a = 1000 self.assertEquals(self.cb,('a',1000)) - a.on_traitlet_change(callback2, 'a', remove=True) + a.on_trait_change(callback2, 'a', remove=True) - a.on_traitlet_change(callback3, 'a') + a.on_trait_change(callback3, 'a') a.a = 10000 self.assertEquals(self.cb,('a',1000,10000)) - a.on_traitlet_change(callback3, 'a', remove=True) + a.on_trait_change(callback3, 'a', remove=True) - self.assertEquals(len(a._traitlet_notifiers['a']),0) + self.assertEquals(len(a._trait_notifiers['a']),0) -class TestHasTraitlets(TestCase): +class TestHasTraits(TestCase): - def test_traitlet_names(self): - class A(HasTraitlets): + def test_trait_names(self): + class A(HasTraits): i = Int f = Float a = A() - self.assertEquals(a.traitlet_names(),['i','f']) + self.assertEquals(a.trait_names(),['i','f']) - def test_traitlet_metadata(self): - class A(HasTraitlets): + def test_trait_metadata(self): + class A(HasTraits): i = Int(config_key='MY_VALUE') a = A() - self.assertEquals(a.traitlet_metadata('i','config_key'), 'MY_VALUE') + self.assertEquals(a.trait_metadata('i','config_key'), 'MY_VALUE') - def test_traitlets(self): - class A(HasTraitlets): + def test_traits(self): + class A(HasTraits): i = Int f = Float a = A() - self.assertEquals(a.traitlets(), dict(i=A.i, f=A.f)) + self.assertEquals(a.traits(), dict(i=A.i, f=A.f)) - def test_traitlets_metadata(self): - class A(HasTraitlets): + def test_traits_metadata(self): + class A(HasTraits): i = Int(config_key='VALUE1', other_thing='VALUE2') f = Float(config_key='VALUE3', other_thing='VALUE2') j = Int(0) a = A() - self.assertEquals(a.traitlets(), dict(i=A.i, f=A.f, j=A.j)) - traitlets = a.traitlets(config_key='VALUE1', other_thing='VALUE2') - self.assertEquals(traitlets, dict(i=A.i)) + self.assertEquals(a.traits(), dict(i=A.i, f=A.f, j=A.j)) + traits = a.traits(config_key='VALUE1', other_thing='VALUE2') + self.assertEquals(traits, dict(i=A.i)) # This passes, but it shouldn't because I am replicating a bug in # traits. - traitlets = a.traitlets(config_key=lambda v: True) - self.assertEquals(traitlets, dict(i=A.i, f=A.f, j=A.j)) + traits = a.traits(config_key=lambda v: True) + self.assertEquals(traits, dict(i=A.i, f=A.f, j=A.j)) #----------------------------------------------------------------------------- -# Tests for specific traitlet types +# Tests for specific trait types #----------------------------------------------------------------------------- @@ -371,7 +371,7 @@ class TestType(TestCase): def test_default(self): class B(object): pass - class A(HasTraitlets): + class A(HasTraits): klass = Type a = A() @@ -379,42 +379,42 @@ class TestType(TestCase): a.klass = B self.assertEquals(a.klass, B) - self.assertRaises(TraitletError, setattr, a, 'klass', 10) + self.assertRaises(TraitError, setattr, a, 'klass', 10) def test_value(self): class B(object): pass class C(object): pass - class A(HasTraitlets): + class A(HasTraits): klass = Type(B) a = A() self.assertEquals(a.klass, B) - self.assertRaises(TraitletError, setattr, a, 'klass', C) - self.assertRaises(TraitletError, setattr, a, 'klass', object) + self.assertRaises(TraitError, setattr, a, 'klass', C) + self.assertRaises(TraitError, setattr, a, 'klass', object) a.klass = B def test_allow_none(self): class B(object): pass class C(B): pass - class A(HasTraitlets): + class A(HasTraits): klass = Type(B, allow_none=False) a = A() self.assertEquals(a.klass, B) - self.assertRaises(TraitletError, setattr, a, 'klass', None) + self.assertRaises(TraitError, setattr, a, 'klass', None) a.klass = C self.assertEquals(a.klass, C) def test_validate_klass(self): - class A(HasTraitlets): + class A(HasTraits): klass = Type('no strings allowed') self.assertRaises(ImportError, A) - class A(HasTraitlets): + class A(HasTraits): klass = Type('rub.adub.Duck') self.assertRaises(ImportError, A) @@ -422,19 +422,19 @@ class TestType(TestCase): def test_validate_default(self): class B(object): pass - class A(HasTraitlets): + class A(HasTraits): klass = Type('bad default', B) self.assertRaises(ImportError, A) - class C(HasTraitlets): + class C(HasTraits): klass = Type(None, B, allow_none=False) - self.assertRaises(TraitletError, C) + self.assertRaises(TraitError, C) def test_str_klass(self): - class A(HasTraitlets): + class A(HasTraits): klass = Type('IPython.utils.ipstruct.Struct') from IPython.utils.ipstruct import Struct @@ -442,7 +442,7 @@ class TestType(TestCase): a.klass = Struct self.assertEquals(a.klass, Struct) - self.assertRaises(TraitletError, setattr, a, 'klass', 10) + self.assertRaises(TraitError, setattr, a, 'klass', 10) class TestInstance(TestCase): @@ -451,7 +451,7 @@ class TestInstance(TestCase): class Bar(Foo): pass class Bah(object): pass - class A(HasTraitlets): + class A(HasTraits): inst = Instance(Foo) a = A() @@ -460,13 +460,13 @@ class TestInstance(TestCase): self.assert_(isinstance(a.inst, Foo)) a.inst = Bar() self.assert_(isinstance(a.inst, Foo)) - self.assertRaises(TraitletError, setattr, a, 'inst', Foo) - self.assertRaises(TraitletError, setattr, a, 'inst', Bar) - self.assertRaises(TraitletError, setattr, a, 'inst', Bah()) + self.assertRaises(TraitError, setattr, a, 'inst', Foo) + self.assertRaises(TraitError, setattr, a, 'inst', Bar) + self.assertRaises(TraitError, setattr, a, 'inst', Bah()) def test_unique_default_value(self): class Foo(object): pass - class A(HasTraitlets): + class A(HasTraits): inst = Instance(Foo,(),{}) a = A() @@ -481,18 +481,18 @@ class TestInstance(TestCase): def __init__(self, c, d): self.c = c; self.d = d - class A(HasTraitlets): + class A(HasTraits): inst = Instance(Foo, (10,)) a = A() self.assertEquals(a.inst.c, 10) - class B(HasTraitlets): + class B(HasTraits): inst = Instance(Bah, args=(10,), kw=dict(d=20)) b = B() self.assertEquals(b.inst.c, 10) self.assertEquals(b.inst.d, 20) - class C(HasTraitlets): + class C(HasTraits): inst = Instance(Foo) c = C() self.assert_(c.inst is None) @@ -500,25 +500,25 @@ class TestInstance(TestCase): def test_bad_default(self): class Foo(object): pass - class A(HasTraitlets): + class A(HasTraits): inst = Instance(Foo, allow_none=False) - self.assertRaises(TraitletError, A) + self.assertRaises(TraitError, A) def test_instance(self): class Foo(object): pass def inner(): - class A(HasTraitlets): + class A(HasTraits): inst = Instance(Foo()) - self.assertRaises(TraitletError, inner) + self.assertRaises(TraitError, inner) class TestThis(TestCase): def test_this_class(self): - class Foo(HasTraitlets): + class Foo(HasTraits): this = This f = Foo() @@ -526,10 +526,10 @@ class TestThis(TestCase): g = Foo() f.this = g self.assertEquals(f.this, g) - self.assertRaises(TraitletError, setattr, f, 'this', 10) + self.assertRaises(TraitError, setattr, f, 'this', 10) def test_this_inst(self): - class Foo(HasTraitlets): + class Foo(HasTraits): this = This() f = Foo() @@ -537,7 +537,7 @@ class TestThis(TestCase): self.assert_(isinstance(f.this, Foo)) def test_subclass(self): - class Foo(HasTraitlets): + class Foo(HasTraits): t = This() class Bar(Foo): pass @@ -549,7 +549,7 @@ class TestThis(TestCase): self.assertEquals(b.t, f) def test_subclass_override(self): - class Foo(HasTraitlets): + class Foo(HasTraits): t = This() class Bar(Foo): t = This() @@ -557,10 +557,10 @@ class TestThis(TestCase): b = Bar() f.t = b self.assertEquals(f.t, b) - self.assertRaises(TraitletError, setattr, b, 't', f) + self.assertRaises(TraitError, setattr, b, 't', f) -class TraitletTestBase(TestCase): - """A best testing class for basic traitlet types.""" +class TraitTestBase(TestCase): + """A best testing class for basic trait types.""" def assign(self, value): self.obj.value = value @@ -577,33 +577,33 @@ class TraitletTestBase(TestCase): def test_bad_values(self): if hasattr(self, '_bad_values'): for value in self._bad_values: - self.assertRaises(TraitletError, self.assign, value) + self.assertRaises(TraitError, self.assign, value) def test_default_value(self): if hasattr(self, '_default_value'): self.assertEquals(self._default_value, self.obj.value) -class AnyTraitlet(HasTraitlets): +class AnyTrait(HasTraits): value = Any -class AnyTraitTest(TraitletTestBase): +class AnyTraitTest(TraitTestBase): - obj = AnyTraitlet() + obj = AnyTrait() _default_value = None _good_values = [10.0, 'ten', u'ten', [10], {'ten': 10},(10,), None, 1j] _bad_values = [] -class IntTraitlet(HasTraitlets): +class IntTrait(HasTraits): value = Int(99) -class TestInt(TraitletTestBase): +class TestInt(TraitTestBase): - obj = IntTraitlet() + obj = IntTrait() _default_value = 99 _good_values = [10, -10] _bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None, 1j, 10L, @@ -611,13 +611,13 @@ class TestInt(TraitletTestBase): u'-10L', u'10.1', u'-10.1', '10', '-10', u'10', u'-10'] -class LongTraitlet(HasTraitlets): +class LongTrait(HasTraits): value = Long(99L) -class TestLong(TraitletTestBase): +class TestLong(TraitTestBase): - obj = LongTraitlet() + obj = LongTrait() _default_value = 99L _good_values = [10, -10, 10L, -10L] @@ -627,13 +627,13 @@ class TestLong(TraitletTestBase): u'-10.1'] -class FloatTraitlet(HasTraitlets): +class FloatTrait(HasTraits): value = Float(99.0) -class TestFloat(TraitletTestBase): +class TestFloat(TraitTestBase): - obj = FloatTraitlet() + obj = FloatTrait() _default_value = 99.0 _good_values = [10, -10, 10.1, -10.1] @@ -642,13 +642,13 @@ class TestFloat(TraitletTestBase): u'-10', u'10L', u'-10L', u'10.1', u'-10.1'] -class ComplexTraitlet(HasTraitlets): +class ComplexTrait(HasTraits): value = Complex(99.0-99.0j) -class TestComplex(TraitletTestBase): +class TestComplex(TraitTestBase): - obj = ComplexTraitlet() + obj = ComplexTrait() _default_value = 99.0-99.0j _good_values = [10, -10, 10.1, -10.1, 10j, 10+10j, 10-10j, @@ -656,13 +656,13 @@ class TestComplex(TraitletTestBase): _bad_values = [10L, -10L, u'10L', u'-10L', 'ten', [10], {'ten': 10},(10,), None] -class StringTraitlet(HasTraitlets): +class StringTrait(HasTraits): value = Str('string') -class TestString(TraitletTestBase): +class TestString(TraitTestBase): - obj = StringTraitlet() + obj = StringTrait() _default_value = 'string' _good_values = ['10', '-10', '10L', @@ -671,13 +671,13 @@ class TestString(TraitletTestBase): ['ten'],{'ten': 10},(10,), None, u'string'] -class UnicodeTraitlet(HasTraitlets): +class UnicodeTrait(HasTraits): value = Unicode(u'unicode') -class TestUnicode(TraitletTestBase): +class TestUnicode(TraitTestBase): - obj = UnicodeTraitlet() + obj = UnicodeTrait() _default_value = u'unicode' _good_values = ['10', '-10', '10L', '-10L', '10.1', diff --git a/IPython/utils/traitlets.py b/IPython/utils/traitlets.py index 30d6211..67af9c2 100644 --- a/IPython/utils/traitlets.py +++ b/IPython/utils/traitlets.py @@ -17,7 +17,7 @@ We don't support: * Delegation * Automatic GUI generation * A full set of trait types. Most importantly, we don't provide container - traitlets (list, dict, tuple) that can trigger notifications if their + traits (list, dict, tuple) that can trigger notifications if their contents change. * API compatibility with enthought.traits @@ -57,7 +57,18 @@ from types import ( ListType, TupleType ) -from IPython.utils.importstring import import_item +def import_item(name): + """Import and return bar given the string foo.bar.""" + package = '.'.join(name.split('.')[0:-1]) + obj = name.split('.')[-1] + execString = 'from %s import %s' % (package, obj) + try: + exec execString + except SyntaxError: + raise ImportError("Invalid class specification: %s" % name) + exec 'temp = %s' % obj + return temp + ClassTypes = (ClassType, type) @@ -75,11 +86,9 @@ NoDefaultSpecified = NoDefaultSpecified() class Undefined ( object ): pass Undefined = Undefined() - -class TraitletError(Exception): +class TraitError(Exception): pass - #----------------------------------------------------------------------------- # Utilities #----------------------------------------------------------------------------- @@ -129,12 +138,12 @@ def parse_notifier_name(name): >>> parse_notifier_name(['a','b']) ['a', 'b'] >>> parse_notifier_name(None) - ['anytraitlet'] + ['anytrait'] """ if isinstance(name, str): return [name] elif name is None: - return ['anytraitlet'] + return ['anytrait'] elif isinstance(name, (list, tuple)): for n in name: assert isinstance(n, str), "names must be strings" @@ -172,25 +181,25 @@ def getmembers(object, predicate=None): #----------------------------------------------------------------------------- -# Base TraitletType for all traitlets +# Base TraitType for all traits #----------------------------------------------------------------------------- -class TraitletType(object): - """A base class for all traitlet descriptors. +class TraitType(object): + """A base class for all trait descriptors. Notes ----- - Our implementation of traitlets is based on Python's descriptor + Our implementation of traits is based on Python's descriptor prototol. This class is the base class for all such descriptors. The - only magic we use is a custom metaclass for the main :class:`HasTraitlets` + only magic we use is a custom metaclass for the main :class:`HasTraits` class that does the following: - 1. Sets the :attr:`name` attribute of every :class:`TraitletType` + 1. Sets the :attr:`name` attribute of every :class:`TraitType` instance in the class dict to the name of the attribute. - 2. Sets the :attr:`this_class` attribute of every :class:`TraitletType` - instance in the class dict to the *class* that declared the traitlet. - This is used by the :class:`This` traitlet to allow subclasses to + 2. Sets the :attr:`this_class` attribute of every :class:`TraitType` + instance in the class dict to the *class* that declared the trait. + This is used by the :class:`This` trait to allow subclasses to accept superclasses for :class:`This` values. """ @@ -200,7 +209,7 @@ class TraitletType(object): info_text = 'any value' def __init__(self, default_value=NoDefaultSpecified, **metadata): - """Create a TraitletType. + """Create a TraitType. """ if default_value is not NoDefaultSpecified: self.default_value = default_value @@ -225,11 +234,11 @@ class TraitletType(object): return dv def instance_init(self, obj): - """This is called by :meth:`HasTraitlets.__new__` to finish init'ing. + """This is called by :meth:`HasTraits.__new__` to finish init'ing. Some stages of initialization must be delayed until the parent - :class:`HasTraitlets` instance has been created. This method is - called in :meth:`HasTraitlets.__new__` after the instance has been + :class:`HasTraits` instance has been created. This method is + called in :meth:`HasTraits.__new__` after the instance has been created. This method trigger the creation and validation of default values @@ -238,8 +247,8 @@ class TraitletType(object): Parameters ---------- - obj : :class:`HasTraitlets` instance - The parent :class:`HasTraitlets` instance that has just been + obj : :class:`HasTraits` instance + The parent :class:`HasTraits` instance that has just been created. """ self.set_default_value(obj) @@ -249,30 +258,30 @@ class TraitletType(object): This method is called by :meth:`instance_init` to create and validate the default value. The creation and validation of - default values must be delayed until the parent :class:`HasTraitlets` + default values must be delayed until the parent :class:`HasTraits` class has been instantiated. """ dv = self.get_default_value() newdv = self._validate(obj, dv) - obj._traitlet_values[self.name] = newdv + obj._trait_values[self.name] = newdv def __get__(self, obj, cls=None): - """Get the value of the traitlet by self.name for the instance. + """Get the value of the trait by self.name for the instance. - Default values are instantiated when :meth:`HasTraitlets.__new__` + Default values are instantiated when :meth:`HasTraits.__new__` is called. Thus by the time this method gets called either the default value or a user defined value (they called :meth:`__set__`) - is in the :class:`HasTraitlets` instance. + is in the :class:`HasTraits` instance. """ if obj is None: return self else: try: - value = obj._traitlet_values[self.name] + value = obj._trait_values[self.name] except: - # HasTraitlets should call set_default_value to populate + # HasTraits should call set_default_value to populate # this. So this should never be reached. - raise TraitletError('Unexpected error in TraitletType: ' + raise TraitError('Unexpected error in TraitType: ' 'default value not set properly') else: return value @@ -281,8 +290,8 @@ class TraitletType(object): new_value = self._validate(obj, value) old_value = self.__get__(obj) if old_value != new_value: - obj._traitlet_values[self.name] = new_value - obj._notify_traitlet(self.name, old_value, new_value) + obj._trait_values[self.name] = new_value + obj._notify_trait(self.name, old_value, new_value) def _validate(self, obj, value): if hasattr(self, 'validate'): @@ -292,7 +301,7 @@ class TraitletType(object): if valid: return value else: - raise TraitletError('invalid value for type: %r' % value) + raise TraitError('invalid value for type: %r' % value) elif hasattr(self, 'value_for'): return self.value_for(value) else: @@ -303,13 +312,13 @@ class TraitletType(object): def error(self, obj, value): if obj is not None: - e = "The '%s' traitlet of %s instance must be %s, but a value of %s was specified." \ + e = "The '%s' trait of %s instance must be %s, but a value of %s was specified." \ % (self.name, class_of(obj), self.info(), repr_type(value)) else: - e = "The '%s' traitlet must be %s, but a value of %r was specified." \ + e = "The '%s' trait must be %s, but a value of %r was specified." \ % (self.name, self.info(), repr_type(value)) - raise TraitletError(e) + raise TraitError(e) def get_metadata(self, key): return getattr(self, '_metadata', {}).get(key, None) @@ -319,62 +328,62 @@ class TraitletType(object): #----------------------------------------------------------------------------- -# The HasTraitlets implementation +# The HasTraits implementation #----------------------------------------------------------------------------- -class MetaHasTraitlets(type): - """A metaclass for HasTraitlets. +class MetaHasTraits(type): + """A metaclass for HasTraits. - This metaclass makes sure that any TraitletType class attributes are + This metaclass makes sure that any TraitType class attributes are instantiated and sets their name attribute. """ def __new__(mcls, name, bases, classdict): - """Create the HasTraitlets class. + """Create the HasTraits class. - This instantiates all TraitletTypes in the class dict and sets their + This instantiates all TraitTypes in the class dict and sets their :attr:`name` attribute. """ # print "MetaHasTraitlets (mcls, name): ", mcls, name # print "MetaHasTraitlets (bases): ", bases # print "MetaHasTraitlets (classdict): ", classdict for k,v in classdict.iteritems(): - if isinstance(v, TraitletType): + if isinstance(v, TraitType): v.name = k elif inspect.isclass(v): - if issubclass(v, TraitletType): + if issubclass(v, TraitType): vinst = v() vinst.name = k classdict[k] = vinst - return super(MetaHasTraitlets, mcls).__new__(mcls, name, bases, classdict) + return super(MetaHasTraits, mcls).__new__(mcls, name, bases, classdict) def __init__(cls, name, bases, classdict): - """Finish initializing the HasTraitlets class. + """Finish initializing the HasTraits class. - This sets the :attr:`this_class` attribute of each TraitletType in the + This sets the :attr:`this_class` attribute of each TraitType in the class dict to the newly created class ``cls``. """ for k, v in classdict.iteritems(): - if isinstance(v, TraitletType): + if isinstance(v, TraitType): v.this_class = cls - super(MetaHasTraitlets, cls).__init__(name, bases, classdict) + super(MetaHasTraits, cls).__init__(name, bases, classdict) -class HasTraitlets(object): +class HasTraits(object): - __metaclass__ = MetaHasTraitlets + __metaclass__ = MetaHasTraits def __new__(cls, *args, **kw): # This is needed because in Python 2.6 object.__new__ only accepts # the cls argument. - new_meth = super(HasTraitlets, cls).__new__ + new_meth = super(HasTraits, cls).__new__ if new_meth is object.__new__: inst = new_meth(cls) else: inst = new_meth(cls, *args, **kw) - inst._traitlet_values = {} - inst._traitlet_notifiers = {} - # Here we tell all the TraitletType instances to set their default + inst._trait_values = {} + inst._trait_notifiers = {} + # Here we tell all the TraitType instances to set their default # values on the instance. for key in dir(cls): # Some descriptors raise AttributeError like zope.interface's @@ -385,19 +394,20 @@ class HasTraitlets(object): except AttributeError: pass else: - if isinstance(value, TraitletType): + if isinstance(value, TraitType): value.instance_init(inst) + return inst # def __init__(self): - # self._traitlet_values = {} - # self._traitlet_notifiers = {} + # self._trait_values = {} + # self._trait_notifiers = {} - def _notify_traitlet(self, name, old_value, new_value): + def _notify_trait(self, name, old_value, new_value): # First dynamic ones - callables = self._traitlet_notifiers.get(name,[]) - more_callables = self._traitlet_notifiers.get('anytraitlet',[]) + callables = self._trait_notifiers.get(name,[]) + more_callables = self._trait_notifiers.get('anytrait',[]) callables.extend(more_callables) # Now static ones @@ -430,25 +440,25 @@ class HasTraitlets(object): elif nargs + offset == 3: c(name, old_value, new_value) else: - raise TraitletError('a traitlet changed callback ' + raise TraitError('a trait changed callback ' 'must have 0-3 arguments.') else: - raise TraitletError('a traitlet changed callback ' + raise TraitError('a trait changed callback ' 'must be callable.') def _add_notifiers(self, handler, name): - if not self._traitlet_notifiers.has_key(name): + if not self._trait_notifiers.has_key(name): nlist = [] - self._traitlet_notifiers[name] = nlist + self._trait_notifiers[name] = nlist else: - nlist = self._traitlet_notifiers[name] + nlist = self._trait_notifiers[name] if handler not in nlist: nlist.append(handler) def _remove_notifiers(self, handler, name): - if self._traitlet_notifiers.has_key(name): - nlist = self._traitlet_notifiers[name] + if self._trait_notifiers.has_key(name): + nlist = self._trait_notifiers[name] try: index = nlist.index(handler) except ValueError: @@ -456,25 +466,25 @@ class HasTraitlets(object): else: del nlist[index] - def on_traitlet_change(self, handler, name=None, remove=False): - """Setup a handler to be called when a traitlet changes. + def on_trait_change(self, handler, name=None, remove=False): + """Setup a handler to be called when a trait changes. - This is used to setup dynamic notifications of traitlet changes. + This is used to setup dynamic notifications of trait changes. - Static handlers can be created by creating methods on a HasTraitlets - subclass with the naming convention '_[traitletname]_changed'. Thus, - to create static handler for the traitlet 'a', create the method + Static handlers can be created by creating methods on a HasTraits + subclass with the naming convention '_[traitname]_changed'. Thus, + to create static handler for the trait 'a', create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below). Parameters ---------- handler : callable - A callable that is called when a traitlet changes. Its + A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new) or handler(name, old, new). name : list, str, None - If None, the handler will apply to all traitlets. If a list + If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name. remove : bool @@ -490,62 +500,62 @@ class HasTraitlets(object): for n in names: self._add_notifiers(handler, n) - def traitlet_names(self, **metadata): - """Get a list of all the names of this classes traitlets.""" - return self.traitlets(**metadata).keys() + def trait_names(self, **metadata): + """Get a list of all the names of this classes traits.""" + return self.traits(**metadata).keys() - def traitlets(self, **metadata): - """Get a list of all the traitlets of this class. + def traits(self, **metadata): + """Get a list of all the traits of this class. - The TraitletTypes returned don't know anything about the values - that the various HasTraitlet's instances are holding. + The TraitTypes returned don't know anything about the values + that the various HasTrait's instances are holding. This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn't exist. """ - traitlets = dict([memb for memb in getmembers(self.__class__) if \ - isinstance(memb[1], TraitletType)]) + traits = dict([memb for memb in getmembers(self.__class__) if \ + isinstance(memb[1], TraitType)]) if len(metadata) == 0: - return traitlets + return traits for meta_name, meta_eval in metadata.items(): if type(meta_eval) is not FunctionType: metadata[meta_name] = _SimpleTest(meta_eval) result = {} - for name, traitlet in traitlets.items(): + for name, trait in traits.items(): for meta_name, meta_eval in metadata.items(): - if not meta_eval(traitlet.get_metadata(meta_name)): + if not meta_eval(trait.get_metadata(meta_name)): break else: - result[name] = traitlet + result[name] = trait return result - def traitlet_metadata(self, traitletname, key): - """Get metadata values for traitlet by key.""" + def trait_metadata(self, traitname, key): + """Get metadata values for trait by key.""" try: - traitlet = getattr(self.__class__, traitletname) + trait = getattr(self.__class__, traitname) except AttributeError: - raise TraitletError("Class %s does not have a traitlet named %s" % - (self.__class__.__name__, traitletname)) + raise TraitError("Class %s does not have a trait named %s" % + (self.__class__.__name__, traitname)) else: - return traitlet.get_metadata(key) + return trait.get_metadata(key) #----------------------------------------------------------------------------- -# Actual TraitletTypes implementations/subclasses +# Actual TraitTypes implementations/subclasses #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- -# TraitletTypes subclasses for handling classes and instances of classes +# TraitTypes subclasses for handling classes and instances of classes #----------------------------------------------------------------------------- -class ClassBasedTraitletType(TraitletType): - """A traitlet with error reporting for Type, Instance and This.""" +class ClassBasedTraitType(TraitType): + """A trait with error reporting for Type, Instance and This.""" def error(self, obj, value): kind = type(value) @@ -554,16 +564,16 @@ class ClassBasedTraitletType(TraitletType): else: msg = '%s (i.e. %s)' % ( str( kind )[1:-1], repr( value ) ) - super(ClassBasedTraitletType, self).error(obj, msg) + super(ClassBasedTraitType, self).error(obj, msg) -class Type(ClassBasedTraitletType): - """A traitlet whose value must be a subclass of a specified class.""" +class Type(ClassBasedTraitType): + """A trait whose value must be a subclass of a specified class.""" def __init__ (self, default_value=None, klass=None, allow_none=True, **metadata ): - """Construct a Type traitlet + """Construct a Type trait - A Type traitlet specifies that its values must be subclasses of + A Type trait specifies that its values must be subclasses of a particular class. If only ``default_value`` is given, it is used for the ``klass`` as @@ -575,12 +585,12 @@ class Type(ClassBasedTraitletType): The default value must be a subclass of klass. If an str, the str must be a fully specified class name, like 'foo.bar.Bah'. The string is resolved into real class, when the parent - :class:`HasTraitlets` class is instantiated. + :class:`HasTraits` class is instantiated. klass : class, str, None - Values of this traitlet must be a subclass of klass. The klass + Values of this trait must be a subclass of klass. The klass may be specified in a string like: 'foo.bar.MyClass'. The string is resolved into real class, when the parent - :class:`HasTraitlets` class is instantiated. + :class:`HasTraits` class is instantiated. allow_none : boolean Indicates whether None is allowed as an assignable value. Even if ``False``, the default value may be ``None``. @@ -592,7 +602,7 @@ class Type(ClassBasedTraitletType): klass = default_value if not (inspect.isclass(klass) or isinstance(klass, basestring)): - raise TraitletError("A Type traitlet must specify a class.") + raise TraitError("A Type trait must specify a class.") self.klass = klass self._allow_none = allow_none @@ -646,7 +656,7 @@ class DefaultValueGenerator(object): return klass(*self.args, **self.kw) -class Instance(ClassBasedTraitletType): +class Instance(ClassBasedTraitType): """A trait whose value must be an instance of a specified class. The value can also be an instance of a subclass of the specified class. @@ -654,9 +664,9 @@ class Instance(ClassBasedTraitletType): def __init__(self, klass=None, args=None, kw=None, allow_none=True, **metadata ): - """Construct an Instance traitlet. + """Construct an Instance trait. - This traitlet allows values that are instances of a particular + This trait allows values that are instances of a particular class or its sublclasses. Our implementation is quite different from that of enthough.traits as we don't allow instances to be used for klass and we handle the ``args`` and ``kw`` arguments differently. @@ -664,7 +674,7 @@ class Instance(ClassBasedTraitletType): Parameters ---------- klass : class, str - The class that forms the basis for the traitlet. Class names + The class that forms the basis for the trait. Class names can also be specified as strings, like 'foo.bar.Bar'. args : tuple Positional arguments for generating the default value. @@ -684,7 +694,7 @@ class Instance(ClassBasedTraitletType): self._allow_none = allow_none if (klass is None) or (not (inspect.isclass(klass) or isinstance(klass, basestring))): - raise TraitletError('The klass argument must be a class' + raise TraitError('The klass argument must be a class' ' you gave: %r' % klass) self.klass = klass @@ -700,9 +710,9 @@ class Instance(ClassBasedTraitletType): kw = {} if not isinstance(kw, dict): - raise TraitletError("The 'kw' argument must be a dict or None.") + raise TraitError("The 'kw' argument must be a dict or None.") if not isinstance(args, tuple): - raise TraitletError("The 'args' argument must be a tuple or None.") + raise TraitError("The 'args' argument must be a tuple or None.") default_value = DefaultValueGenerator(*args, **kw) @@ -741,9 +751,9 @@ class Instance(ClassBasedTraitletType): def get_default_value(self): """Instantiate a default value instance. - This is called when the containing HasTraitlets classes' + This is called when the containing HasTraits classes' :meth:`__new__` method is called to ensure that a unique instance - is created for each HasTraitlets instance. + is created for each HasTraits instance. """ dv = self.default_value if isinstance(dv, DefaultValueGenerator): @@ -752,11 +762,11 @@ class Instance(ClassBasedTraitletType): return dv -class This(ClassBasedTraitletType): - """A traitlet for instances of the class containing this trait. +class This(ClassBasedTraitType): + """A trait for instances of the class containing this trait. Because how how and when class bodies are executed, the ``This`` - traitlet can only have a default value of None. This, and because we + trait can only have a default value of None. This, and because we always validate default values, ``allow_none`` is *always* true. """ @@ -768,7 +778,7 @@ class This(ClassBasedTraitletType): def validate(self, obj, value): # What if value is a superclass of obj.__class__? This is # complicated if it was the superclass that defined the This - # traitlet. + # trait. if isinstance(value, self.this_class) or (value is None): return value else: @@ -776,17 +786,17 @@ class This(ClassBasedTraitletType): #----------------------------------------------------------------------------- -# Basic TraitletTypes implementations/subclasses +# Basic TraitTypes implementations/subclasses #----------------------------------------------------------------------------- -class Any(TraitletType): +class Any(TraitType): default_value = None info_text = 'any value' -class Int(TraitletType): - """A integer traitlet.""" +class Int(TraitType): + """A integer trait.""" evaluate = int default_value = 0 @@ -798,7 +808,7 @@ class Int(TraitletType): self.error(obj, value) class CInt(Int): - """A casting version of the int traitlet.""" + """A casting version of the int trait.""" def validate(self, obj, value): try: @@ -807,8 +817,8 @@ class CInt(Int): self.error(obj, value) -class Long(TraitletType): - """A long integer traitlet.""" +class Long(TraitType): + """A long integer trait.""" evaluate = long default_value = 0L @@ -823,7 +833,7 @@ class Long(TraitletType): class CLong(Long): - """A casting version of the long integer traitlet.""" + """A casting version of the long integer trait.""" def validate(self, obj, value): try: @@ -832,8 +842,8 @@ class CLong(Long): self.error(obj, value) -class Float(TraitletType): - """A float traitlet.""" +class Float(TraitType): + """A float trait.""" evaluate = float default_value = 0.0 @@ -848,7 +858,7 @@ class Float(TraitletType): class CFloat(Float): - """A casting version of the float traitlet.""" + """A casting version of the float trait.""" def validate(self, obj, value): try: @@ -856,8 +866,8 @@ class CFloat(Float): except: self.error(obj, value) -class Complex(TraitletType): - """A traitlet for complex numbers.""" +class Complex(TraitType): + """A trait for complex numbers.""" evaluate = complex default_value = 0.0 + 0.0j @@ -872,7 +882,7 @@ class Complex(TraitletType): class CComplex(Complex): - """A casting version of the complex number traitlet.""" + """A casting version of the complex number trait.""" def validate (self, obj, value): try: @@ -881,8 +891,8 @@ class CComplex(Complex): self.error(obj, value) -class Str(TraitletType): - """A traitlet for strings.""" +class Str(TraitType): + """A trait for strings.""" evaluate = lambda x: x default_value = '' @@ -895,7 +905,7 @@ class Str(TraitletType): class CStr(Str): - """A casting version of the string traitlet.""" + """A casting version of the string trait.""" def validate(self, obj, value): try: @@ -907,8 +917,8 @@ class CStr(Str): self.error(obj, value) -class Unicode(TraitletType): - """A traitlet for unicode strings.""" +class Unicode(TraitType): + """A trait for unicode strings.""" evaluate = unicode default_value = u'' @@ -923,7 +933,7 @@ class Unicode(TraitletType): class CUnicode(Unicode): - """A casting version of the unicode traitlet.""" + """A casting version of the unicode trait.""" def validate(self, obj, value): try: @@ -932,8 +942,8 @@ class CUnicode(Unicode): self.error(obj, value) -class Bool(TraitletType): - """A boolean (True, False) traitlet.""" +class Bool(TraitType): + """A boolean (True, False) trait.""" evaluate = bool default_value = False info_text = 'a boolean' @@ -945,7 +955,7 @@ class Bool(TraitletType): class CBool(Bool): - """A casting version of the boolean traitlet.""" + """A casting version of the boolean trait.""" def validate(self, obj, value): try: @@ -954,7 +964,7 @@ class CBool(Bool): self.error(obj, value) -class Enum(TraitletType): +class Enum(TraitType): """An enum that whose value must be in a given sequence.""" def __init__(self, values, default_value=None, allow_none=True, **metadata): @@ -999,7 +1009,7 @@ class List(Instance): """An instance of a Python list.""" def __init__(self, default_value=None, allow_none=True, **metadata): - """Create a list traitlet type from a list or tuple. + """Create a list trait type from a list or tuple. The default value is created by doing ``list(default_value)``, which creates a copy of the ``default_value``. @@ -1008,6 +1018,8 @@ class List(Instance): args = ((),) elif isinstance(default_value, SequenceTypes): args = (default_value,) + else: + raise TypeError('default value of List was %s' % default_value) super(List,self).__init__(klass=list, args=args, allow_none=allow_none, **metadata) diff --git a/docs/source/config/overview.txt b/docs/source/config/overview.txt index 2f386bc..7e7b215 100644 --- a/docs/source/config/overview.txt +++ b/docs/source/config/overview.txt @@ -134,7 +134,7 @@ traitlets for a number of other types. .. note:: Underneath the hood, the :class:`Component` base class is a subclass of - :class:`IPython.utils.traitlets.HasTraitlets`. The + :class:`IPython.utils.traitlets.HasTraits`. The :mod:`IPython.utils.traitlets` module is a lightweight version of :mod:`enthought.traits`. Our implementation is a pure Python subset (mostly API compatible) of :mod:`enthought.traits` that does not have any