code_junkie

How do I specify input and output data types in python comments

Nov 13th, 2011
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. def somefunc(param1: "string annotation",
  2. param2: 151631,
  3. param3: any_object): -> "some information here":
  4.  
  5. print (somefunc.func_annotations)
  6. {'param1': "string annotation",
  7. 'param2': 151631,
  8. 'param3': <object any_object>,
  9. 'return': "some information here"}
  10.  
  11. def x_intercept(m, b):
  12. """
  13. Return the x intercept of the line M{y=m*x+b}. The X{x intercept}
  14. of a line is the point at which it crosses the x axis (M{y=0}).
  15.  
  16. This function can be used in conjuction with L{z_transform} to
  17. find an arbitrary function's zeros.
  18.  
  19. @type m: number
  20. @param m: The slope of the line.
  21. @type b: number
  22. @param b: The y intercept of the line. The X{y intercept} of a
  23. line is the point at which it crosses the y axis (M{x=0}).
  24. @rtype: number
  25. @return: the x intercept of the line M{y=m*x+b}.
  26. """
  27. return -b/m
  28.  
  29. def someFunction( arg1, arg2 ):
  30. """Returns the average of *two* (and only two) arguments.
  31.  
  32. :param arg1: a numeric value
  33. :type arg1: **any** numeric type
  34.  
  35. :param arg2: another numeric value
  36. :type arg2: **any** numeric type
  37.  
  38. :return: mid-point (or arithmetic mean) between two values
  39. :rtype: numeric type compatible with the args.
  40. """
  41. return (arg1+arg2)/2
Add Comment
Please, Sign In to add comment