Download Python/train/3.8/protocol/modern_14.py from SwashBuckler001/idiombench: direct link, hf CLI and curl.
- Browser
- Download file 490 Bytes
-
https://huggingface.co/datasets/SwashBuckler001/idiombench/resolve/main/Python/train/3.8/protocol/modern_14.py
- Command line
-
hf download hf://datasets/SwashBuckler001/idiombench/Python/train/3.8/protocol/modern_14.py
-
curl -L -o modern_14.py https://huggingface.co/datasets/SwashBuckler001/idiombench/resolve/main/Python/train/3.8/protocol/modern_14.py
490 Bytes
| # file lib.py | |
| from typing import Sized | |
| T = TypeVar('T', contravariant=True) | |
| class ListLike(Sized, Protocol[T]): | |
| def append(self, x: T) -> None: | |
| pass | |
| def populate(lst: ListLike[int]) -> None: | |
| ... | |
| # file main.py | |
| from lib import populate # Note that ListLike is NOT imported | |
| class MockStack: | |
| def __len__(self) -> int: | |
| return 42 | |
| def append(self, x: int) -> None: | |
| print(x) | |
| populate([1, 2, 3]) # Passes type check | |
| populate(MockStack()) # Also OK | |