Last active
February 23, 2020 20:46
-
-
Save hjwp/e322c86d14ce0b11f08b27d7b17f7791 to your computer and use it in GitHub Desktop.
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
def foo() -> int: | |
return 42 |
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
from typing import Protocol | |
class MyType(Protocol): | |
def foo(self) -> int: | |
... | |
class MyClass: | |
def foo(self) -> int: | |
return 1 | |
# this is OK | |
a = MyClass() # type: MyType | |
import mymodule | |
# mymodule.py just contains | |
# def foo() -> int: | |
# return 42 | |
# but this is not. | |
b = mymodule # type: MyType | |
# mypy complains saying | |
# Incompatible types in assignment (expression has type Module, variable has type "MyType") | |
import inspect | |
print(inspect.signature(a.foo)) | |
print(inspect.signature(b.foo)) | |
# both print: () -> int |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment