News for hackers. Stuff that matters.
Re:Adoption of Mypy for Python type checking: 45% already us... by philwelch on Sunday March 21, 2021 @10:50AM (#26530861)
Python 3 type annotations are part of the language spec. Whether you use mypy or a different library for type checking shouldn’t necessarily make a difference to the code.
Re:Adoption of Mypy for Python type checking: 45% already us... by ali_m on Sunday March 21, 2021 @11:23AM (#26531113)
Type annotations may be part of the language spec, but the way they are enforced is not. Different type checking libraries have made different design choices (leniency vs strictness, type inference vs gradual typing etc.). Although these differences don't matter at runtime, they do mean that code which passes one particular type checker might fail with another.
Re:Adoption of Mypy for Python type checking: 45% already us... by throwaway81523 on Sunday March 21, 2021 @03:54PM (#26533370)
There actually seems to be no story about inductive types (e.g. trees) in Python and this appears due to well known theoretical difficulties combining subtyping (required for OO) and type inference (?). I.e. it is a hard problem. There are a few long term open mypy github issues about it, and some hacky workarounds, but no real answer. This is also why languages like Haskell (with good support for inductive types) tend to not have OO. I'm not exactly familiar with the issues, but there is some PLT literature about it, by Anton Setzer and others.
Re:Adoption of Mypy for Python type checking: 45% already us... by joshuamorton on Monday March 22, 2021 @12:13PM (#26542829)
Can you elaborate on this? Forward refs and recursive types are accepted on most places that isn't NewType, so you can make them, but not in a one liner.
Re:Adoption of Mypy for Python type checking: 45% already us... by throwaway81523 on Sunday March 28, 2021 @02:04PM (#26612596)
Sorry about the slow reply but I just noticed your question. Haskell supports recursive types just fine. The issue I'm mentioning is that it is hard to express those types in MyPy, which is a static typechecking add-on for Python, not Haskell.
Re:Adoption of Mypy for Python type checking: 45% already us... by davnicwil on Sunday March 21, 2021 @12:09PM (#26531434)
Is the solution here just to skip type checking the code of dependencies, and just check the types at the interface with your own code using your tool of choice? Or is it more complex than that?
Re:Adoption of Mypy for Python type checking: 45% already us... by neilparikh on Sunday March 21, 2021 @02:47PM (#26532810)
I think that mostly works, but it's still possible that different tools assign different semantics for the same syntax, which could then interact in a weird way if the library author wrote the interface annotations with Tool A's semantics in mind, while you ended up checking them against your code with Tool B.

I think the type systems are simple enough that this is probably a theoretical concern, and won't come up often in practice.

Re:Adoption of Mypy for Python type checking: 45% already us... by jraph on Sunday March 21, 2021 @01:40PM (#26532232)
I think so. When typing checking a project, its dependencies don't get type checked as well as far as I know. Type errors in dependencies are kind of not relevant for you, and many dependencies are not type-annotated anyway.
Re:Adoption of Mypy for Python type checking: 45% already us... by ali_m on Sunday March 21, 2021 @02:29PM (#26532653)
Well you probably do still want the type checker to at least look at the public interfaces of any libraries you depend on, since you want it to enforce that you're calling into them correctly.
Re:Adoption of Mypy for Python type checking: 45% already us... by jraph on Sunday March 21, 2021 @02:38PM (#26532735)
Absolutely. It should probably not report errors that are not in your code, by default anyway, but still extract information about typing relevant to you as much as it can.