News for hackers. Stuff that matters.
Re:Pyre: Fast Type Checking for Python by mlevental on Friday May 11, 2018 @12:38PM (#17048749)
what i don't understand about stuff like this (and honestly typescript as well) is if there aren't definitions for type schemas then this doesn't work right? like none of these tools will introspect or something and figure out which types i really mean without me annotating with some kind of crazy sum/tuple type definition (e.g. foo() -> Object{a:b,c:d} or whatever it is in typescript). maybe i'm wrong and there's something different here?
Re:Pyre: Fast Type Checking for Python by avbor on Friday May 11, 2018 @01:05PM (#17048971)
Instagram actually has a program for stubbing existing code called MonkeyType. It requires running your code to collect the data, and then after your run finishes you can then apply the new inferred types to your program.
Re:Pyre: Fast Type Checking for Python by mlevental on Friday May 11, 2018 @01:07PM (#17049004)
so like can i throw my entire django app at this thing and have it spit out types for me? probably not right?
Re:Pyre: Fast Type Checking for Python by mhlakhani on Friday May 11, 2018 @01:15PM (#17049086)
That's actually correct - it will spit out types it can infer. https://github.com/Instagram/MonkeyType
Re:Pyre: Fast Type Checking for Python by carapace on Friday May 11, 2018 @02:08PM (#17049544)
(Oh daaaamn that's cool!)
Re:Pyre: Fast Type Checking for Python by hobofan on Friday May 11, 2018 @01:01PM (#17048935)
Even without you explicitly defining types, there is already quite a bit such tools can help you with since they usually come with type annotations for the standard library (or equivalent) of their languages.
Re:Pyre: Fast Type Checking for Python by mlevental on Friday May 11, 2018 @01:06PM (#17048988)
>there is already quite a bit such tools

example?

Re:Pyre: Fast Type Checking for Python by ben509 on Friday May 11, 2018 @02:32PM (#17049729)
Typeshed[1] identifies the types of all builtins for all current (2.7+) versions of python.

[1] https://github.com/python/typeshed/

Re:Pyre: Fast Type Checking for Python by hobofan on Friday May 11, 2018 @01:12PM (#17049051)
0.to_string() / 5

map([1, 2, 3], lambda n: n * 2).some_field_that_doesnt_exist

A type checker would find both mistakes very easily, by only using the information from the standard library.

Re:Pyre: Fast Type Checking for Python by zem on Friday May 11, 2018 @03:22PM (#17050136)
pytype [https://github.com/google/pytype] does do type inference (disclaimer - i work on it). if you supply an explicit type annotation it will be checked for correctness, and if not we trace through the control flow graph to figure out the types of everything as best as we can (which does sometimes mean falling back to Any).

we are working on an extension that will add the inferred types as annotations to your code.

Re:Pyre: Fast Type Checking for Python by orf on Friday May 11, 2018 @12:43PM (#17048791)
PyCharm, and perhaps other tools/editors, does introspect the code. It's not too hard to work out what protocols or interfaces an argument requires, e.g if you use it in a for loop it needs to be iterable, if you index or slice it then it needs to support that, if you add it to an integer etc etc.

It's not about the concrete types but instead about what protocols it supports.