haxsaw/hikaru

Hikaru functions should return a specific type

Closed this issue · 3 comments

Hi Tom, my name is Tal and I work with @aantn in Robusta, where we use Hikaru as our kubernetes library.

It would be super nice if the functions exported by Hikaru will return a specific type rather than the general "Response" type.

For example, rather than writing:

from hikaru.model.rel_1_16.v1 import EventList
event_list: EventList = EventList.listNamespacedEvent("default").obj

It would be nice if one could simply write:

from hikaru.model.rel_1_16.v1 import EventList
event_list = EventList.listNamespacedEvent("default").obj

And still get the right type (EventList in this case), rather than the Optional[Any] type of Response.obj

(One possible implementation: rather than one Response type, Hikaru can maintain multiple Response[TYPE] types - for example Response[EventList], Response[Pod] etc. - and return the correct one from every function it exports)

Thanks :)

This is an interesting idea and as soon as I can figure out how to address the problem I have at hand I'll give this some investigation.

So I've changed the Response object to be a generic type; it is now Response[T], and the T type is used to create a type annotation on the obj attribute as you suggested. I'm working on creating a new release now that will include this, but be warned that due to a some changes in the underlying swagger, a pair of methods on the EventList object can raise an exception. That bug is covered here: kubernetes-client/python#1616. I'm hoping to have the new release out soon; it's been a bit of a beast.

aantn commented

As always, thank you!