-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from scrapinghub/annotated-support
Support annotated deps in serialization and testing.
- Loading branch information
Showing
6 changed files
with
162 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
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,26 @@ | ||
from dataclasses import dataclass | ||
from typing import Any, Tuple | ||
|
||
|
||
@dataclass | ||
class AnnotatedInstance: | ||
"""Wrapper for instances of annotated dependencies. | ||
It is used when both the dependency value and the dependency annotation are | ||
needed. | ||
:param result: The wrapped dependency instance. | ||
:type result: Any | ||
:param metadata: The copy of the annotation. | ||
:type metadata: Tuple[Any, ...] | ||
""" | ||
|
||
result: Any | ||
metadata: Tuple[Any, ...] | ||
|
||
def get_annotated_cls(self): | ||
"""Returns a re-created :class:`typing.Annotated` type.""" | ||
from typing import Annotated | ||
|
||
return Annotated[(type(self.result), *self.metadata)] |
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