4 ms·
"Type hinting" without checking is kind of lame. If you're going to have declarations such as def zero_all_vars(vars: Iterable[LoggedVar[int]]) -> None:
by Animats 11y ago
"Type hinting" without checking is kind of lame. If you're going to have declarations such as
def zero_all_vars(vars: Iterable[LoggedVar[int]]) -> None:
people are going to get them wrong some of the time. Dumping the checking problem on some IDE, with a very vague specification of what an error is, is not progress. If functions have type specifications, you should not be able to call them with the wrong type, ever. This is the job of the compiler and the run time system, not the IDE.
Somebody should stop Python's little tin god before he creates another giant step backwards like the Python 2 to 3 mess.
- gamesbrainiac 11y agoI would have to say that I agree. A friend of mine put it this way, "If you expect me to put specify a type and not enforce it, you're just trolling".
- mixmastamyk 11y agoIt's an optional addition to a dynamic scripting language. Lightweight when you need it, more robust when you need it. Sounds like you are trolling.
- DasIch 11y agoIt's not more robust though. The type hints do absolutely nothing.
- mixmastamyk 11y agoFalse, they provide information to analysis tools, which can prevent errors.
- ubernostrum 11y agoIf there is a tool which statically analyzes your code and reports errors due to type mismatches, does it matter to you whether that tool has the exact literal name "ahead-of-time compiler"?
- lmm 11y agoWhat does matter to me is whether the standard build tool for the language will run that tool on a proposed library release before that library gets uploaded to PyPI (or equivalent). If there are type annotations in the standard package repository that are lies then that seriously limits the usefulness of the whole thing.
- orf 11y ago> If there are type annotations in the standard package repository There aren't. > whether the standard build tool for the language will run that tool on a proposed library release before that library gets uploaded to PyPI It's optional. If the library maintainer wants to do that then he can.
- lmm 11y ago> It's optional. If the library maintainer wants to do that then he can. A library with no annotations in PyPI is fine-ish. A library with correct annotations in PyPI is fine. A library with incorrect annotations in PyPI is extremely not-fine. I'm fine-ish with annotations being optional, but if they're there then their correctness needs to be enforced, otherwise they're worse than useless.
- orf 11y ago> A library with incorrect annotations in PyPI is extremely not-fine. As is a library with broken logic or one that throws exceptions randomly. You want Guido and the developers to implement some kind of system that automatically scans all PyPi packages for any kind of errors? I'm sure them solving the halting problem won't take that long. Incorrect annotations are a bug. The onus is on the maintainers of packages to fix bugs in their packages, not PyPi which is a distribution channel.
- lmm 11y ago> As is a library with broken logic or one that throws exceptions randomly. You want Guido and the developers to implement some kind of system that automatically scans all PyPi packages for any kind of errors? Yes I do, but perfect is the enemy of good; it's ok to do something that makes things better without solving the whole problem. I want the build system to encourage people to do the right thing. E.g. any serious build system already ensures that you run the unit tests as part of the build or at least release process, because it would be just dumb to publish a library release on PyPI if it failed the unit tests. > I'm sure them solving the halting problem won't take that long. We already know how to avoid the halting problem, it's called types; see e.g. Idris. But you don't need to solve the halting problem to check annotations. It's not even hard. Why would you want to not check them? I mean if you're not even going to check them then why bother having annotations in the first place? Comments would provide the same functionality and have less danger of being misleading, because everyone already knows comments often end up being out of date.
- StavrosK 11y agoSo just run the compiler and runtime type checker, what's the problem?
- pjmlp 11y agoUsually optional tooling tends to be ignored. For example, C would have been a much safer language if lint was part of the compiler, instead of being optional.
- StavrosK 11y agoSure, but how is that "another 2 to 3 mess"? If anything, the backwards-incompatible changes made the language more robust.
- pjmlp 11y agoI was replying to the issue that this being two separate tools: "This is the job of the compiler and the run time system, not the IDE." Making this optional will mean the majority won't bother to run the checker. How many do bother to run lint, jslint, core.typed or dialyzer?
- ubernostrum 11y agoWith the rise of online CI tools, I've seen it become much more common for Python-based projects to include a lint run as part of their tests and break the build on lint output.
- pjmlp 11y agoIf you are lucky to work on a shop that values CI, yeah. But those are usually the same ones that take the effort to run the tools anyway.
- anentropic 11y agothat doesn't make sense? Who would go to the effort of adding type hints and then not run the checker?
- realharo 11y agoFrom the IDE point of view, there are other benefits besides correctness. Proper autocomplete for objects (huge whenever you have a chain of method calls), ctrl+click to go to a method, showing a method's documentation in a popup, find usages - all these require the IDE to know about types if they are to work reliably.
- DasIch 11y agoNo, they aren't. In order to make use of type hints for anything, they need to be correct. If they aren't, anything else you build on top of them will be unreliable and confusing. As long as there is no way to check them, they're worthless.
- realharo 11y agoIf a library comes annotated with types, then an error in the typehints is just as much of a bug as an error in code or documentation. Having most of the standard library plus large portions of the ecosystem come with these hints will be hugely beneficial for productivity. And of course, there IS a way to check them. IDEs, linters, etc. - I'm sure if you say that your function returns an instance of User and then you try to return a boolean, they will yell at you. And I expect that the standard library and popular libraries WILL run these tools before releasing a stable version. A 90% percent solution is still a step forward compared to relying on much less reliable human brains at every step.
- DasIch 11y agoI understand that errors in type hints are bugs just like errors in code are. That's the problem. The entire point of type systems is to enforce correctness. They allow you to describe problems on the type level and ensure that the code being described matches that description, eliminating certain classes of bugs. That's why languages have them, that's the expectation. Type hints are just an overhyped standardized comment format with special syntax support.
- 11y ago
- deleted 11y ago[deleted]
- sitkack 11y ago> If functions have type specifications, you should not be able to call them with the wrong type, ever. This assumes you can represent a type specification for the function you are calling, this isn't always possible in a dynamic language with advanced metaprogramming facilities. Think of it as modularizing the compiler and runtime so that the dials on dynamism can be tuned by the team. PyCharm already used pretty sophisticated type inference this just helps it. But the real win is being able to run mypy or pytype over a codebase automatically. Types, Contracts, Properties, Tests are different directions in a tensor field. With Python you can mix and match at your will. This is in _no way_ relatable to the 2-3 mess.