Download Python/train/3.8/protocol/modern_04.py from SwashBuckler001/idiombench: direct link, hf CLI and curl.
- Browser
- Download file 729 Bytes
-
https://huggingface.co/datasets/SwashBuckler001/idiombench/resolve/main/Python/train/3.8/protocol/modern_04.py
- Command line
-
hf download hf://datasets/SwashBuckler001/idiombench/Python/train/3.8/protocol/modern_04.py
-
curl -L -o modern_04.py https://huggingface.co/datasets/SwashBuckler001/idiombench/resolve/main/Python/train/3.8/protocol/modern_04.py
729 Bytes
| class PColor(Protocol): | |
| def draw(self) -> str: | |
| ... | |
| def complex_method(self) -> int: | |
| ... | |
| # some complex code here | |
| class NiceColor(PColor): | |
| def draw(self) -> str: | |
| return "deep blue" | |
| class BadColor(PColor): | |
| def draw(self) -> str: | |
| return super().draw() # Error, no default implementation | |
| class ImplicitColor: # Note no 'PColor' base here | |
| def draw(self) -> str: | |
| return "probably gray" | |
| def complex_method(self) -> int: | |
| ... | |
| # class needs to implement this | |
| nice: NiceColor | |
| another: ImplicitColor | |
| def represent(c: PColor) -> None: | |
| print(c.draw(), c.complex_method()) | |
| represent(nice) # OK | |
| represent(another) # Also OK | |