joythief.core module

class joythief.core.Matcher[source]

Bases: Generic[T], ABC

Abstract base class for all other matchers.

Defines the core requirements for any matcher:

As __eq__ and __repr__ are defined in Matcher itself, to provide core matcher behaviour, this abstract base class defines two equivalent abstract methods: compare() and represent(). You can write custom matchers by implementing these methods:

import typing as tp

from joythief.core import Matcher


class IsWelcoming(Matcher[str]):

    def compare(self, other: tp.Any) -> bool:
        return other == "hello, world"

    def represent(self) -> str:
        return super().represent()  # 'IsWelcoming()'
joythief.core.MaybeMatcher

Either T or a matcher of T.

alias of T | Matcher[T]