Python Forum
Tool to adding type annoations
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tool to adding type annoations
#1
Is there a tool that will analyze Python code and add type annotations to functions? A human would look at comments, the body of a function, and at code that calls a function to infer the types of function arguments. I wonder if this can be automated. The tool would not have to be 100% accurate to be useful as an aid in manually adding type annotations.
Reply
#2
Look at MonkeyType made bye Instagram.
Our journey to type checking 4 million lines of Python

So can test MonkeyType to see what it dos.
def double(number):
    return number * 2.5
 
print(double(4))
print(double(5.5))
Output:
10.0 13.75
So can take integer or float as input,and output will be float.
Using MonkeyType:
λ monkeytype apply clean
After apply:
from typing import Union
 
def double(number: Union[float, int]) -> float:
    return number * 2.5
 
print(double(4))
print(double(5.5))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Type hinting - return type based on parameter micseydel 2 2,502 Jan-14-2020, 01:20 AM
Last Post: micseydel
  How to import annoations for python 3.7 and below BrendanSimon 3 13,711 Dec-18-2019, 01:26 PM
Last Post: buran
  Adding markers to Folium map only adding last element. tantony 0 2,132 Oct-16-2019, 03:28 PM
Last Post: tantony

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020