Comparity#

Comparities are powerful classes which allow for comparisons between 2 objects to be withheld till needed, this is extremely useful with variables and expressions where the value may not be immediatley known.

Comparity#

class cake.Comparity(left: L, right: R, symbol: ComparitySymbol)[source]#

Bases: Generic[L, R]

Generic class for representing a comparison between 2 values, Values can be chained.

>>> (5 < x)
Comparity(x > 5)
>>> (5 < x) < y
Comparity(y > x > 5)
>>> ((x < 5) > y) < z
Comparity(z > y < x < 5)
fits(**kwds) bool[source]#

Checks whether given values fit inside of the comparitive expression, for chained expressions each pair is worked out, any pairs returning Comparity are assumed False.

Note

Any variables must be passed as a kwarg!

>>> c = x > 5
>>> c
Comparity(x > 5)
>>> c.fits(x=6)
True
>>> c.fits(x=1)
False

Comparity Symbol#

class cake.ComparitySymbol(value)[source]#

Bases: str, Enum

Represents the comparison being made between 2 objects.

EQUAL_TO

  • Represents the == operator

NOT_EQUAL_TO

  • Represents the != operator

GREATER_THAN

  • Represents the > operator

GREATER_OR_EQUAL_TO

  • Represents the >= operator

LESS_THAN

  • Represents the < operator

LESS_OR_EQUAL_TO

  • Represents the <= operator