You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/source/custom_resolvers.rst
+17-15
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ You can add additional interpolation types by registering custom resolvers with
27
27
28
28
Attempting to register the same resolver twice will raise a ``ValueError`` unless using ``replace=True``.
29
29
30
-
The example below creates a resolver that adds 10 to the given value.
30
+
The example below creates a resolver that adds ``10`` to the given value.
31
31
32
32
.. doctest::
33
33
@@ -36,9 +36,9 @@ The example below creates a resolver that adds 10 to the given value.
36
36
>>> c.key
37
37
1000
38
38
39
-
Custom resolvers support variadic argument lists in the form of a commaseparated list of zero or more values.
40
-
Whitespaces are stripped from both ends of each value ("foo,bar" is the same as "foo, bar ").
41
-
You can use literal commas and spaces anywhere by escaping (:code:`\,` and :code:`\ `), or
39
+
Custom resolvers support variadic argument lists in the form of a comma-separated list of zero or more values.
40
+
In a variadic argument list, whitespace is stripped from the ends of each value ("foo,bar" gives the same result as "foo, bar ").
41
+
You can use literal commas and spaces anywhere by escaping (``\,`` and :code:`\ `), or
42
42
simply use quotes to bypass character limitations in strings.
43
43
44
44
.. doctest::
@@ -90,7 +90,7 @@ namespace, and to use interpolations in the name itself. The following example d
90
90
By default a custom resolver is called on every access, but it is possible to cache its output
91
91
by registering it with ``use_cache=True``.
92
92
This may be useful either for performance reasons or to ensure the same value is always returned.
93
-
Note that the cache is based on the string literals representing the resolver's inputs, and not
93
+
Note that the cache is based on the string literals representing the resolver's inputs, not on
94
94
the inputs themselves:
95
95
96
96
.. doctest::
@@ -121,14 +121,14 @@ the inputs themselves:
121
121
122
122
Custom interpolations can also receive the following special parameters:
123
123
124
-
- ``_parent_``: the parent node of an interpolation.
124
+
- ``_parent_``: The parent node of an interpolation.
125
125
- ``_root_``: The config root.
126
126
127
127
This can be achieved by adding the special parameters to the resolver signature.
128
-
Note that special parameters must be defined as named keywords (after the `*`).
128
+
Note that special parameters must be defined as named keywords (after the ``*``).
129
129
130
-
In the example below, we use ``_parent_`` to implement a sum function that defaults to 0 if the node does not exist.
131
-
(In contrast to the sum we defined earlier where accessing an invalid key, e.g. ``"a_plus_z": ${sum:${a}, ${z}}`` would result in an error).
130
+
In the example below, we use ``_parent_`` to implement a sum function that defaults to ``0`` if the node does not exist.
131
+
This is in contrast to the sum we defined earlier where accessing an invalid key, e.g. ``"a_plus_z": ${sum:${a}, ${z}}``, would result in an error.
132
132
133
133
.. doctest::
134
134
@@ -175,7 +175,8 @@ Input YAML file:
175
175
'/home/omry'
176
176
177
177
You can specify a default value to use in case the environment variable is not set.
178
-
In such a case, the default value is converted to a string using ``str(default)``, unless it is ``null`` (representing Python ``None``) - in which case ``None`` is returned.
178
+
In such a case, the default value is converted to a string using ``str(default)``,
179
+
unless it is ``null`` (representing Python ``None``) - in which case ``None`` is returned.
179
180
180
181
The following example falls back to default passwords when ``DB_PASSWORD`` is not defined:
Copy file name to clipboardexpand all lines: docs/source/structured_config.rst
+51-23
Original file line number
Diff line number
Diff line change
@@ -21,10 +21,10 @@ Two types of structures classes that are supported: dataclasses and attr classes
21
21
- `dataclasses <https://docs.python.org/3.7/library/dataclasses.html>`_ are standard as of Python 3.7 or newer and are available in Python 3.6 via the `dataclasses` pip package.
22
22
- `attrs <https://github.com/python-attrs/attrs>`_ Offset slightly cleaner syntax in some cases but depends on the attrs pip package.
23
23
24
-
This documentation will use dataclasses, but you can use the annotation `@attr.s(auto_attribs=True)` from attrs instead of `@dataclass`.
24
+
This documentation will use dataclasses, but you can use the annotation ``@attr.s(auto_attribs=True)`` from attrs instead of ``@dataclass``.
25
25
26
-
Basic usage involves passing in a structured config class or instance to OmegaConf.structured(), which will return an OmegaConf config that matches
27
-
the values and types specified in the input. OmegaConf will validate modifications to the created config object at runtime against the schema specified
26
+
Basic usage involves passing in a structured config class or instance to ``OmegaConf.structured()``, which will return an OmegaConf config that matches
27
+
the values and types specified in the input. At runtine, OmegaConf will validate modifications to the created config object against the schema specified
28
28
in the input class.
29
29
30
30
Simple types
@@ -52,7 +52,7 @@ The following class defines fields with all simple types:
52
52
... height: Height = Height.SHORT
53
53
... description: str="text"
54
54
55
-
You can create a config based on the SimpleTypes class itself or instances of it.
55
+
You can create a config based on the SimpleTypes class itself or an instance of it.
56
56
Those would be equivalent by default, but the Object variant allows you to set the values of specific
57
57
fields during construction.
58
58
@@ -74,7 +74,7 @@ fields during construction.
74
74
description: text
75
75
<BLANKLINE>
76
76
77
-
The resulting object is a regular OmegaConf DictConfig, except it will utilize the type information in the input class/object
77
+
The resulting object is a regular OmegaConf ``DictConfig``, except that it will utilize the type information in the input class/object
78
78
and will validate the data at runtime.
79
79
The resulting object and will also rejects attempts to access or set fields that are not already defined
80
80
(similarly to configs with their to :ref:`struct-flag` set, but not recursive).
@@ -99,8 +99,8 @@ Python type annotation can be used by static type checkers like Mypy/Pyre or by
99
99
>>> with raises(ValidationError):
100
100
... conf.num ="foo"
101
101
102
-
This is duck-typing, the actual object type of `conf` is `DictConfig`. You can access the underlying
103
-
type using `OmegaConf.get_type()`:
102
+
This is duck-typing; the actual object type of ``conf`` is ``DictConfig``. You can access the underlying
103
+
type using ``OmegaConf.get_type()``:
104
104
105
105
.. doctest::
106
106
@@ -206,7 +206,8 @@ Python container types are fully supported in Structured configs.
206
206
207
207
Lists
208
208
^^^^^
209
-
Lists can hold any type supported by OmegaConf (int, float. bool, str, enum and Structured configs). Lists can be created from Lists and Tuples.
209
+
Structured Config fields annotated with ``typing.List`` or ``typing.Tuple`` can hold any type
210
+
supported by OmegaConf (``int``, ``float``. ``bool``, ``str``, ``Enum`` or Structured configs).
210
211
211
212
.. doctest::
212
213
@@ -216,18 +217,19 @@ Lists can hold any type supported by OmegaConf (int, float. bool, str, enum and
216
217
... name: str=MISSING
217
218
218
219
>>> @dataclass
219
-
... classLists:
220
+
... classListsExample:
220
221
... # Typed list can hold Any, int, float, bool, str and Enums as well
OmegaConf supports field modifiers such as MISSING and Optional.
280
+
OmegaConf supports field modifiers such as ``MISSING`` and ``Optional``.
252
281
253
282
.. doctest::
254
283
@@ -266,8 +295,8 @@ OmegaConf supports field modifiers such as MISSING and Optional.
266
295
Mandatory missing values
267
296
^^^^^^^^^^^^^^^^^^^^^^^^
268
297
269
-
Fields assigned the constant MISSING do not have a value and the value must be set prior to accessing the field
270
-
Otherwise a MissingMandatoryValue exception is raised.
298
+
Fields assigned the constant ``MISSING`` do not have a value and the value must be set prior to accessing the field.
299
+
Otherwise a ``MissingMandatoryValue`` exception is raised.
271
300
272
301
.. doctest::
273
302
@@ -294,8 +323,8 @@ Optional fields
294
323
Interpolations
295
324
^^^^^^^^^^^^^^
296
325
297
-
:ref:`interpolation` works normally with Structured configs but static type checkers may object to you assigning a string to another type.
298
-
To work around it, use SI and II described below.
326
+
:ref:`interpolation` works normally with Structured configs, but static type checkers may object to you assigning a string to another type.
327
+
To work around this, use the special functions ``omegaconf.SI`` and ``omegaconf.II`` described below.
299
328
300
329
.. doctest::
301
330
@@ -305,10 +334,10 @@ To work around it, use SI and II described below.
305
334
... val: int=100
306
335
... # This will work, but static type checkers will complain
307
336
... a: int="${val}"
308
-
... # This is identical to the above, but static type checkers
337
+
... # This is equivalent to the above, but static type checkers
309
338
... # will not complain
310
339
... b: int= SI("${val}")
311
-
... # This is a syntactic sugar, the input string is
340
+
... # This is syntactic sugar; the input string is
312
341
... # wrapped with ${} automatically.
313
342
... c: int= II("val")
314
343
@@ -354,7 +383,7 @@ Note however that this validation step is currently skipped for container node i
354
383
Frozen
355
384
^^^^^^
356
385
357
-
Frozen dataclasses and attr classes are supported via OmegaConf :ref:`read-only-flag`, which turns the entire config node and all if it's child nodes read-only.
386
+
Frozen dataclasses and attr classes are supported via OmegaConf :ref:`read-only-flag`, which makes the entire config node and all if it's child nodes read-only.
358
387
359
388
.. doctest::
360
389
@@ -367,7 +396,7 @@ Frozen dataclasses and attr classes are supported via OmegaConf :ref:`read-only-
367
396
>>> with raises(ReadonlyConfigError):
368
397
... conf.x =20
369
398
370
-
Read-only flag is recursive:
399
+
The read-only flag is recursive:
371
400
372
401
.. doctest::
373
402
@@ -406,7 +435,7 @@ A Schema for the above config can be defined like this.
0 commit comments