-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added failing test case for annotated * Fix issues with Annotated * fix failing CI checks * cleaned up pr --------- Co-authored-by: Samuel Hodges <[email protected]> Co-authored-by: Wessel <[email protected]>
- Loading branch information
1 parent
68f5110
commit 9b42fae
Showing
5 changed files
with
63 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import sys | ||
from typing import Literal | ||
|
||
if sys.version_info < (3, 9): | ||
import typing_extensions | ||
|
||
get_type_hints = typing_extensions.get_type_hints | ||
get_origin = typing_extensions.get_origin | ||
get_args = typing_extensions.get_args | ||
|
||
def is_literal(x): | ||
return x == Literal and not isinstance(x, typing_extensions.Annotated) | ||
|
||
else: | ||
import typing | ||
|
||
get_type_hints = typing.get_type_hints | ||
get_origin = typing.get_origin | ||
get_args = typing.get_args | ||
|
||
def is_literal(x): | ||
return x == Literal |
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,29 @@ | ||
import sys | ||
|
||
if sys.version_info < (3, 9): | ||
from typing_extensions import Annotated | ||
else: | ||
from typing import Annotated | ||
|
||
import pytest | ||
from beartype.vale import Is | ||
|
||
from plum import Dispatcher, NotFoundLookupError | ||
|
||
|
||
def test_simple_annotated(): | ||
dispatch = Dispatcher() | ||
|
||
positive_int = Annotated[int, Is[lambda value: value > 0]] | ||
|
||
@dispatch | ||
def f(x: positive_int): | ||
return x | ||
|
||
assert f(1) == 1 | ||
|
||
with pytest.raises(NotFoundLookupError): | ||
f("my string") | ||
|
||
with pytest.raises(NotFoundLookupError): | ||
f(-1) |