Ryan Morshead

Results 319 comments of Ryan Morshead

Rather, `class_init` would be renamed `__set_name__` and `subclass_init` would be renamed `__init_subclass__`. To keep with the theme, we might choose `init_instance` instead of `instance_init`. Perhaps even `__init_instance__`, but the dunder...

According to the PEP: > upon class creation, a `__set_name__` hook is called So it can't possibly be the `obj` from `__get__(self, obj, cls)`.

@NeilGirdhar, I'm not sure if this is what you had meant, but `__init_subclass__` does not do what I thought - `__set_name__` is analogous to `class_init`, but `__init_subclass__` is **not** analogous...

That'd definitely be a possibility, and the way you'd want to type this is via generics: ```python T = TypeVar("T") class TraitType(Generic[T]): def __get__(self, obj, cls) -> T: ... def...

I think this'd be a pretty useful feature for Traitlets since it's non-intrusive, but will have a broad positive impact on everyone downstream that shouldn't require significant code changes that...

It definitely gets a little tricky, but I think you could solve that with `typing.overload`: ```python T = TypeVar("T") class TraitType(Generic[T]): @overload def __new__(cls, allow_none: Literal[True]) -> TraitType[Optional[T]]: ... @overload...

@djarecka I think that https://github.com/ipython/traitlets/pull/403 might fix this problem for you. If so, I can invest the time to try and get that into the 5.0 release. Otherwise it may...

@djarecka, I have confirmed that the issue is (in my branch) just bad argument handling. For example this works: ```python class X(HasTraits): l = List([1, 2, 3]) x = X()...

`master` probably fails for the same reason, though I have not checked that myself.

Seems like a fine idea to me. If someone's interested in implementing it I'm happy to help advise.