Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 3, 2025 11:34
Show Gist options
  • Save mypy-play/99c760889e2ef17d6b4fc94af9285e73 to your computer and use it in GitHub Desktop.
Save mypy-play/99c760889e2ef17d6b4fc94af9285e73 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import Protocol
class Descriptor:
def __get__(self, instance, owner) -> int:
return 42
class Foo(Protocol):
x: Descriptor = Descriptor()
class Bar(Protocol):
@property
def x(self) -> int:
return 42
class HasX:
def __init__(self) -> None:
self.x: int = 42
def f(obj: Foo): ...
def g(obj: Bar): ...
f(HasX())
g(HasX())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment