Skip to content

Commit 47e328c

Browse files
authored
fix(typing): ensure create_decoy typing accepts ABC as spec (#20)
1 parent f8c49eb commit 47e328c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

decoy/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Decoy test double stubbing and verification library."""
22
from os import linesep
3-
from typing import cast, Any, Optional, Sequence, Type
3+
from typing import cast, Any, Callable, Optional, Sequence
44
from warnings import warn
55

66
from .registry import Registry
@@ -56,7 +56,12 @@ def __getattribute__(self, name: str) -> Any:
5656

5757
return actual_method
5858

59-
def create_decoy(self, spec: Type[ClassT], *, is_async: bool = False) -> ClassT:
59+
def create_decoy(
60+
self,
61+
spec: Callable[..., ClassT],
62+
*,
63+
is_async: bool = False,
64+
) -> ClassT:
6065
"""Create a class decoy for `spec`.
6166
6267
Arguments:

tests/typing/test_typing.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
out: |
1515
main:9: note: Revealed type is 'main.Dependency*'
1616
17+
- case: class_decoy_mimics_abstract_class_type
18+
main: |
19+
from abc import ABC
20+
from decoy import Decoy
21+
22+
class Dependency(ABC):
23+
def do_thing(self, input: str) -> int:
24+
...
25+
26+
decoy = Decoy()
27+
fake = decoy.create_decoy(spec=Dependency)
28+
reveal_type(fake)
29+
out: |
30+
main:10: note: Revealed type is 'main.Dependency*'
31+
1732
- case: function_decoy_mimics_type
1833
main: |
1934
from decoy import Decoy

0 commit comments

Comments
 (0)