Comments (9)
We would probably would need to improve https://classes.readthedocs.io/en/latest/pages/dry-python.html page as well.
from classes.
Could you say more about what those tests should be, please?
from classes.
We need to test:
Result.success_type
andfailure_type
Maybe
withempty
IOResult
So, imagine that you want to dispatch some action based on the result/mayb type using classes
. That's we basically need to cover for different types.
from classes.
I got some errors with Result
using the example from the docs:
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:
ex.py:10: error: Instance "returns.result.Result[Any, Any]" does not match inferred type "Type[returns.result._Success[Any]]"
ex.py:16: error: Instance "returns.result.Result[Any, Any]" does not match inferred type "Type[returns.result._Failure[Any]]"
ex.py:23: error: Argument 1 to "result_to_str" has incompatible type "Result[str, Any]"; expected <nothing>
ex.py:24: error: Argument 1 to "result_to_str" has incompatible type "Result[Any, str]"; expected <nothing>
Found 4 errors in 1 file (checked 1 source file)
PS.: I'm using the returns
plugin too
from classes.
The same thing for Maybe
😢
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:
ex.py:10: error: Instance "returns.maybe.Maybe[Any]" does not match inferred type "Type[returns.maybe._Some[Any]]"
ex.py:15: error: Instance "returns.maybe.Maybe[Any]" does not match inferred type "Type[returns.maybe._Nothing]"
ex.py:21: error: Argument 1 to "maybe_to_str" has incompatible type "Maybe[str]"; expected <nothing>
ex.py:22: error: Argument 1 to "maybe_to_str" has incompatible type "Maybe[NoReturn]"; expected <nothing>
Found 4 errors in 1 file (checked 1 source file)
from classes.
@thepabloaguilar Will you have the time to debug why this happens?
from classes.
I can try, it's a problem with classes
mypy plugin
from classes.
How do you develop mypy
plugin locally? I want to put some breakpoints 😄
from classes.
Try --pdb
option for mypy
. I don't use debuggers, sorry.
from classes.
Related Issues (20)
- Add link to `__instancecheck__` docs
- `TypedDict` support for `delegate` types HOT 1
- Should we support `Union` runtime types?
- Reconsider "get type from function annotation"
- Require strict `delegate=` subtyping
- Internal error HOT 3
- Support `pass` for typeclass bodies
- `Supports` should support `__instancecheck__` HOT 1
- classes vs multipledispatch HOT 2
- Support `Any` as an alias for `object` to describe a default typeclass implementation
- Prevent an implementation for `int` class from operating on `bool` values HOT 1
- `recommonmark` is deprecated HOT 2
- Provides delegate classes for common cases HOT 1
- Your readme looks a little funky in dark theme HOT 1
- delegate fails for `Literal` type HOT 2
- Crash: lookup of unknown name HOT 1
- Update `typing_extensions` definition HOT 1
- Bug with mypy plugin HOT 2
- Unable to install both returns and classes together
- Error importing plugin "classes.contrib.mypy.classes_plugin" cannot import name 'union_items' from 'mypy.types' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from classes.