guettli / python-name2type-mapping

Idea to map variable names in code to type information
Apache License 2.0
2 stars 0 forks source link

consider making it an annotation-generating tool instead of a behavior of type checkers #2

Open carljm opened 6 years ago

carljm commented 6 years ago

I can't see wanting to use this as a long-term way of specifying types in any codebase I work on (too implicit, types divorced from code, when reading the code it just looks un-annotated), but I can definitely imagine using it as a way to bootstrap type annotations on an existing large codebase with strong conventions, in the spirit of existing tools like MonkeyType and pyannotate. In other words, you specify a name to type mapping and run the tool over your code, and it annotates any unannotated argument of that name with the given type. Then you can discard the name-to-type mapping and proceed normally, annotating new code as it is written.

gvanrossum commented 6 years ago

A tool that does something like that is https://github.com/edreamleo/make-stub-files — it writes a stub file, but isn’t there a tool that merges stubs back into the source?

carljm commented 6 years ago

Yep, https://github.com/ambv/retype does that.

gvanrossum commented 6 years ago

Also, this echoes IMPLICIT INTEGER in FORTRAN. :-) -- --Guido (mobile)

guettli commented 6 years ago

@carljm Imagine you do update the source code like you explained. 99 methods were updated. And the next day you create a new method. Now you have 99 methods with type annotation and 1 method without it. But now IDE support could happen: It automatically annotates your new method with the help of the name2type mapping. Wouldn't this be nice? But for this to happen, you must not remove the name2type mapping.

guettli commented 5 years ago

Thank you for your feedback. I will wait until all my code switched to Python3.

Maybe after that name2type mapping is not needed any more.