-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Use returns
in testing
#235
Comments
We would probably would need to improve https://classes.readthedocs.io/en/latest/pages/dry-python.html page as well. |
Could you say more about what those tests should be, please? |
We need to test:
So, imagine that you want to dispatch some action based on the result/mayb type using |
I got some errors with from classes import typeclass
from returns.result import Result, Success, Failure
@typeclass
def result_to_str(instance) -> str:
"""This is a typeclass definition to convert Result container to str."""
@result_to_str.instance(Result.success_type)
def _result_to_str_success(instance: Result) -> str:
return str(instance.unwrap()) # will always receive `Success` types
@result_to_str.instance(Result.failure_type)
def _result_to_str_failure(instance: Result) -> str:
return str(instance.failure()) # will always receive `Failure` types
if __name__ == '__main__':
result_to_str(Success('test'))
result_to_str(Failure('test')) mypy output:
PS.: I'm using the |
The same thing for from classes import typeclass
from returns.maybe import Maybe, Some, Nothing
@typeclass
def maybe_to_str(instance) -> str:
"""This is a typeclass definition to convert Maybe container to str."""
@maybe_to_str.instance(Maybe.success_type)
def _maybe_to_str(instance: Maybe) -> str:
return str(instance.unwrap()) # will always receive `Maybe` types
@maybe_to_str.instance(Maybe.failure_type)
def _nothing_to_str(instance: Maybe) -> str:
return str(instance) # will always receive `Nothing`
if __name__ == '__main__':
maybe_to_str(Some('test'))
maybe_to_str(Nothing) mypy output:
|
@thepabloaguilar Will you have the time to debug why this happens? |
I can try, it's a problem with |
How do you develop |
Try |
We need to be sure that
classes
andreturns
can be used together and that typing works.Plan:
returns
asdev-dependency
typesafety/test_integration/test_returns
folder where we would test itpytest-mypy-plugins
we would need to addreturns_plugin
tomypy
settingsThe text was updated successfully, but these errors were encountered: