MCPcopy Create free account
hub / github.com/ipython/traitlets / Foo

Class Foo

examples/myapp.py:49–70  ·  view source on GitHub ↗

A class that has configurable, typed attributes.

Source from the content-addressed store, hash-verified

47
48
49class Foo(Configurable):
50 """A class that has configurable, typed attributes."""
51
52 i = Int(0, help="The integer i.").tag(config=True)
53 j = Int(1, help="The integer j.").tag(config=True)
54 name = Unicode("Brian", help="First name.").tag(config=True, shortname="B")
55 mode = Enum(values=["on", "off", "other"], default_value="on").tag(config=True)
56
57 def __init__(self, **kwargs):
58 super().__init__(**kwargs)
59 # using parent=self allows configuration in the form c.Foo.SubConfigurable.subvalue=1
60 # while c.SubConfigurable.subvalue=1 will still work, this allow to
61 # target specific instances of SubConfigurables
62 self.subconf = SubConfigurable(parent=self)
63
64 def describe(self):
65 print("I am Foo with:")
66 print(" i =", self.i)
67 print(" j =", self.j)
68 print(" name =", self.name)
69 print(" mode =", self.mode)
70 self.subconf.describe()
71
72
73class Bar(Configurable):

Callers 1

init_fooMethod · 0.70

Calls 4

IntClass · 0.90
UnicodeClass · 0.90
EnumClass · 0.90
tagMethod · 0.80

Tested by

no test coverage detected