Skip to content
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

Allowing Generic Atom #156

Open
MatthieuDartiailh opened this issue Feb 14, 2022 · 1 comment
Open

Allowing Generic Atom #156

MatthieuDartiailh opened this issue Feb 14, 2022 · 1 comment

Comments

@MatthieuDartiailh
Copy link
Member

MatthieuDartiailh commented Feb 14, 2022

With the improved support for typing in atom, I am wondering if it would make to have some special support for the following:

Currently this will work and will statically type check:

from typing import Generic, TypeVar
from atom.api import Atom, List

T = TypeVar("T", bound=object)


class A(Atom, Generic[T]):

    # Mypy dislike the use of T outside an annotation 
    # but with #133 we could just use an annotation
    l: List[T] = List(T)  # type: ignore


class B(A[int]):
    pass


b = B()
b.l.append("")  # mypy complain atom is happy though

The fact that atom does not complain at runtime is something I find sad (I work currently in a context where I appreciate the strictest possible typing). I believe we could alter AtomMeta to make it so that the member becomes specialized to also do validation at runtime. Would that be of interest to you @clamdad @frmdstryr ?

One thing I am undecided upon yet if we go this is if A[int] should create a subclass or should only its use in B creation trigger specialization.

@frmdstryr
Copy link
Contributor

I'd prefer if A[int] made it's own singleton type otherwise I don't think isinstance would work?

B = A[int]
C = A[int]
assert B is C 

class D(A[int]):
  pass
assert isinstance(D, B)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants