const module

Contains redscience constants plus functions for internationalization and versioning.

Most constants in this module are encoded as a category.Category or as a NamedTuple. Each displays in the locale set via setlang() and excludes members not in the version set via setvers().

Examples:

import matplotlib.pyplot as plt

ttt=Game()
ipywidgets.Dropdown(options=sorted(Command), value=Command.QUIT)
ipywidgets.Button(
    description=Command.QUIT,
    tooltip=Command.QUIT.TOOLTIP,
    icon=Command.QUIT.ICON,
)
fig = plt.figure(1,(
    Layout.FIGURE_HEIGHT,
    Layout.FIGURE_WIDTH,
))
ax = ttt.AXES(fig)
ax.scatter(
    x = 1,
    y = 1,
    c = Color.WHITE.HEX,
    marker = Marker.CIRCLE.CODE,
    edgecolors = Color.BLACK.HEX,
)

setlang(")
setvers("")
print(ttt.RULES)
print(Command.QUIT)
plt.show()

General Constants

Color

class const.Color(value)[source]

Bases: category.Categorized

Color used in a game. E.g.:

Color.BLACK

Attributes:

STR (str)

A localized name. How the color prints.

HEX (str)

A hex code to communicate the color to computers.

VERSIONS (Iterable)

The versions which offer this color.

BLACK = _Color(STR='black', HEX='#000000', VERSIONS=(-inf,+inf))
BLUE = _Color(STR='blue', HEX='#95d0fc', VERSIONS=(-inf,+inf))
GRAY = _Color(STR='gray', HEX='#929591', VERSIONS=(-inf,+inf))
GREEN = _Color(STR='green', HEX='#96f97b', VERSIONS=(-inf,+inf))
ORANGE = _Color(STR='orange', HEX='#fdaa48', VERSIONS=(-inf,+inf))
PINK = _Color(STR='pink', HEX='#ff81c0', VERSIONS=(-inf,+inf))
PURPLE = _Color(STR='purple', HEX='#bf77f6', VERSIONS=(-inf,+inf))
WHITE = _Color(STR='white', HEX='#ffffff', VERSIONS=(-inf,+inf))
YELLOW = _Color(STR='yellow', HEX='#ffff14', VERSIONS=(-inf,+inf))

Command

class const.Command(value)[source]

Bases: category.Categorized

Command from user to the application. E.g.:

Command.NEW

Attributes:

STR (str)

A localized name. How the command prints.

KEY (str)

A localized shortcut key.

VERSIONS (Iterable)

The versions which offer this command.

Each command tests == to its KEY as well as to itself. For example, if the language is English:

>>> Command.NEW == "n"
True
NEW = _Command(STR='Play New', KEY='n', VERSIONS=(-inf,+inf))
QUIT = _Command(STR='Quit', KEY='q', VERSIONS=(-inf,+inf))
UNDO = _Command(STR='Back', KEY='z', VERSIONS=(-inf,+inf))

Layout

class const.Layout(value)[source]

Bases: enum.IntEnum

Layout constants. E.g.:

Layout.POINTS_PER_INCH

See enum.IntEnum

FIGURE_HEIGHT = 5
FIGURE_WIDTH = 5
MARKER_MARGIN = 8
POINTS_PER_INCH = 54

Player Constants

Player

class const.Player(TYPE: const._PlayerType = PlayerType.HUMAN)[source]

Bases: tuple

The constant parts of a player. E.g.:

Player()  # To use all defaults (i.e. human)

Attributes:

TYPE (PlayerType)

If specified, determines the type. Default is Human.

property VERSIONS: Iterable

The versions in which this player can be selected.

PlayerType

class const.PlayerType(value)[source]

Bases: category.Categorized

Type of player. E.g.:

PlayerType.HUMAN

Attributes:

STR (str)

A localized name. How the type prints.

VERSIONS (Iterable)

The versions which offer this PlayerType.

ANONYMOUS = _PlayerType(STR='Anonymous', VERSIONS=(-inf,+inf))
HUMAN = _PlayerType(STR='Human', VERSIONS=[(1, 2, 0, '~'),+inf))

PlayerColor

class const.PlayerColor(value)

Bases: category.Categorized

Color used in a game. E.g.:

Color.BLACK

Attributes:

STR (str)

A localized name. How the color prints.

HEX (str)

A hex code to communicate the color to computers.

VERSIONS (Iterable)

The versions which offer this color.

BLACK = _Color(STR='black', HEX='#000000', VERSIONS=(-inf,+inf))
PINK = _Color(STR='pink', HEX='#ff81c0', VERSIONS=(-inf,+inf))
WHITE = _Color(STR='white', HEX='#ffffff', VERSIONS=(-inf,+inf))
YELLOW = _Color(STR='yellow', HEX='#ffff14', VERSIONS=(-inf,+inf))

DefaultName

class const.DefaultName(value)[source]

Bases: category.Categorized

Default names for players. E.g.:

DefaultName.PLAYER_ONE

Attributes:

STR (str)

A localized name. How the name prints.

VERSIONS (Iterable)

The versions which offer this name.

PLAYER_FOUR = _DefaultName(STR='Player 4', VERSIONS=[(1, 5, 0, '~'),+inf))
PLAYER_ONE = _DefaultName(STR='Player 1', VERSIONS=(-inf,+inf))
PLAYER_THREE = _DefaultName(STR='Player 3', VERSIONS=[(1, 5, 0, '~'),+inf))
PLAYER_TWO = _DefaultName(STR='Player 2', VERSIONS=(-inf,+inf))

Piece Constants

Marker

class const.Marker(value)[source]

Bases: category.Categorized

The shape of a game piece. E.g.:

Marker.CIRCLE

Attributes:

STR (str)

A localized name. How the narker prints.

CODE (str)

A matplotlib.marker.

VERSIONS (Iterable)

The versions which offer this marker.

CIRCLE = _Marker(STR='circle', CODE='o', VERSIONS=(-inf,+inf))

PieceRules

class const.PieceRules(INITIAL_RESERVES: Tuple[int, ...])[source]

Bases: tuple

Rules for a type of piece in a game. E.g.:

PieceRules(INITIAL_RESERVES=(5,4))

Attributes:

INITIAL_RESERVES (Tuple[int, …])

Specifies the number of each color in initial reserves, e.g. (5, 4) means start with 5 of the first color and 4 of the second color in reserve.

property RESERVES_STR: str

A constant localized str describing initial reserves for the piece. E.g.:

>>> piece.RESERVES_STR
'5 black and 4 white start in reserve'
property STRS: Tuple[str, ...]

Get tuple of strings describing the rules for the piece. E.g.:

>>> piece.STRS
('No movement', 'No power', '5 black and 4 white start in reserve')
property VERSIONS: Iterable

The versions which offer this piece. E.g.:

>>> piece.VERSIONS
(-inf, +inf)

Directions

class const.Directions(value)[source]

Bases: category.Categorized

Categories of ways in which to move or build in square-tiled space. E.g:

>>> Directions.DIAGONAL(2)

((1,1), (1,-1), (-1,1), (-1,-1))

Parameters

dimensions (int) – The number of dimensions in the space

Returns

Of relative coordinates (each a numpy.array of int)

Return type

tuple

Attributes:

STR (str)

A localized name. How the Directions prints.

CALL (Callable)

The bound method that yields the tuples.

VERSIONS (Iterable)

The versions which offer this option.

Tip

To get cache info:

Directions.DIAGONAL.call.cache_info()
ANY = _DirectionsValue(STR='any direction', CALL=<functools._lru_cache_wrapper object>, VERSIONS=(-inf,+inf))
DIAGONAL = _DirectionsValue(STR='diagonal', CALL=<functools._lru_cache_wrapper object>, VERSIONS=(-inf,+inf))
KNIGHT = _DirectionsValue(STR='knight move', CALL=<functools._lru_cache_wrapper object>, VERSIONS=(-inf,+inf))
ORTHOGONAL = _DirectionsValue(STR='orthogonal', CALL=<functools._lru_cache_wrapper object>, VERSIONS=(-inf,+inf))

Game Constants

Game

class const.Game(PLAYERS: const._PlayersOption = PlayersOption.TWO, COLOR: const._ColorOption = ColorOption.ASSIGNED, BOARD: const._BoardOption = BoardOption.HASH, DIMENSIONS: typing.Tuple[int, ...] = (3, 3), PIECES: typing.Tuple[const.PieceRules, ...] = (PieceRules(INITIAL_RESERVES=(5, 4)),), MOVE_CHECKS: typing.Union[typing.Tuple[()], typing.Tuple[const._CheckOption, ...]] = (<CheckOption.THREE_SAME_COLOR_IN_ROW_WINS: _CheckOption(STR='first 3-same-color-in-a-row wins', VERSIONS=(-inf,+inf), PATTERN='CCC', DIRECTIONS=<Directions.ANY: _DirectionsValue(STR='any direction', CALL=<functools._lru_cache_wrapper object>, VERSIONS=(-inf,+inf))>, OUTCOME=<Outcome.VICTORY: _OutcomeValue(STR='Victory', FORMAT='Victory: {players}', CALL=<function Outcome._formatter>, VERSIONS=(-inf,+inf))>)>,), STALEMATE: const._StalemateOption = StalemateOption.DRAW)[source]

Bases: tuple

A game definition. E.g.:

Game()  # To use all defaults (i.e. Tic-Tac-Toe)

Attributes:

PLAYERS (PlayersOption)

If specified, determines the number/ relationship of players. Default is 2-Player.

COLOR (ColorOption)

If specified, determines the significance of colors. Default is Assigned Colors.

BOARD (BoardOption)

If specified, determines the type of board. Default is hash.

DIMENSIONS (Tuple[int, …])

If specified, determines the dimensions of the board. Default is (3,3).

PIECES (Tuple[PieceRules, …])

If specified, determines piece-specific rules. Default is to have only one type of piece (circle) with 5 black and 4 white circles starting in reserve.

MOVE_CHECKS (Tuple[CheckOption, …])

If specified, determines which rules are checked at the end of each move. Can be None. Default is to award the win to any player that gets three of the same color in a row.

STALEMATE (StalemateOption)

If specified, determines the result of stalemate. Default is that stalemate results in a draw.

AXES(fig: matplotlib.figure.Figure) matplotlib.axes._axes.Axes[source]

The board in terms of matplotlib E.g.:

import matplotlib.pyplot as plt
figure = plt.figure(1,(
    Layout.FIGURE_HEIGHT,
    Layout.FIGURE_WIDTH,
))
game.AXES(fig=figure)
plt.show()
Parameters

fig (matplotlib.figure.Figure_) – The Figure in which the Axes will appear

Returns

A framework in which to place pieces

Return type

matplotlib.axes.Axes

property MARKER_SIZE: float

The (int) size for markers in this game. E.g.:

>>> Game().MARKER_SIZE
6724
property RULES: str

A localized str of check and stalemate rules. E.g:

>>>game().RULES ‘Rules: First 3-same-color-in-a-row wins and stalemate draws’

property VERSIONS: Iterable

The (Tuple) versions which offer this Game. E.g.:

>>> Game().VERSIONS
(-inf,+inf)

PlayersOption

class const.PlayersOption(value)[source]

Bases: category.Categorized

Category of game by number/relationship of players. E.g.:

PlayersOption.TWO

Attributes:

STR (str)

A localized name. How the option prints.

NUM (int)

The number of regular players.

VERSIONS (Iterable)

The versions which offer this option.

THREE = _PlayersOption(STR='3-Player', NUM=3, VERSIONS=(-inf,+inf))
TWO = _PlayersOption(STR='2-Player', NUM=2, VERSIONS=(-inf,+inf))

ColorOption

class const.ColorOption(value)[source]

Bases: category.Categorized

Category of game by how it treats colors. E.g.:

ColorOption.ASSIGNED

Attributes:

STR (str)

A localized name. How the option prints.

VERSIONS (Iterable)

The versions which offer this marker.

ASSIGNED = _ColorOption(STR='Assigned Colors', VERSIONS=(-inf,+inf))

BoardOption

class const.BoardOption(value)[source]

Bases: category.Categorized

Category of game board. E.g.:

BoardOption.HASH

BoardValue Attributes:

STR (str)

A localized name. How the option prints.

AX (Callable)

Function to return matplotlib.axes.Axes, given a matplotlib.figure.Figure and tuple of dimensions.

VERSIONS (Iterable)

The versions which offer this option.

HASH = _BoardOption(STR='a hash', AX=<function BoardOption._hash_board>, VERSIONS=(-inf,+inf))

CheckOption

class const.CheckOption(value)[source]

Bases: category.Categorized

Game rules checked at the end of each move. E.g.:

CheckOption.THREE_SAME_COLOR_IN_ROW_WINS

Attributes:

STR (str)

A localized name. How the option prints.

VERSIONS (Iterable)

The versions which offer this option.

PATTERN (str)

If specified, a type of pattern to be checked. Default to None.

DIRECTIONS (Directions)

If specified, directions in which to check the pattern. Default to None.

OUTCOME (Outcome)

If specified, the outcome if the check triggers. Default to None.

THREE_SAME_COLOR_IN_ROW_WINS = _CheckOption(STR='first 3-same-color-in-a-row wins', VERSIONS=(-inf,+inf), PATTERN='CCC', DIRECTIONS=<Directions.ANY: _DirectionsValue(STR='any direction', CALL=<functools._lru_cache_wrapper object>, VERSIONS=(-inf,+inf))>, OUTCOME=<Outcome.VICTORY: _OutcomeValue(STR='Victory', FORMAT='Victory: {players}', CALL=<function Outcome._formatter>, VERSIONS=(-inf,+inf))>)

StalemateOption

class const.StalemateOption(value)[source]

Bases: category.Categorized

How statemate ends a game. E.g.:

StalemateOption.DRAW

Attributes:

STR (str)

A localized name. How the option prints.

VERSIONS (Iterable)

The versions which offer this option.

DRAW = _StalemateOption(STR='stalemate draws', VERSIONS=(-inf,+inf))

Move Constants

Move

class const.Move(value)[source]

Bases: category.Categorized

A type of move in a game. Prints localized str. Examples:

Move.PASS
Move.PLACE(COLOR=Color.WHITE, MARKER=Marker.CIRCLE, TO=(2,3))
Move.JUMP(FROM=(1,1), TO=(2,3))

Attributes:

STR (str)

A localized name. How the move prints.

VERSIONS (Iterable)

The versions which offer this Move.

TO (Tuple[int,…])

Only for PLACE and JUMP. destination coordinates.

COLOR (PlayerColor)

Only for PLACE. Color to be placed. Default is black

MARKER (Marker)

Only for PLACE. Shape to be placed. Default is circle.

FROM (Tuple[int, …])

Only for JUMP. Origin coordinates.

AGREE = _Move(STR='Agree to draw', CALL=None, VERSIONS=[(1, 5, 0, '~'),+inf))
JUMP = _Move(STR='Reposition', CALL=<class 'const._Jump'>, VERSIONS=[(1, 5, 0, '~'),+inf))
OFFER = _Move(STR='Offer to draw', CALL=None, VERSIONS=[(1, 5, 0, '~'),+inf))
PASS = _Move(STR='Pass', CALL=None, VERSIONS=(-inf,+inf))
PLACE = _Move(STR='Place from reserves', CALL=<class 'const._Placement'>, VERSIONS=(-inf,+inf))
REFUSE = _Move(STR='Refuse to draw', CALL=None, VERSIONS=[(1, 5, 0, '~'),+inf))

Outcome

class const.Outcome(value)[source]

Bases: category.Categorized

Function to apply localized formatting to strings. E.g:

>>> winners = (DefaultName.PLAYER_ONE, DefaultName.PLAYER_THREE)
>>> Outcome.VICTORY(players=winners)
'Victory: Player 1 and Player 3'
Parameters

**kwargs – a str for each bookmark in the STR

Returns

The localized string.

Return type

str

OutcomeValue Attributes:

STR (str)

A localized name. How the Directions prints.

CALL (Callable)

The bound method that yields the str.

FORMAT (str)

The formatted string for the CALL.

VERSIONS (Iterable)

The versions which offer this option.

VICTORY = _OutcomeValue(STR='Victory', FORMAT='Victory: {players}', CALL=<function Outcome._formatter>, VERSIONS=(-inf,+inf))

Language Functions

setlang()

const.setlang(*langs: str) babel.core.Locale[source]

Gets/sets locale for language functions. E.g.:

setlang()  # to get the currenty set locale
setlang("zh_Hans_HK", "zh_HK")  # to set a language (e.g. for testing)
setlang("")  # to restore the default language
Parameters

*langs (str) – locale names in order of preference.

Returns

The babel.core.Locale that is currently set.

The babel functions can then be used (defaulted to the set language) as follows:

print(format_decimal(-12345.6789))
print(format_percent(-12345.6789))
print(format_unit(-12345.6789, "second"))
print(format_datetime(datetime.datetime.now()))
print(format_list(["Alvin", "Simon", "Theodore"]))
print(_("Hello world!"))

format_datetime()

const.format_datetime(datetime: _Instant = None, format: _PredefinedTimeFormat | str = 'medium', tzinfo: datetime.tzinfo | None = None, *, locale: Locale | str | None = Locale('en')) str

Default locale from setlang() Otherwise: Return a date formatted according to the given pattern.

>>> from datetime import datetime
>>> dt = datetime(2007, 4, 1, 15, 30)
>>> format_datetime(dt, locale='en_US')
u'Apr 1, 2007, 3:30:00\u202fPM'

For any pattern requiring the display of the timezone:

>>> format_datetime(dt, 'full', tzinfo=get_timezone('Europe/Paris'),
...                 locale='fr_FR')
'dimanche 1 avril 2007, 17:30:00 heure d’été d’Europe centrale'
>>> format_datetime(dt, "yyyy.MM.dd G 'at' HH:mm:ss zzz",
...                 tzinfo=get_timezone('US/Eastern'), locale='en')
u'2007.04.01 AD at 11:30:00 EDT'
param datetime

the datetime object; if None, the current date and time is used

param format

one of “full”, “long”, “medium”, or “short”, or a custom date/time pattern

param tzinfo

the timezone to apply to the time for display

param locale

a Locale object or a locale identifier

format_decimal()

const.format_decimal(number: float | decimal.Decimal | str, format: str | NumberPattern | None = None, *, locale: Locale | str | None = Locale('en'), decimal_quantization: bool = True, group_separator: bool = True) str

Default locale from setlang() Otherwise: Return the given decimal number formatted for a specific locale.

>>> format_decimal(1.2345, locale='en_US')
u'1.234'
>>> format_decimal(1.2346, locale='en_US')
u'1.235'
>>> format_decimal(-1.2346, locale='en_US')
u'-1.235'
>>> format_decimal(1.2345, locale='sv_SE')
u'1,234'
>>> format_decimal(1.2345, locale='de')
u'1,234'

The appropriate thousands grouping and the decimal separator are used for each locale:

>>> format_decimal(12345.5, locale='en_US')
u'12,345.5'

By default the locale is allowed to truncate and round a high-precision number by forcing its format pattern onto the decimal part. You can bypass this behavior with the decimal_quantization parameter:

>>> format_decimal(1.2346, locale='en_US')
u'1.235'
>>> format_decimal(1.2346, locale='en_US', decimal_quantization=False)
u'1.2346'
>>> format_decimal(12345.67, locale='fr_CA', group_separator=False)
u'12345,67'
>>> format_decimal(12345.67, locale='en_US', group_separator=True)
u'12,345.67'
param number

the number to format

param format

param locale

the Locale object or locale identifier

param decimal_quantization

Truncate and round high-precision numbers to the format pattern. Defaults to True.

param group_separator

Boolean to switch group separator on/off in a locale’s number format.

format_list()

const.format_list(lst: Sequence[str], style: Literal['standard', 'standard-short', 'or', 'or-short', 'unit', 'unit-short', 'unit-narrow'] = 'standard', *, locale: Locale | str | None = Locale('en')) str

Default locale from setlang() Otherwise:

Format the items in lst as a list.

>>> format_list(['apples', 'oranges', 'pears'], locale='en')
u'apples, oranges, and pears'
>>> format_list(['apples', 'oranges', 'pears'], locale='zh')
u'apples、oranges和pears'
>>> format_list(['omena', 'peruna', 'aplari'], style='or', locale='fi')
u'omena, peruna tai aplari'

These styles are defined, but not all are necessarily available in all locales. The following text is verbatim from the Unicode TR35-49 spec [1].

  • standard: A typical ‘and’ list for arbitrary placeholders. eg. “January, February, and March”

  • standard-short: A short version of a ‘and’ list, suitable for use with short or abbreviated placeholder values. eg. “Jan., Feb., and Mar.”

  • or: A typical ‘or’ list for arbitrary placeholders. eg. “January, February, or March”

  • or-short: A short version of an ‘or’ list. eg. “Jan., Feb., or Mar.”

  • unit: A list suitable for wide units. eg. “3 feet, 7 inches”

  • unit-short: A list suitable for short units eg. “3 ft, 7 in”

  • unit-narrow: A list suitable for narrow units, where space on the screen is very limited. eg. “3′ 7″”

[1]: https://www.unicode.org/reports/tr35/tr35-49/tr35-general.html#ListPatterns

Parameters
  • lst – a sequence of items to format in to a list

  • style – the style to format the list with. See above for description.

  • locale – the locale

format_percent()

const.format_percent(number: float | decimal.Decimal | str, format: str | NumberPattern | None = None, *, locale: Locale | str | None = Locale('en'), decimal_quantization: bool = True, group_separator: bool = True) str

Default locale from setlang() Otherwise: Return formatted percent value for a specific locale.

>>> format_percent(0.34, locale='en_US')
u'34%'
>>> format_percent(25.1234, locale='en_US')
u'2,512%'
>>> format_percent(25.1234, locale='sv_SE')
u'2\xa0512\xa0%'

The format pattern can also be specified explicitly:

>>> format_percent(25.1234, u'#,##0‰', locale='en_US')
u'25,123‰'

By default the locale is allowed to truncate and round a high-precision number by forcing its format pattern onto the decimal part. You can bypass this behavior with the decimal_quantization parameter:

>>> format_percent(23.9876, locale='en_US')
u'2,399%'
>>> format_percent(23.9876, locale='en_US', decimal_quantization=False)
u'2,398.76%'
>>> format_percent(229291.1234, locale='pt_BR', group_separator=False)
u'22929112%'
>>> format_percent(229291.1234, locale='pt_BR', group_separator=True)
u'22.929.112%'
param number

the percent number to format

param format

param locale

the Locale object or locale identifier

param decimal_quantization

Truncate and round high-precision numbers to the format pattern. Defaults to True.

param group_separator

Boolean to switch group separator on/off in a locale’s number format.

format_format_unit()

const.format_unit(value: float | decimal.Decimal, measurement_unit: str, length: Literal['short', 'long', 'narrow'] = 'long', format: str | None = None, *, locale: Locale | str | None = Locale('en')) str

Default locale from setlang() Otherwise: Format a value of a given unit.

Values are formatted according to the locale’s usual pluralization rules and number formats.

>>> format_unit(12, 'length-meter', locale='ro_RO')
u'12 metri'
>>> format_unit(15.5, 'length-mile', locale='fi_FI')
u'15,5 mailia'
>>> format_unit(1200, 'pressure-millimeter-ofhg', locale='nb')
u'1\xa0200 millimeter kvikks\xf8lv'
>>> format_unit(270, 'ton', locale='en')
u'270 tons'

Number formats may be overridden with the format parameter.

>>> import decimal
>>> format_unit(decimal.Decimal("-42.774"), 'temperature-celsius', 'short', format='#.0', locale='fr')
u'-42,8\u202f\xb0C'

The locale’s usual pluralization rules are respected.

>>> format_unit(1, 'length-meter', locale='ro_RO')
u'1 metru'
>>> format_unit(0, 'length-mile', locale='cy')
u'0 mi'
>>> format_unit(1, 'length-mile', locale='cy')
u'1 filltir'
>>> format_unit(3, 'length-mile', locale='cy')
u'3 milltir'
>>> format_unit(15, 'length-horse', locale='fi')
Traceback (most recent call last):
    ...
UnknownUnitError: length-horse is not a known unit in fi

New in version 2.2.0.

param value

the value to format. If this is a string, no number formatting will be attempted.

param measurement_unit

the code of a measurement unit. Known units can be found in the CLDR Unit Validity XML file: https://unicode.org/repos/cldr/tags/latest/common/validity/unit.xml

param length

“short”, “long” or “narrow”

param format

An optional format, as accepted by format_decimal.

param locale

the Locale object or locale identifier

Versioning Functions

setvers()

const.setvers(name: Optional[str] = None) Tuple[Union[int, str], ...][source]

Get or set the version. E.g.:

setvers()  # to get the currenty set version
setlang("1.1.0")  # to set a version (e.g. for testing)
setlang("")  # to restore the default from pyproject.toml
Parameters

name (str) – The name of the version to set. Default to None.

Returns

The currently set version as a tuple.

ALL

const.ALL = (-inf,+inf)

A shortcut for the portion.interval.Interval that contains all (e.g. versions)

from_version()

const.from_version(start: str, to: Optional[str] = None) Iterable[source]

The simple interval starting with a certain version. E.g.:

>>> from_version("1.5.0")
[(1, 5, 0, '~'),+inf)
Parameters
  • start (str) – The starting version

  • to (str) – If set, the (excluded) last version. If None, there is no end version. Default to None.

Returns

The portion.interval.Interval

ntversions()

const.ntversions(self: Iterable) Iterable[source]

The versions which offer a NamedTuple. E.g.:

@property
def VERSIONS(self) -> Iterable:
    return ntversions(self)

Note

This function assumes that each attribute that can contain values specific to a version has a VERSIONS attribute listing valid versions as a portion.interval.Interval