GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use `returns` in testing · Issue #235 · dry-python/classes

Use returns in testing #235

New issue
Copy link
New issue
Copy link
Open
Open
Use returns in testing#235
Copy link
Assignees
thepabloaguilar
Labels
enhancementNew feature or requestNew feature or request

Description

@sobolevn
sobolevn
opened on Jun 20, 2021
Issue body actions

We need to be sure that classes and returns can be used together and that typing works.

Plan:

  1. Install returns as dev-dependency
  2. Create special typesafety/test_integration/test_returns folder where we would test it
  3. In pytest-mypy-plugins we would need to add returns_plugin to mypy settings

Activity

  1. sobolevn
    added
    enhancementNew feature or requestNew feature or request
    on Jun 20, 2021
  2. sobolevn commented on Jun 20, 2021

    @sobolevn
    sobolevn
    on Jun 20, 2021
    MemberAuthor
    More actions

    We would probably would need to improve https://classes.readthedocs.io/en/latest/pages/dry-python.html page as well.

  3. thepabloaguilar
    self-assigned this
    on Oct 2, 2021
  4. thepabloaguilar commented on Oct 2, 2021

    @thepabloaguilar
    thepabloaguilar
    on Oct 2, 2021
    Member
    More actions

    Could you say more about what those tests should be, please?

  5. sobolevn commented on Oct 2, 2021

    @sobolevn
    sobolevn
    on Oct 2, 2021
    MemberAuthor
    More actions

    We need to test:

    1. Result.success_type and failure_type
    2. Maybe with empty
    3. 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.

  6. thepabloaguilar commented on Oct 3, 2021

    @thepabloaguilar
    thepabloaguilar
    on Oct 3, 2021
    Member
    More actions

    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

  7. thepabloaguilar commented on Oct 3, 2021

    @thepabloaguilar
    thepabloaguilar
    on Oct 3, 2021
    Member
    More actions

    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)
    
  8. sobolevn commented on Oct 3, 2021

    @sobolevn
    sobolevn
    on Oct 3, 2021
    MemberAuthor
    More actions

    @thepabloaguilar Will you have the time to debug why this happens?

  9. thepabloaguilar commented on Oct 3, 2021

    @thepabloaguilar
    thepabloaguilar
    on Oct 3, 2021
    Member
    More actions

    I can try, it's a problem with classes mypy plugin

  10. thepabloaguilar commented on Oct 4, 2021

    @thepabloaguilar
    thepabloaguilar
    on Oct 4, 2021
    Member
    More actions

    How do you develop mypy plugin locally? I want to put some breakpoints 😄

  11. sobolevn commented on Oct 4, 2021

    @sobolevn
    sobolevn
    on Oct 4, 2021
    MemberAuthor
    More actions

    Try --pdb option for mypy. I don't use debuggers, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @thepabloaguilar
    thepabloaguilar

Labels

enhancementNew feature or requestNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.