Skip to content

Commit 4915986

Browse files
authored
rename MyClass to School (#858)
1 parent a5f0718 commit 4915986

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

docs/source/config.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,28 @@ subclass
127127
from traitlets.config.configurable import Configurable
128128
from traitlets import Int, Float, Unicode, Bool
129129
130-
class MyClass(Configurable):
130+
class School(Configurable):
131131
name = Unicode('defaultname', help="the name of the object").tag(config=True)
132132
ranking = Integer(0, help="the class's ranking").tag(config=True)
133133
value = Float(99.0)
134134
# The rest of the class implementation would go here..
135135
136-
# Construct from config via MyClass(config=..)
136+
# Construct from config via School(config=..)
137137
138-
In this example, we see that :class:`MyClass` has three attributes, two
138+
In this example, we see that :class:`School` has three attributes, two
139139
of which (``name``, ``ranking``) can be configured. All of the attributes
140-
are given types and default values. If a :class:`MyClass` is instantiated,
140+
are given types and default values. If a :class:`School` is instantiated,
141141
but not configured, these default values will be used. But let's see how
142142
to configure this class in a configuration file
143143

144144
.. code-block:: python
145145
146146
# Sample config file
147-
c.MyClass.name = 'coolname'
148-
c.MyClass.ranking = 10
147+
c.School.name = 'coolname'
148+
c.School.ranking = 10
149149
150150
After this configuration file is loaded, the values set in it will override
151-
the class defaults anytime a :class:`MyClass` is created. Furthermore,
151+
the class defaults anytime a :class:`School` is created. Furthermore,
152152
these attributes will be type checked and validated anytime they are set.
153153
This type checking is handled by the :mod:`traitlets` module,
154154
which provides the :class:`~traitlets.Unicode`, :class:`~traitlets.Integer` and
@@ -167,7 +167,7 @@ attribute of ``c`` is not the actual class, but instead is another
167167

168168
.. note::
169169

170-
The careful reader may wonder how the ``ClassName`` (``MyClass`` in
170+
The careful reader may wonder how the ``ClassName`` (``School`` in
171171
the above example) attribute of the configuration object ``c`` gets
172172
created. These attributes are created on the fly by the
173173
:class:`~traitlets.config.Config` instance, using a simple naming
@@ -191,7 +191,7 @@ JSON configuration file:
191191
.. code-block:: json
192192
193193
{
194-
"MyClass": {
194+
"School": {
195195
"name": "coolname",
196196
"ranking": 10
197197
}
@@ -218,8 +218,8 @@ example that loads all of the values from the file :file:`base_config.py`:
218218
:caption: examples/docs/configs/base_config.py
219219
220220
c = get_config() # noqa
221-
c.MyClass.name = 'coolname'
222-
c.MyClass.ranking = 100
221+
c.School.name = 'Harvard'
222+
c.School.ranking = 100
223223
224224
into the configuration file :file:`main_config.py`:
225225

@@ -233,7 +233,7 @@ into the configuration file :file:`main_config.py`:
233233
load_subconfig('base_config.py') # noqa
234234
235235
# Now override one of the values
236-
c.MyClass.name = 'bettername'
236+
c.School.name = 'bettername'
237237
238238
In a situation like this the :func:`load_subconfig` makes sure that the
239239
search path for sub-configuration files is inherited from that of the parent.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Example config used by load_config_app.py
22

33
c = get_config() # noqa
4-
c.MyClass.name = 'coolname'
4+
c.MyClass.name = 'Harvard'
55
c.MyClass.ranking = 100

examples/docs/configs/main_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
load_subconfig('base_config.py') # noqa
77

88
# Now override one of the values
9-
c.MyClass.name = 'bettername'
9+
c.School.name = 'Caltech'

examples/docs/load_config_app.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
Example:
66
77
$ ./examples/docs/load_config_app.py
8-
bettername ranking:100
8+
The school Caltech has a rank of 1.
99
10-
$ ./examples/docs/load_config_app.py --name cli_name
11-
cli_name ranking:100
10+
$ ./examples/docs/load_config_app.py --name Duke
11+
The school Duke has a rank of 1.
1212
13-
$ ./examples/docs/load_config_app.py --name cli_name --MyApp.MyClass.ranking=99
14-
cli_name ranking:99
13+
$ ./examples/docs/load_config_app.py --name Duke --MyApp.MyClass.ranking=12
14+
The school Duke has a rank of 12.
1515
1616
$ ./examples/docs/load_config_app.py -c ""
17-
default ranking:0
17+
The school MIT has a rank of 1.
1818
"""
1919

2020
from pathlib import Path
@@ -23,22 +23,22 @@
2323
from traitlets.config import Application, Configurable
2424

2525

26-
class MyClass(Configurable):
27-
name = Unicode(default_value="default").tag(config=True)
28-
ranking = Int().tag(config=True)
26+
class School(Configurable):
27+
name = Unicode(default_value="MIT").tag(config=True)
28+
ranking = Int(default_value=1).tag(config=True)
2929

3030
def __str__(self):
31-
return f"{self.name} ranking:{self.ranking}"
31+
return f"The school {self.name} has a rank of {self.ranking}."
3232

3333

3434
class MyApp(Application):
35-
classes = [MyClass]
35+
classes = [School]
3636
config_file = Unicode(default_value="main_config", help="base name of config file").tag(
3737
config=True
3838
)
3939
aliases = {
40-
"name": "MyClass.name",
41-
"ranking": "MyClass.ranking",
40+
"name": "School.name",
41+
"ranking": "School.ranking",
4242
("c", "config-file"): "MyApp.config_file",
4343
}
4444

@@ -48,7 +48,7 @@ def initialize(self, argv=None):
4848
self.load_config_file(self.config_file, [Path(__file__).parent / "configs"])
4949

5050
def start(self):
51-
print(MyClass(parent=self))
51+
print(School(parent=self))
5252

5353

5454
if __name__ == "__main__":

0 commit comments

Comments
 (0)