8000 Concrete generics support · Issue #24 · dry-python/classes · GitHub
[go: up one dir, main page]

Skip to content

Concrete generics support #24

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

Closed
sobolevn opened this issue Jan 17, 2020 · 2 comments · Fixed by #256
Closed

Concrete generics support #24

sobolevn opened this issue Jan 17, 2020 · 2 comments · Fixed by #256
Labels
enhancement New feature or request

Comments

@sobolevn
Copy link
Member
sobolevn commented Jan 17, 2020

Right now it is impossible to write a code like this one:

from classes import typeclass
from typing import List

@typeclass
def some(instance) -> int:
    ...

@some.instance(List[int])
def _some_list_int(instance: List[int]) -> int:
    ...

Because, you cannot check that some variable has type List[int] in runtime.

Maybe we can use runtime typecheckers? Like: https://github.com/erezsh/runtype

Related #8

@sobolevn sobolevn added the enhancement New feature or request label Jan 17, 2020
@sobolevn
Copy link
Member Author

@sobolevn sobolevn changed the title Look at runtype Concrete generics support Jun 24, 2021
@sobolevn
Copy link
Member Author
sobolevn commented Jul 6, 2021

My current design:

from typing import List, TYPE_CHECKING

if not TYPE_CHECKING:
    reveal_type = prin
870F
t

from phantom import Phantom
from phantom.predicates import collection, generic

class ListOfInt(
    List[int],
    Phantom,
    predicate=collection.every(generic.of_type(int)),
):
    ...



from classes import typeclass

@typeclass
def sum_all(instance) -> int:
    ...

@sum_all.instance(List[int], delegate=ListOfInt)
def _sum_list_of_int(instance: List[int]) -> int:
    return sum(x for x in instance)

l = [1, 2, 3]
reveal_type(sum_all(l))

It both typechecks (I need to fix my plugin, though) and works in runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

1 participant
0