itchcraft.prefs

User preferences

Attributes

CliEnum

Helper union type consisting of an Enum and its stringified values.

Classes

SkinSensitivity

Whether or not a person’s skin is particularly sensitive.

Generation

The age cohort of a person.

Duration

The duration of a demo session.

Preferences

User preferences for a bite healer demo session.

Functions

default(enum_type)

Returns the default preference for a given Enum type.

parse(value, enum_type)

Parses a given value into an Enum if it isn’t one yet.

Module Contents

itchcraft.prefs.CliEnum

Helper union type consisting of an 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:

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":

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")
class itchcraft.prefs.SkinSensitivity

Bases: enum.Enum

Whether or not a person’s skin is particularly sensitive.

SENSITIVE = 1
REGULAR = 2
class itchcraft.prefs.Generation

Bases: enum.Enum

The age cohort of a person.

CHILD = 1
ADULT = 2
class itchcraft.prefs.Duration

Bases: enum.Enum

The duration of a demo session.

SHORT = 1
MEDIUM = 2
LONG = 3
class itchcraft.prefs.Preferences

User preferences for a bite healer demo session.

skin_sensitivity: SkinSensitivity
generation: Generation
duration: Duration
itchcraft.prefs.default(enum_type)

Returns the default preference for a given Enum type.

Parameters:

enum_type (type[_E]) – Enum type which exists as an attribute in Preferences and whose corresponding attribute name is equal to the type name converted to snake case.

Return type:

str

itchcraft.prefs.parse(value, enum_type)

Parses a given value into an Enum if it isn’t one yet.

Parameters:
  • value (CliEnum[_E]) – an Enum value or a corresponding name, written in lower case.

  • enum_type (type[_E]) – the type of the Enum to parse into.

Returns:

an instance of enum_type that represents value. If value is already an instance of enum_type, then the return value is value itself.

Return type:

_E