itchcraft.prefs =============== .. py:module:: itchcraft.prefs .. autoapi-nested-parse:: User preferences Attributes ---------- .. autoapisummary:: itchcraft.prefs.CliEnum Classes ------- .. autoapisummary:: itchcraft.prefs.SkinSensitivity itchcraft.prefs.Generation itchcraft.prefs.Duration itchcraft.prefs.Preferences Functions --------- .. autoapisummary:: itchcraft.prefs.default itchcraft.prefs.parse Module Contents --------------- .. py:data:: CliEnum Helper union type consisting of an :py:class:`~enum.Enum` and its stringified values. If a command line switch is backed by an `Enum`, then allow the enum to stand in for that switch. For example, if you have the following `Enum` class: .. code:: python from enum import Enum class Widget(Enum): FOO = 1 BAR = 2 and an associated command line switch ``--widget``, which can take the form of either ``--widget foo`` and ``--widget bar``, then `CliEnum[Widget]` means that the four values ``Widget.FOO``, ``Widget.BAR``, ``"foo"``, and ``"bar"`` should be accepted. `Widget.FOO` is equivalent to ``"foo"``, while `Widget.BAR` stands in for ``"bar"``: .. code:: python from itchcraft.prefs import CliEnum, parse def frob(widget: CliEnum[Widget]) -> None: real_widget: Widget = parse(widget, Widget) ... frob("foo") frob("bar") frob(Widget.FOO) # same as frob("foo") frob(Widget.BAR) # same as frob("bar") .. py:class:: SkinSensitivity Bases: :py:obj:`enum.Enum` Whether or not a person’s skin is particularly sensitive. .. py:attribute:: SENSITIVE :value: 1 .. py:attribute:: REGULAR :value: 2 .. py:class:: Generation Bases: :py:obj:`enum.Enum` The age cohort of a person. .. py:attribute:: CHILD :value: 1 .. py:attribute:: ADULT :value: 2 .. py:class:: Duration Bases: :py:obj:`enum.Enum` The duration of a demo session. .. py:attribute:: SHORT :value: 1 .. py:attribute:: MEDIUM :value: 2 .. py:attribute:: LONG :value: 3 .. py:class:: Preferences User preferences for a bite healer demo session. .. py:attribute:: skin_sensitivity :type: SkinSensitivity .. py:attribute:: generation :type: Generation .. py:attribute:: duration :type: Duration .. py:function:: default(enum_type) Returns the default preference for a given :py:class:`~enum.Enum` type. :param enum_type: Enum type which exists as an attribute in :py:class:`.Preferences` and whose corresponding attribute name is equal to the type name converted to snake case. .. py:function:: parse(value, enum_type) Parses a given value into an :py:class:`~enum.Enum` if it isn’t one yet. :param value: an `Enum` value or a corresponding name, written in lower case. :param enum_type: the type of the `Enum` to parse into. :return: an instance of `enum_type` that represents `value`. If `value` is already an instance of `enum_type`, then the return value is `value` itself.