4 ms·
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? li
by mlevental 8y ago
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?
- orf 8y agoPyCharm, 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.
- hobofan 8y agoEven 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.
- mlevental 8y ago>there is already quite a bit such tools example?
- hobofan 8y ago0.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.
- ben509 8y agoTypeshed[1] identifies the types of all builtins for all current (2.7+) versions of python. [1] https://github.com/python/typeshed/ https://github.com/python/typeshed/
- avbor 8y agoInstagram 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.
- mlevental 8y agoso like can i throw my entire django app at this thing and have it spit out types for me? probably not right?
- zem 8y agopytype [https://github.com/google/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.