-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No keys hints for TypedDict when it is in union #2860
Comments
I think you need to check that the type is if isinstance(x, MyDict):
x['a'] = 'hi'
else:
x = 1 |
I don't think one should check with isinstance to get autocomplete hints, finally, it's just a nice feature, the inference of types works correctly (I said so in the issue, that |
So it is currently not supported but maybe it will be fixed later? |
It's a trivial fix. Working on it now. |
Thanks! In fact, what I want to achieve with this is to say that some class has these and these keys. Are there any other ways to tell this to pylance? As I understand, now only TypedDict has supported hints. There are 2 "pythonic" solutions, both are prohibited by TypedDict pep though :)
So what I am doing is a hack, I say "this is both class and it has these keys" by passing the union of my class and created TypedDict. Motivation / common use-case: pandas.DataFrame / numpy.ndarray (with fields) with known in advance columns / dtype. I might create a separate issue for this, though not sure, if it's pylance or current Python typing state. (I think the latter) |
This would be a topic better discussed in the python/typing discussions forum. |
Ok, thanks! |
We'll leave this open until next week's release. |
BTW, is the problem below also fixed by your change or should I open another issue? Normal classes have hints in notebooks, but TypedDicts don't. foo.py
in notebook:
|
That should have worked prior to my change because Here are the completions I receive with the latest code (which includes my recent change). I think this is what one would expect. Edit: It looks like there's another issue that may be specific to Jupyter notebooks. There's already another bug tracking that issue. |
Yes, it works perfectly in normal py files, however for notebooks:
We can wait for that issue to be resolved first and if it still does not work, I ll open a new issue. |
This issue has been fixed in version 2022.6.0, which we've just released. You can find the changelog here: CHANGELOG.md |
Environment data
Code Snippet
Expected behavior
Show keys hints, 'a' in this case
Actual behavior
Does not show key hints.
The text was updated successfully, but these errors were encountered: