4 ms·
Are there any code editors/editor plugins that make effective use of python type hints? The python plugins for visual studio code didn't make much use of the ty
by MichaelMoser123 5y ago
Are there any code editors/editor plugins that make effective use of python type hints? The python plugins for visual studio code didn't make much use of the type hints, last time that I checked. i was hoping that type hints would be used for code completion, but that doesn't seem to be the case.
- aldanor 5y agoPyCharm has its own engine and while not perfect, it's fairly good.
- quietbritishjim 5y agoAnd when it fails to infer the type of something you can add `assert isinstance(foo, T)`, and PyCharm will make use of that.
- ramraj07 5y agoThis will throw an error in runtime for bad types, which might or might not be your intention (unless of course you build the package, which only makes it all the more harder to debug if this is where your program fails at this step). So, just don’t use assert outside of tests?
- quietbritishjim 5y agoFor sure, adding that line of code will affect the runtime as well as type hinting in the IDE. Certainly don't use it unless you're sure that the asserted condition is actually always true (or not sure and want to know if it isn't!).
- willvarfar 5y agoI’m not a huge fan of pycharm’s inference and autocomplete. It’s not that it’s bad, I was really just that I was hoping for more. There is so much that could be done eg IDEs could enable proper exhaustive signature checks when running code in debuggers. Pypy could probably do some really good cheap checks in debug mode too. And if not checking while debugging, they could at least highlight failed hints in the call stack when the debugger stops. A long long time ago before MyPy I made a runtime checker called Obiwan. I always preferred its syntax to MyPy, eg [int] instead of list[int]. I then got into playing with SSA within functions and that really helped type checking. So there’s loads more I think could be done to do what typescript did for JavaScript but to python.
- MichaelMoser123 5y agoare you using the free community edition of pycharm, or do you need the paid one for that?
- aldanor 5y agoI'm using CE, don't think you need the paid one for that
- qsort 5y ago> The python plugins for visual studio code didn't make much use of the type hints, last time that I checked. When was that? The Python Vscode extension with Pylance is pretty much perfect, Intellisense works as well as it does in, say, Java.
- MichaelMoser123 5y agoabout two or three months ago, I added type annotations to one of my libraries, but the intellisense didn't make any use of that.
- maleldil 5y agoVS Code with Pylance (which uses the Pyright type-checker) is really good. It even works well with Numpy and Pandas, which AFAIK mypy doesn't.