-
Notifications
You must be signed in to change notification settings - Fork 550
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 'intellisense' autosuggestion of functions #372
Comments
This comment has been minimized.
This comment has been minimized.
Ok, I think I've figured out the problem.
The quickstart examples are thus using a shortcut that harms type hinting. Does |
You're right on point! When I developed the first version of TinyDB back in 2013 (it's been a while!), static typing and intellisense wasn't really on my mind. The very first design didn't have tables, all methods like Thinking about this decision again, I see it as a trade-off between convenience and consistency: using I'll keep thinking about how we can find a better way for this. |
Oh that makes sense, I wasn't aware the module was so old. Your explanation makes sense. Having glanced through the code of The purpose of Lines 246 to 253 in d142849
What would be the harm of treating
I'll try this out locally and see whether it works. Maybe there will be a surprise! Is there a name for the |
Well, the very simple answer is that doing so breaks some tests 🙃
To be honest, when I came up with the idea I didn't think very much about the theory behind it. In retrospect I guess it's the delegation pattern or delegation concept. Unfortunately delegation seems to be unspported by PEP 484 which defines the standard type hints. |
Right! Great, I think I've managed to rewrite it without breaking existing tests at all. Will submit PR in a minute. |
Hey @corneliusroemer. First, sorry for the long delay. I wanted to merge your PR in #374 for a while now but somehow I always felt hesitant when thinking about it. The main reason is that I felt like making Now I found a new approach that looks promising. The main goal after all is to get Visual Studio Code, MyPy and others to properly support TinyDB's API. And I found that we can achieve this by using Basically, my approach would be something like this: def with_typehint(baseclass: Type[T]) -> Type[T]:
if TYPE_CHECKING:
return baseclass
return object
TableBase = with_typehint(Table)
class TinyDB(TableBase):
... This would make Pylance correctly detect that What do you think about this? |
Looks good! Should fix type hinting without disrupting anything else |
Great! I've pushed a commit that should add better type completion for PyCharm, VS Code and MyPy. Could you check whether you get better IntelliSense suggestions when using the development version of TinyDB ( |
The fix has been released in TinyDB 4.5.0 which I've just published 🙂 |
I'm not sure if I've done something wrong installing TinyDB, but I'm not getting any intellisense/autocomplete, as I'm used to from most packages.
There also seem to be no type hints, maybe that's why? Is this something you'd want help with?
I'm using Pylance as my Language server in VS Code.
Here are screenshots from me using TinyDB in VSCode, note, return type is always none, so
Pylance
can't figure out what's going on.The text was updated successfully, but these errors were encountered: