python: typing *args / **kwargs (intermediate) anthony explains #145

preview_player
Показать описание
today I talk about typing the two types of starargs and why it's tricky / impossible to get correct

==========

I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!
Рекомендации по теме
Комментарии
Автор

Thanks for this Anthony!! This gave some insight for type hinting *args and **kwargs!

akshaymestry
Автор

This means less libraries exposing `some_func(*args:Any, **kwargs: Any) -> Any` which wraps a function which wraps a function where arguments are finally defined? Amazing!


Last time I ended up redefining the API subset I was using:

def typed_wrapper(
arg1: str,
arg2: int,
arg3: Tuple[str, str]
) -> int:
kwargs = rebuild_kwargs(locals())
return untyped_function(**kwargs)

erwan
Автор

I'm still struggling to understand the syntax exactly, say I have a class from a module:

class MyClass(module.Class):
def __init__(self, *args: Any, **kwargs: Any):
super.__init__(*args, **kwargs)

How would I annotate that to avoid Any?

esparafucio