▲ | agubelu 15 hours ago | ||||||||||||||||||||||||||||||||||||||||
Type hints are nice, until you have to interact with a library that isn't type-hinted, and then it very quickly becomes a mess. I don't know how other IDEs behave, but VScode + the Python extensions try to infer the missing hints and you end up with beauties such as `str | None | Any | Unknown`, which of course are completely meaningless. Even worse, the IDE marks as an error some code that is perfectly correct, because it somehow doesn't match those nonsensical hints. And so it gives you the worst of both worlds: a lot of false positives that you quickly learn to ignore, dooming the few actual type errors to irrelevance, because you'll ignore them anyways until they blow up at runtime, just as it'd happen without typehints. | |||||||||||||||||||||||||||||||||||||||||
▲ | Hackbraten 12 hours ago | parent | next [-] | ||||||||||||||||||||||||||||||||||||||||
> Type hints are nice, until you have to interact with a library that isn't type-hinted, and then it very quickly becomes a mess. Whenever I find myself in that situation, I usually write a typing stub for the parts that I use from that library (example: [0]) and then let `mypy_path` point to that directory [1]. VS Code will then pick up the hints from those stubs. [0]: https://github.com/claui/itchcraft/blob/5ca04e070f56bf794c38... [1]: https://github.com/claui/itchcraft/blob/5ca04e070f56bf794c38... | |||||||||||||||||||||||||||||||||||||||||
▲ | coldtea 10 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||
>I don't know how other IDEs behave, but VScode + the Python extensions try to infer the missing hints and you end up with beauties such as `str | None | Any | Unknown`, which of course are completely meaningless. Are they correct? If they're correct (even though they are a superset of the actual intended type) then what's the problem? At worst, it's like not having type checks for that particular package. | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
▲ | zelphirkalt 14 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||
For example in mypy the default is to not check procedures, which have no argument type annotations and no return type annotation. That gets rid of your whole problem of untyped library, if you have a wrapper procedure. If VSCode still highlights it, then it is time to configure VSCode properly. | |||||||||||||||||||||||||||||||||||||||||
▲ | thebigspacefuck 9 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||
I believe VSCode by default uses pyright which is fast but shitty in that it gives a lot of false positives. If you want the most correct typing experience, use mypy. Even then you may need a config. | |||||||||||||||||||||||||||||||||||||||||
▲ | mcdeltat 2 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||
I believe there's a mode for VS Code type checking which ignores untyped code - have you tried that? | |||||||||||||||||||||||||||||||||||||||||
▲ | Lutger 14 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||
I get what you need, yet I find these cases aren't all that often, and when it happens it doesn't bother me as I quickly recognize where the type system is somewhat failing and either ignore it or add a type hint. But maybe if you have a codebase with a lot of magic of certain libraries, you experience is different. I also don't really depend on the typing treat it the same as C# or Java. | |||||||||||||||||||||||||||||||||||||||||
▲ | robjwells 14 hours ago | parent | prev [-] | ||||||||||||||||||||||||||||||||||||||||
Worst of both worlds is right. I came back to a Python project with a couple of critical but untyped dependencies recently after writing mostly Rust, and to clear up a large number of these (particularly “type is partially unknown”) I had the choice between lots of purely type-checking ceremony (`typing.cast`) or going without. | |||||||||||||||||||||||||||||||||||||||||
|