Last active
November 2, 2023 14:33
-
-
Save kejadlen/e051ef080ed5ed8b04b9635eb0f0f487 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
from typing import Literal, Protocol, Optional | |
class Side: | |
... | |
class Wombat: | |
... | |
class Frobnicator(Protocol): | |
def frobnicate(self, left: Optional[Wombat], right: Optional[Wombat]): | |
... | |
@dataclass | |
class Fnord: | |
is_triangular: bool | |
@dataclass | |
class Grault: | |
color: Literal["red", "green"] | |
fnord: Fnord | |
left: Optional[Wombat] | |
right: Optional[Wombat] | |
class GraultFrobnicator: | |
def __init__(self, frobnicator: Frobnicator): | |
self.frobnicator = frobnicator | |
def frobnicate(self, grault: Grault): | |
if not ( | |
(grault.color is None) | |
or (grault.color == "red" and grault.fnord.is_triangular) | |
): | |
return | |
if grault.left is None and grault.right is None: | |
return | |
self.frobnicator.frobnicate(grault.left, grault.right) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment