teext.constraints

Types that express a constraint.

Data:

Fraction(x)

NaturalNum(x)

Percentage(x)

PositiveInt(x)

Probability(x)

Functions:

assert_fraction(num)

Assert that the given number is a fraction.

assert_natural_num(num)

Assert that the given number is a natural number.

assert_percentage(num)

Assert that the given number is a percentage.

assert_positive_int(num)

Assert that the given number is a positive integer.

assert_prob(num)

Assert that the given number is a probability.

is_fraction(num)

Check whether the given number is a fraction.

is_natural_num(num)

Check whether the given number is a natural number.

is_percentage(num)

Check whether the given number is a percentage.

is_positive_int(num)

Check whether the given number is a positive integer.

is_prob(num)

Check whether the given number is a probability.

Fraction

A type for fractions (i.e., floats between 0 and 1, inclusive).

alias of float

NaturalNum

A type for natural numbers (i.e., integers without the negative numbers).

alias of int

Percentage

A type for percentages (i.e., floats between 0 and 1, inclusive).

alias of float

PositiveInt

A type for positive integers.

alias of int

Probability

A type for probabilities (i.e., floats between 0 and 1, inclusive).

alias of float

assert_fraction(num)

Assert that the given number is a fraction.

Parameters

num (float) –

Return type

Fraction

assert_natural_num(num)

Assert that the given number is a natural number.

Parameters

num (int) –

Return type

NaturalNum

assert_percentage(num)

Assert that the given number is a percentage.

Parameters

num (float) –

Return type

Percentage

assert_positive_int(num)

Assert that the given number is a positive integer.

Parameters

num (int) –

Return type

PositiveInt

assert_prob(num)

Assert that the given number is a probability.

Parameters

num (float) –

Return type

Probability

is_fraction(num)

Check whether the given number is a fraction.

Parameters

num (float) –

Return type

typing_extensions.TypeGuard[Fraction]

is_natural_num(num)

Check whether the given number is a natural number.

Parameters

num (int) –

Return type

typing_extensions.TypeGuard[NaturalNum]

is_percentage(num)

Check whether the given number is a percentage.

Parameters

num (float) –

Return type

typing_extensions.TypeGuard[Percentage]

is_positive_int(num)

Check whether the given number is a positive integer.

Parameters

num (int) –

Return type

typing_extensions.TypeGuard[PositiveInt]

is_prob(num)

Check whether the given number is a probability.

Parameters

num (float) –

Return type

typing_extensions.TypeGuard[Probability]