Skip to content

Instantly share code, notes, and snippets.

@akaptur
Last active December 14, 2021 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akaptur/93756c965c56514be7f1abc9afe98f0d to your computer and use it in GitHub Desktop.
Save akaptur/93756c965c56514be7f1abc9afe98f0d to your computer and use it in GitHub Desktop.
from typing import Protocol
class MyProto(Protocol):
value: str
@dataclass
class A:
value: str
@dataclass
class B:
value: str
image: str
def my_func(obj: MyProto) -> str: # note the changed the type annotation
return obj.value
my_func(B("hi", "a gzipped photo of a cat")) # no error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment