# 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