Open
Description
Switching to using attrs was a huge help. I'd like to do the same thing for the many, many sets of constants that we have. http://constantly.readthedocs.io/en/latest/ looks like a pretty good library, and has had the advantage of a long period of testing.
e.g.
# Y Axis formats
DURATION_FORMAT = "dtdurations"
NO_FORMAT = "none"
OPS_FORMAT = "ops"
PERCENT_UNIT_FORMAT = "percentunit"
SECONDS_FORMAT = "s"
MILLISECONDS_FORMAT = "ms"
SHORT_FORMAT = "short"
BYTES_FORMAT = "bytes"
which is used as
yAxes = attr.ib(
default=attr.Factory(lambda: [YAxis(format=SHORT_FORMAT)] * 2))
would become something like:
from constantly import ValueConstant, Values
class YAxisFormat(Values):
"""Y-axis formats."""
DURATION = ValueConstant("dtdurations")
NONE = ValueConstant("none")
OPS = ValueConstant("ops")
PERCENT_UNIT = ValueConstant("percentunit")
SECONDS = ValueConstant("s")
MILLISECONDS = ValueConstant("ms")
SHORT = ValueConstant("short")
BYTES = ValueConstant("bytes")
which would be used as:
yAxes = attr.ib(
default=attr.Factory(lambda: [YAxis(format=YAxisFormat.SHORT)] * 2))
We can then write validators that use .iterconstants()
or .lookupByName()
to validate the constants.
I don't know how this will affect backwards compatibility, or indeed what backwards compatibility goals we should have.