-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced wrap generic to dispatch construction to third-party subcl…
…asses. (#54) This is necessary as we can't dispatch to different subclasses in DelayedArray's own __init__ method. So, developers need to write their own method for wrap() in order to construct a custom DelayedArray subclass based on their seed type.
- Loading branch information
Showing
7 changed files
with
53 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
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,27 @@ | ||
from functools import singledispatch | ||
from typing import Any | ||
|
||
from .DelayedArray import DelayedArray | ||
|
||
|
||
@singledispatch | ||
def wrap(x: Any) -> DelayedArray: | ||
"""Create a :py:class:`~delayedarray.DelayedArray.DelayedArray` from an | ||
object satisfying the seed contract. Developers can implement methods for | ||
this generic to create ``DelayedArray`` subclasses based on the seed type. | ||
Args: | ||
x: | ||
Any object satisfiying the seed contract, see documentation for | ||
:py:class:`~delayedarray.DelayedArray.DelayedArray` for details. | ||
Returns: | ||
A ``DelayedArray`` or one of its subclasses. | ||
""" | ||
return DelayedArray(x) | ||
|
||
|
||
@wrap.register | ||
def wrap_DelayedArray(x: DelayedArray): | ||
"""See :py:meth:`~delayedarray.wrap.wrap`.""" | ||
return x |
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