-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/transform #60
Conversation
meiga/result.py
Outdated
@@ -31,6 +37,7 @@ def __init__( | |||
self._value_success = success | |||
self._value_failure = failure | |||
self._assert_values() | |||
self._inner_transformer: Union[Callable[[Result], Any], None] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- maybe use
Optional
here and intransform()
, since it is already imported? - *
Result[TS, TF]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The
Union[Callable[[Result], Any], None]
is equivalent toOptional[Callable[[Result], Any],]
. In fact, I think that newer syntax is recommendedCallable[[Result], Any] | None
. To fully adopt the newer Python syntax while maintaining backwards compatibility, I'm considering adding thefrom __future__ import annotations
statement to meigas's code. This statement enables the use of forward references in annotations, allowing you to refer to classes and types that haven't been defined yet.
meiga/result.py
Outdated
@@ -219,11 +226,11 @@ def handle( | |||
|
|||
return self | |||
|
|||
def map(self, transform: Callable) -> None: | |||
def map(self, mapper: Callable) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure one cannot use Callable
without type arguments in []
. Maybe update it to Callable[..., Any]
while we're here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why mypy
doesn't warn us about this missing typehint 🤔.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mypy has pretty tame defaults, to the point that I myself prefer to run it with --strict
option (enabling all complaints possible) and then meticulously disabling unwanted options.
Tho forcing this on an unprepared codebase will result in a ton of unexpected red squiggles. Currently counting 33 on meiga/
and 153 on tests/
directories in Meiga repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh thank you for this advice.
meiga/result.py
Outdated
@@ -255,3 +262,21 @@ def assert_failure( | |||
) | |||
|
|||
value = property(get_value) | |||
|
|||
def set_transformer(self, transformer: Callable[["Result"], Any]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- *
Result[TS, TF]
- not sure if quoting the type is required here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to work
def set_transformer(self, transformer: Callable[["Result[TS, TF]"], Any]):
tests/unit/test_result_transform.py
Outdated
|
||
|
||
@pytest.mark.unit | ||
def test_should_set_transformer_an_return_transformed_value(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* _and_
instead of _an_
? Same with the 2nd test below.
No description provided.