-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: type checking logic for awaitable and coroutine (#64)
* bugfix: type checking logic for awaitable and coroutine * fix doctest * fix tests and coverage Co-authored-by: Willi Sontopski <willi.sontopski@peerox.de>
- Loading branch information
1 parent
8246efc
commit 86cb684
Showing
11 changed files
with
615 additions
and
17 deletions.
There are no files selected for viewing
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
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
385 changes: 385 additions & 0 deletions
385
docs/pedantic/tests/test_assert_value_matches_type.html
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import unittest | ||
from dataclasses import dataclass | ||
from typing import Callable, Awaitable, Coroutine | ||
|
||
from pedantic.exceptions import PedanticTypeCheckException | ||
from pedantic.type_checking_logic.check_types import assert_value_matches_type | ||
|
||
|
||
@dataclass | ||
class Foo: | ||
value: int | ||
|
||
|
||
class TestAssertValueMatchesType(unittest.TestCase): | ||
def test_callable(self): | ||
def _cb(foo: Foo) -> str: | ||
return str(foo.value) | ||
|
||
assert_value_matches_type( | ||
value=_cb, | ||
type_=Callable[..., str], | ||
err='', | ||
type_vars={}, | ||
) | ||
|
||
with self.assertRaises(expected_exception=PedanticTypeCheckException): | ||
assert_value_matches_type( | ||
value=_cb, | ||
type_=Callable[..., int], | ||
err='', | ||
type_vars={}, | ||
) | ||
|
||
def test_callable_awaitable(self): | ||
async def _cb(foo: Foo) -> str: | ||
return str(foo.value) | ||
|
||
assert_value_matches_type( | ||
value=_cb, | ||
type_=Callable[..., Awaitable[str]], | ||
err='', | ||
type_vars={}, | ||
) | ||
|
||
with self.assertRaises(expected_exception=PedanticTypeCheckException): | ||
assert_value_matches_type( | ||
value=_cb, | ||
type_=Callable[..., Awaitable[int]], | ||
err='', | ||
type_vars={}, | ||
) | ||
|
||
with self.assertRaises(expected_exception=PedanticTypeCheckException): | ||
assert_value_matches_type( | ||
value=_cb, | ||
type_=Callable[..., str], | ||
err='', | ||
type_vars={}, | ||
) | ||
|
||
def test_coroutine_awaitable(self): | ||
async def _cb(foo: Foo) -> str: | ||
return str(foo.value) | ||
|
||
assert_value_matches_type( | ||
value=_cb, | ||
type_=Callable[..., Coroutine[None, None, str]], | ||
err='', | ||
type_vars={}, | ||
) | ||
|
||
with self.assertRaises(expected_exception=PedanticTypeCheckException): | ||
assert_value_matches_type( | ||
value=_cb, | ||
type_=Callable[..., Coroutine[None, None, int]], | ||
err='', | ||
type_vars={}, | ||
) |
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
Oops, something went wrong.