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: README.rst
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,39 +58,38 @@ An option manager object can then be obtained by instantiating the option manage
58
58
classMyOptions(OptionManager):
59
59
""" Options of some library. """
60
60
61
-
validate = Option(True, bool)
61
+
validate = Option(bool, True)
62
62
""" Whether to validate arguments to functions and methods. """
63
63
64
-
eq_atol = Option(1e-8, float, lambdax: x >=0)
64
+
eq_atol = Option(float, 1e-8, lambdax: x >=0)
65
65
""" Absolute tolerance used for equality comparisons."""
66
66
67
67
scaling: Option(
68
-
{"x": 1.0, "y": 2.0, "z": 1.0},
69
68
Mapping[Literal["x", "y", "z"], float],
69
+
{"x": 1.0, "y": 2.0, "z": 1.0},
70
70
lambdascaling: all(v >=0for v in scaling.values())
71
71
)
72
72
""" Scaling for coordinate axes used in plots. """
73
73
74
74
options = MyOptions()
75
75
76
-
77
76
Each option takes a default value, a type, and an optional validator function:
78
77
79
78
.. code-block:: python
80
79
81
-
validate = Option(True, bool)
82
-
#default value ^^^^ ^^^^ option type
80
+
validate = Option(bool, True)
81
+
# option type ^^^^ ^^^^ default value
83
82
84
-
eq_atol = Option(1e-8, float, lambdax: x >=0)
83
+
eq_atol = Option(float, 1e-8, lambdax: x >=0)
85
84
# optional validator ^^^^^^^^^^^^^^^^
86
85
87
86
Any type supported by the `typing-validation <https://github.com/hashberg-io/typing-validation>`_ library can be used for options, including `PEP 484 <https://peps.python.org/pep-0484/>`_ type hints:
88
87
89
88
.. code-block:: python
90
89
91
90
scaling: Option(
92
-
{"x": 1.0, "y": 2.0, "z": 1.0},
93
91
Mapping[Literal["x", "y", "z"], float], # <- type hints supported
92
+
{"x": 1.0, "y": 2.0, "z": 1.0},
94
93
lambdascaling: all(v >=0for v in scaling.values())
95
94
)
96
95
@@ -120,7 +119,7 @@ It is also possible to use the options object as a context manager, for temporar
120
119
print(options.validate) # True
121
120
print(options.eq_atol) # 0.00000001
122
121
123
-
All options can be reset to their default values by using the `reset <https://optmanage.readthedocs.io/en/latest/api/optmanage.manager.html#optmanage.manager.OptionManager.reset>`_ method of the ``options`` object:
122
+
All options can be reset to their default values by using the `OptionManager.reset <https://optmanage.readthedocs.io/en/latest/api/optmanage.manager.html#optmanage.manager.OptionManager.reset>`_ method of the ``options`` object:
124
123
125
124
.. code-block:: python
126
125
@@ -131,7 +130,7 @@ All options can be reset to their default values by using the `reset <https://op
131
130
print(options.validate) # True
132
131
print(options.eq_atol) # 0.00000001
133
132
134
-
An individual option can be reset to its default value by using the `reset <https://optmanage.readthedocs.io/en/latest/api/optmanage.option.html#optmanage.option.Option.reset>`_ method of the `Option <https://optmanage.readthedocs.io/en/latest/api/optmanage.option.html#option>`_ object, accessed from the option manager class:
133
+
An individual option can be reset to its default value by using the `Option.reset <https://optmanage.readthedocs.io/en/latest/api/optmanage.option.html#optmanage.option.Option.reset>`_ method of the `Option <https://optmanage.readthedocs.io/en/latest/api/optmanage.option.html#option>`_ object, accessed from the option manager class:
Copy file name to clipboardExpand all lines: docs/getting-started.rst
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,15 +19,15 @@ An option manager object can then be obtained by instantiating the option manage
19
19
classMyOptions(OptionManager):
20
20
""" Options of some library. """
21
21
22
-
validate = Option(True, bool)
22
+
validate = Option(bool, True)
23
23
""" Whether to validate arguments to functions and methods. """
24
24
25
-
eq_atol = Option(1e-8, float, lambdax: x >=0)
25
+
eq_atol = Option(float, 1e-8, lambdax: x >=0)
26
26
""" Absolute tolerance used for equality comparisons."""
27
27
28
28
scaling: Option(
29
-
{"x": 1.0, "y": 2.0, "z": 1.0},
30
29
Mapping[Literal["x", "y", "z"], float],
30
+
{"x": 1.0, "y": 2.0, "z": 1.0},
31
31
lambdascaling: all(v >=0for v in scaling.values())
32
32
)
33
33
""" Scaling for coordinate axes used in plots. """
@@ -39,19 +39,19 @@ Each option takes a default value, a type, and an optional validator function:
39
39
40
40
.. code-block:: python
41
41
42
-
validate = Option(True, bool)
43
-
#default value ^^^^ ^^^^ option type
42
+
validate = Option(bool, True)
43
+
# option type ^^^^ ^^^^ default value
44
44
45
-
eq_atol = Option(1e-8, float, lambdax: x >=0)
45
+
eq_atol = Option(float, 1e-8, lambdax: x >=0)
46
46
# optional validator ^^^^^^^^^^^^^^^^
47
47
48
48
Any type supported by the `typing-validation <https://github.com/hashberg-io/typing-validation>`_ library can be used for options, including `PEP 484 <https://peps.python.org/pep-0484/>`_ type hints:
49
49
50
50
.. code-block:: python
51
51
52
52
scaling: Option(
53
-
{"x": 1.0, "y": 2.0, "z": 1.0},
54
53
Mapping[Literal["x", "y", "z"], float], # <- type hints supported
54
+
{"x": 1.0, "y": 2.0, "z": 1.0},
55
55
lambdascaling: all(v >=0for v in scaling.values())
0 commit comments