vickumar1981 / pyeffects

Handle side-effects in Python like a boss. Implements functional types for Either, Option, Try, and Future.
Other
31 stars 6 forks source link

add equality for all classes except Future #32

Closed BattiniSandeep closed 11 months ago

BattiniSandeep commented 1 year ago

Hii @vickumar1981 I have added equality for all classes except Future. I have added related test cases too. Let me know if you need any other changes.

Sandeep Kumar

vickumar1981 commented 1 year ago

The build is failing with the errors below (run pipenv run mypy pyeffects/*.py to check the type hints)

pyeffects/Try.py:187: error: "object" has no attribute "value"  [attr-defined]
pyeffects/Try.py:208: error: "object" has no attribute "value"  [attr-defined]
pyeffects/Option.py:91: error: "object" has no attribute "value"  [attr-defined]
pyeffects/Option.py:1[12](https://github.com/vickumar1981/pyeffects/actions/runs/6396612398/job/17362773336?pr=32#step:6:13): error: "object" has no attribute "value"  [attr-defined]
pyeffects/Either.py:93: error: "object" has no attribute "value"  [attr-defined]
pyeffects/Either.py:1[17](https://github.com/vickumar1981/pyeffects/actions/runs/6396612398/job/17362773336?pr=32#step:6:18): error: "object" has no attribute "value"  [attr-defined]

This is b/c in all the functions we said that the type annotation of the input parameter was object instead of what class it really is, i.e. (Future[A], or Either[A], or Option[A]).

If we change that to the appropriate class, mypy won't complain anymore. object doesn't have an attribute called value, but our classes do.

vickumar1981 commented 1 year ago

@BattiniSandeep left some comments. thanks again for working on this! much appreciated.

BattiniSandeep commented 1 year ago

Hii @vickumar1981 I have made changes acoording to our convo, But still getting error. Not sure where I'm wrong.

vickumar1981 commented 1 year ago

@BattiniSandeep yeah, i guess changing away from object violates the liskov subtitution of the __eq__ method. I think you can just add a type: ignore at the end of the function signature to surpress the mypy warnings.

I.e. (for try, would also have to add it to either and option):

def __eq__(self, other: 'Try[A]') -> bool:  # type: ignore

thanks!

vickumar1981 commented 1 year ago

@BattiniSandeep will take a look at this in a couple of days. sorry for the delay.

vickumar1981 commented 11 months ago

@BattiniSandeep Pulled in all your commits in this PR and made some updates: https://github.com/vickumar1981/pyeffects/pull/34

vickumar1981 commented 11 months ago

Closing.