dry-python / dry-python/classes

Typeclasses with several methods

Open
#83 2 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
Python
Stars
730
Forks
30
PR merge metrics
No merged PRs in 30d

Description

There's a common use-case when we need to create a type-class with several methods. Like:

```python
class Functor(Protocol[T]):
def map(self, function: Callable[[T], Functor[V]]) -> Functor[V]:
...

@classmethod
def from_value(cls, inner_value: V) -> Functor[V]:
...
```

Currently, there's no way we can do that.

I propose something like this:

```python
@typeclass
class Functor(Protocol[T]):
def map(self, function: Callable[[T], Functor[V]]) -> Functor[V]:
...

@classmethod
def from_value(cls, inner_value: V) -> Functor[V]:
...

```

I am not sure how to bound it to the actual implementation.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.