Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 24, 2024 22:22
Show Gist options
  • Save mypy-play/20278be77b4ecaca10c4e180752808c4 to your computer and use it in GitHub Desktop.
Save mypy-play/20278be77b4ecaca10c4e180752808c4 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
# mypy: no-strict-optional
from typing import overload, Protocol
class Descriptor:
@overload
def __get__(self, instance: None, owner: type) -> int: ...
@overload
def __get__(self, instance: object, owner: type) -> str: ...
def __get__(self, instance: object | None, owner: type) -> int | str: ...
class A:
prop = Descriptor()
x : int = A.prop
y : str = A().prop
a_or_none: A | None
z : str = a_or_none.prop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment