These are chat archives for evhub/coconut

8th
Mar 2018
Jeffrey Benjamin Brown
@JeffreyBenjaminBrown
Mar 08 2018 04:05

I had previously thought mypy was the only static typechecking tool for Python. The Coconut tutorial made me aware that there are many others, including some that are built into Python. Now I'm worried that they might conflict. Do I need anything but mypy?

I posted a question to this effect on Stackoverflow.

Elliott Indiran
@eindiran
Mar 08 2018 19:04
mypy does most of its work by leveraging the type hints/annotations built in to Python 3.5+ and the variable annotations in Python 3.6 . You can definitely just use mypy; I have never used pytype.
Evan Hubinger
@evhub
Mar 08 2018 22:52
@Darkle Incompatible types in assignment (expression has type overloaded function, variable has type overloaded function) is a known issue (#405) which should be fixed on coconut-develop. Just pip install -U coconut-develop to get the fix.
@JeffreyBenjaminBrown MyPy is the most popular static type checker, but you're right that there are others. Fortunately, as @eindiran noted, they all use the same syntax, so you don't need to worry about incompatibilities. Just use MyPy and you'll be fine.
Jeffrey Benjamin Brown
@JeffreyBenjaminBrown
Mar 08 2018 22:55
So none of them can do anything that MyPy can't?
(where by "do" I mean "express" -- I'm not worried about performance differences in compilation time)
Elliott Indiran
@eindiran
Mar 08 2018 22:58
is there something specific you're hoping to get out of a type checker that you're worried mypy won't support?
basically, the only difference you are likely to see is in handling of edge cases
Jeffrey Benjamin Brown
@JeffreyBenjaminBrown
Mar 08 2018 23:00
I'm unaware of any particular thing that I'll want to express that isn't expressible in MyPy.
Could you describe what you mean by edge case?
Elliott Indiran
@eindiran
Mar 08 2018 23:01
there are cases where mypy will complain about something that pytype, pycharm, etc. won't as well as cases where the opposite is true
this explains it fairly well with some examples
Jeffrey Benjamin Brown
@JeffreyBenjaminBrown
Mar 08 2018 23:04

Woah, that's super interesting. Thanks!

I suppose ideally I would want to be able to express refinement types :D

Elliott Indiran
@eindiran
Mar 08 2018 23:10
you can sort of fake some simple refinement types using the typing module to define new types with arbitrary constraints, but as far as I am aware there is no first class support for it
Jeffrey Benjamin Brown
@JeffreyBenjaminBrown
Mar 08 2018 23:11
could I specify the dimensions or column names of a table? or that an array is sorted on some condition?
Elliott Indiran
@eindiran
Mar 08 2018 23:13
It would probably turn out kind of messy but you could define a new type for each specific column, with an underlying type that matches what you want
ie
SomeColumn = NewType('SomeColumn', int)
and then do
xyz = SomeColumn(42)
off the top of my head I can't think of a way to do the array sorting task