Skip to content
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

Match expected type when using Success and Failure aliases #35

Closed
3 tasks done
acostapazo opened this issue Oct 8, 2022 · 0 comments · Fixed by #36
Closed
3 tasks done

Match expected type when using Success and Failure aliases #35

acostapazo opened this issue Oct 8, 2022 · 0 comments · Fixed by #36
Assignees
Labels
enhancement New feature or request

Comments

@acostapazo
Copy link
Contributor

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I already read and followed all the documentation and didn't find an answer.

Description

When use alias Success and Failure and the return typing is a Result. the IDE warns us, as in the following example:

Screenshot 2022-10-08 at 15 58 29

Screenshot 2022-10-08 at 15 58 40

This is the current implementation:

from typing import Any, Generic, cast

from meiga.error import Error
from meiga.result import TF, TS, Result


class Success(Result, Generic[TS]):
    def __init__(self, value: TS = cast(TS, True)) -> None:
        Result.__init__(self, success=value)


class Failure(Result, Generic[TF]):
    def __init__(self, error: TF = cast(TF, Error())) -> None:
        Result.__init__(self, failure=error)

Wanted Solution

We want to match typed return with returned one.

Could we use a function to resolve this

Wanted Code

def Success(value: TS = cast(TS, True)) -> Result:
    return Result(success=value)


def Failure(error: TF = cast(TF, Error())) -> Result:
    return Result(failure=error)

Alternatives

No response

Operating System

macOS

Operating System Details

No response

meiga Version

1.6.1

Python Version

3.10.6

Additional Context

No response

@acostapazo acostapazo added the enhancement New feature or request label Oct 8, 2022
@acostapazo acostapazo self-assigned this Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant