Skip to content

Implement Maybe monad and custom mypy plugin #25

Closed
@sobolevn

Description

@sobolevn

Currently it is impossible to use this monad due to this bug in typing:

x: Optional[int]
Monad.new(x)  # ?

Type will be: Some[Union[int, None]]
, not Union[Some[int], Nothing]
Related:

_ContainerType = TypeVar('_ContainerType', bound=Container)
_ValueType = TypeVar('_ValueType')
_NewValueType = TypeVar('_NewValueType')
class Maybe(GenericContainerOneSlot[_ValueType], metaclass=ABCMeta):
@overload
@classmethod
def new(cls, inner_value: Literal[None]) -> 'Nothing': # type: ignore
...
@overload # noqa: F811
@classmethod
def new(cls, inner_value: _ValueType) -> 'Some[_ValueType]':
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions