Closed dgellow closed 2 years ago
Related issue thread in mypy: https://github.com/python/mypy/issues/4441
This feature (using a TypedDict
to specify the value of **kwargs
) is experimental and hasn't yet been ratified. It's supported only as a proof of concept to inform an eventual PEP. Until it becomes standard, I don't think it's likely to get much adoption, and it's probably not worth investing the time in adding completion suggestion support. But it may eventually make sense to do so if we get sufficient signal from users.
Since this is not a core type checking issue, I'm going to transfer this request to the pylance-release repo for consideration and tracking.
Sounds good, thanks for the quick response. Would you accept a pull request, or do you consider the feature too experimental and would prefer to first wait for the feature to become standard? (or at least for a PEP to be accepted)
We would prefer to wait for it to become standard. If that happens, please reopen if you would still like it. Thank you.
In my opinion, this is a must have feature for the future of python. Typescript had this for 10 years and it's an essential feature of the language. I'm happy to see python making progress in supporting better typing.
The good news is that this proposal is one step closer to becoming standardized in Python. It is now a draft PEP, and if it's accepted, it will become part of Python 3.12.
@bschnurr it looks like this PEP has now been accepted and is on track to be a standard in Python 3.12. See https://peps.python.org/pep-0692/
Would you be willing to open this issue again?
We actually implemented this. It should be working in our latest prerelease.
@rchiodo Oh sweet! I had just tried this on VSCode but I'm not on any preview versions. Thanks for the quick response.
Environment: Pylance version v2022.3.4, from vscode.
I'm not sure if it is a bug or would be considered a new feature. I understood from https://github.com/microsoft/pyright/issues/3002 that typed
**kwargs
are now supported by pylance/pyright. Thank you for this!Now when I try the example mentioned at https://github.com/microsoft/pyright/issues/3002#issuecomment-1046100462 I see that while type checking seem to work correctly, the autocompletion doesn't seem to work as I would expect.
Let's say I have this code in vscode, with Pylance enabled:
I would expect that when I trigger the autocompletion via
ctrl+space
I would get suggestedfoo=
andbar=
, but instead the only relevant suggestion iskwargs=
.When I trigger the autocompletion for
MyKwargs()
arguments I get something correct, the issue seem to only be when usingUnpack[T]
:It would be nice to have the list of keys of the unpacked typed dict :)