-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type Hints, Lazy Evaluation (Inheritance & Dependencies), New Top Lev…
…el Interfaces (#205) * adds some stubs to the underlying decorator that should help with type hinting in VSCode (via pylance/pyright). changed packaging to reflect the stubs and partial type info. added in two forms of lazy evaluation: (1) the @spock decorator now has a boolean flag that allows inherited classes to not be @spock decorated -- will automatically cast parent classes to a spock class by traversing the MRO, (2) the ConfigArgBuilder now takes a keyword argument that will attempt to lazily handle dependencies between @spock decorated classes thus preventing the need for every @spock decorated classes to be passed into *args within the method * fixing spockTuner class based on new underlying functions. adding in stubs for type hinting * linted * added more tests that should cover new graph and inheritance laziness * updated docs for lazy evaluation. added in method that lazily finds parents and adds them to the input_class list if within the underlying spock module
- Loading branch information
Showing
44 changed files
with
728 additions
and
178 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include versioneer.py | ||
include spock/_version.py | ||
include "README.md", "LICENSE.txt", "NOTICE.txt", "CONTRIBUTING.md" |
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
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,39 @@ | ||
from typing import Any, Callable, Tuple, TypeVar, Union, overload | ||
|
||
from attr import attrib, field | ||
|
||
_T = TypeVar("_T") | ||
_C = TypeVar("_C", bound=type) | ||
|
||
# Note: from here | ||
# https://github.com/python-attrs/attrs/blob/main/src/attr/__init__.pyi | ||
|
||
# Static type inference support via __dataclass_transform__ implemented as per: | ||
# https://github.com/microsoft/pyright/blob/main/specs/dataclass_transforms.md | ||
# This annotation must be applied to all overloads of "spock_attr" | ||
|
||
# NOTE: This is a typing construct and does not exist at runtime. Extensions | ||
# wrapping attrs decorators should declare a separate __dataclass_transform__ | ||
# signature in the extension module using the specification linked above to | ||
# provide pyright support -- this currently doesn't work in PyCharm | ||
def __dataclass_transform__( | ||
*, | ||
eq_default: bool = True, | ||
order_default: bool = False, | ||
kw_only_default: bool = False, | ||
field_descriptors: Tuple[Union[type, Callable[..., Any]], ...] = (()), | ||
) -> Callable[[_T], _T]: ... | ||
@overload | ||
@__dataclass_transform__(kw_only_default=True, field_descriptors=(attrib, field)) | ||
def _spock_tune( | ||
maybe_cls: _C, | ||
kw_only: bool = True, | ||
make_init: bool = True, | ||
) -> _C: ... | ||
@overload | ||
@__dataclass_transform__(kw_only_default=True, field_descriptors=(attrib, field)) | ||
def _spock_tune( | ||
maybe_cls: None = ..., | ||
kw_only: bool = True, | ||
make_init: bool = True, | ||
) -> Callable[[_C], _C]: ... |
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.