Last active
February 25, 2023 18:40
-
-
Save hober/b1aa525e1e2bbca1ddeb12d43ba6090a to your computer and use it in GitHub Desktop.
I don't understand why mypy likes this code but doesn't like the previous revision of this gist.
This file contains 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
from dataclasses import dataclass | |
from typing import Optional, Protocol, TypeVar | |
class ProtoA(Protocol): | |
def a(self) -> None: | |
... | |
Why_Though = TypeVar('Why_Though', bound=ProtoA) | |
class ProtoB(Protocol[Why_Though]): | |
a: Why_Though | |
class RealA: | |
def a(self) -> None: | |
pass | |
@dataclass | |
class RealB: | |
a: RealA | |
def main(b: ProtoB) -> None: | |
if b.a is not None: | |
b.a.a() | |
if __name__ == '__main__': | |
main(RealB(a=RealA())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment