jspahrsummers / adt

Algebraic data types for Python (experimental, not actively maintained)
MIT License
172 stars 14 forks source link

PyCharm can't recognizes that `Case` is callable and etc. #36

Open rscarrera27 opened 4 years ago

rscarrera27 commented 4 years ago

My Code:

@adt
class Result(Generic[S, E]):
    Success: Case[S]
    Error: Case[E]

    async def map(self, func: Callable[[S], Awaitable[Union[S, E]]]) -> "Result[S, E]":
        return self.match(success=lambda s: self.Success(func(s)), error=lambda e: e)

    async def flat_map(self, func: Callable[[S], Awaitable["Result[S, E]"]]) -> "Result[S, E]":
        return self.match(success=lambda s: (await func(s)), error=lambda e: e)

Pycharm said "Case object is not callable" for this line.

self.Success(func(s))

also intellisense doesn't work for completing self.match

I understand that this is architectural issue. to make pycharm intellisense work, I think we have to use base class, not use decorator.

this is just a suggestion. your lib works perfectly on runtime :)

LewisGaul commented 3 years ago

As someone who uses PyCharm and was looking into options for ADTs in Python - I'm not surprised it causes issues with PyCharm's intellisense, and I doubt there will be anything that can really be done about it. I'd love to be proven wrong, but in general it's not possible for metaprogramming to be followed without actually running the code, which IDEs can't be expected to do!