flake8-pyi icon indicating copy to clipboard operation
flake8-pyi copied to clipboard

Encourage typing_extensions.Unpack for many overload-invariant keywords

Open twoertwein opened this issue 2 years ago • 3 comments

If a function has many keyword arguments that do not change across all overloads (for example pandas.read_csv). It is more readable and shorter to move all the overload-invariant keywords into a TypedDict and suggest using the Unpack feature which is supported by at least pyright and mypy.

This would probably need some heuristic of when is it worth recommending Unpack: Using a TypedDict for less than insert magic number keywords is probably not helpful.

twoertwein avatar Sep 28 '22 19:09 twoertwein

We shouldn't do this in typeshed until PEP 692 is accepted. I think it's better to also wait in flake8-pyi.

JelleZijlstra avatar Sep 28 '22 21:09 JelleZijlstra

We shouldn't do this in typeshed until PEP 692 is accepted. I think it's better to also wait in flake8-pyi.

Yeah, I agree. Hopefully the PEP will be accepted, but until then this is essentially an unofficial/unsanctioned use of this symbol, so I'm not sure we should write a lint enforcing its use just yet. I'll mark this as "deferred" for now :)

AlexWaygood avatar Sep 28 '22 21:09 AlexWaygood

The PEP's been accepted now, but mypy's support is still guarded behind --enable-incomplete-feature=Unpack (our typeshed trackig issue is https://github.com/python/typeshed/issues/9710). We probably shouldn't write a lint encouraging it until it's properly supported by all major type checkers.

AlexWaygood avatar May 01 '23 22:05 AlexWaygood