3 ms·
"Mypy allows you to add type annotations and enforce them prior to running your program" Yes, and if I wanted type annotations to stop my program from working
by raverbashing 10y ago
"Mypy allows you to add type annotations and enforce them prior to running your program"
Yes, and if I wanted type annotations to stop my program from working I wouldn't be using Python
Enforcing types is exactly what Python IS NOT about. Because of Duck Typing and everything else
So this is not "postmodern error handling" this is "let's code Java in something else and pat ourselves in the back"
Do you want to check errors in "compile time"? Use Pylint. It does the right thing
- rspeer 10y agoDuck typing is not the solution to every problem. Pylint has nothing to do with catching type errors. It catches problems with code style. I don't find the code in this blog post convincing, but there are reasons to write type-safe code.
- raverbashing 10y ago> Pylint has nothing to do with catching type errors. No, it does catch type errors, for example accessing methods that are not present in the object > but there are reasons to write type-safe code. Yes, and there are lots of languages that allow you that
- uweschmitt 10y agoI'm not a big fan of type annotations because the code easily turns unreadable which is not what I expect from Python code. But for larger projects type checking is valuable. Types introduce additional contracts between components to manage and control the overall complexity of the system. For small scripts and self contained applications I regard type checking as a burden. For larger projects not. Pylint is a valuable tool to detect typical errors but does not check types. Regard a function which returns the sum of two given arguments. It will work with both arguments being integers and for both being strings. PyLint will not complain here, but if your code uses this result you might trigger errors much later during progam execution which are hard to detect or understand without type checking.
- njharman 10y ago> But for larger projects type checking is valuable. Wrong solution to the wrong problem. Break that too large for duck typing fucking mess into smaller independent components with well defined and enforced interfaces.
- adwn 10y ago> components with well defined and enforced interfaces "Well defined and enforced interfaces"? That sounds like a job for static typing! But seriously, that's exactly what types are good for: defining and enforcing an interface.
- fpoling 10y agoDuck typing is still a type system that can be checked before running the code. Flow for JavaScrip does that while allowing to use comments for type annotations. That is with Flow one has an option to program in idiomatic JavaScript that relies on Duck types and then check for type violations using the tool. The cool part of Flow is that it tries hard to check for various typical patterns making annotations minimal.