4 ms·
This does restrict all of your keyword arguments to the same type. If you have keyword arguments of different types, you're right back to no type safety.
by assbuttbuttass 3y ago
This does restrict all of your keyword arguments to the same type. If you have keyword arguments of different types, you're right back to no type safety.
- masklinn 3y agoThat seems obvious? If you want a variable number of arguments of arbitrary type you have to specify the common supertype, commonly top itself. To do otherwise would require some form of vararg generics which is uncommon.
- IshKebab 3y agoIt's extremely common for Python programmers to write code with kwargs of different types. Look at subprocess.run() for example.
- actualwitch 3y agoWell, if you want to type your kwargs and use newer versions of python, you can use Unpack with typed dicts to achieve that. But the footgun there is that you can't redefine fields when extending them, so no Partial<SomeType> for you.
- zbentley 3y agoTrue, but there are a couple of mitigations available: you can express the types of selected kwargs (by leaving them out of the * residual), and you can use typing.Union/| to express product types for values in the residual as well.