nucleic / enaml

Declarative User Interfaces for Python
http://enaml.readthedocs.io/en/latest/
Other
1.53k stars 130 forks source link

Support atom members in attr types #408

Closed frmdstryr closed 4 years ago

frmdstryr commented 4 years ago

It'd be nice to be able to have more explicit control of the type of an attr using an atom member.

Ex

from atom.api import List

enamdef SomeWidget(Widget):
     attr items: List(int) = [1, 2, 3]

I assume it doesn't do this because parsing it becomes a mess?

MatthieuDartiailh commented 4 years ago

This would require special casing Atom members since currently a simple type check is performed.

sccolbert commented 4 years ago

It just needs to be a type. You can define your own type subclass with a magic method that hooks the type-checking validation (I forget the magic method name off the top of my head).

On Wed, Apr 8, 2020 at 9:29 AM Matthieu Dartiailh notifications@github.com wrote:

This would require special casing Atom members since currently a simple type check is performed.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nucleic/enaml/issues/408#issuecomment-610989119, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABBQSLAXXG5Y7O4NMPMQVDRLSCCZANCNFSM4MD63K4A .

frmdstryr commented 4 years ago

__instancecheck__ works but it seems like a hack compared to passing in a member.