$ pyright mycode_test.py
pyright 1.1.261
./mycode_test.py
./mycode_test.py:42:16 - error: Cannot assign member "slow_method" for type "Gizmo"
Expression of type "() -> Literal[3]" cannot be assigned to member "slow_method" of class "Gizmo"
Type "() -> Literal[3]" cannot be assigned to type "() -> Frob"
Function return type "Literal[3]" is incompatible with type "Frob"
"Literal[3]" is incompatible with "Frob" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informations
Completed in 0.564sec
exit code: 1
Last active
July 19, 2022 21:12
-
-
Save bukzor/c11517f8a5c38b62cab157d25492caea 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
from __future__ import annotations | |
def thing_to_test(gizmo: Gizmo): | |
return gizmo.slow_method() | |
class Frob: | |
pass | |
class Gizmo: | |
def slow_method(self): | |
return Frob() |
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
import typing | |
from unittest.mock import Mock | |
import mycode | |
def fake_slow_method(): | |
return mycode.Frob() | |
def fake_slow_method_wrong(): | |
return 3 | |
def test_a_thing(): | |
mocked_gizmo = typing.cast(mycode.Gizmo, Mock()) | |
mocked_gizmo.slow_method = fake_slow_method | |
assert mycode.thing_to_test(mocked_gizmo) == 3 | |
def test_a_thing_wrong(): | |
mocked_gizmo = typing.cast(mycode.Gizmo, Mock()) | |
mocked_gizmo.slow_method = fake_slow_method_wrong | |
assert mycode.thing_to_test(mocked_gizmo) == 3 |
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
[tool.pyright] | |
include = ["**"] | |
typeCheckingMode = "strict" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment