Created
May 3, 2025 11:34
-
-
Save mypy-play/99c760889e2ef17d6b4fc94af9285e73 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
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 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