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


I have seen many ways to write comments which hope for the function and gives it in Python. Is there any consensus on which is the best practice?

Should I start new functionality in something for this?

Function annotations are not for any particular use, it can be used for anything .

Totes can be written to remove information from annotations and do anything, but the dragon does not do anything with the information itself, you can use it for a completely different purpose, that is, To provide functions that will be called on the parameter or to declare a string of possible return values.

The comment can be any object:

  def somefunc (Ultimate 1: "string annotation", absolute 2: 151631, paragraph 3: any_object): - & gt; ; "Here are some information":  

and you can retrieve items you use:

  print (somefunc.func_annotations) {'param1' : Use the case suggestions provided by "String Annotation" PAP:       
  • Provide typing information
  • IDEs show what kind of function is expected and returns
  • function overloading / generic function
  • foreign language bridges
  • Optimization
  • Logic
  • Database Query Mapping
  • RPC Parameter Marshling <
  • Other Information
    • For Parameter and Return Values Document Annotation syntax is very new, it is not actually used for any production tools.

      I use epydoc to create my documents, and it can read parameter typing information from the dotstring:

        def x_intercept (m, b): Return "X" of the X block of the line y {y = M * x + B}. The x {x intercept} of a line is the point at which it crosses X axis (M {y = 0}). To use this function can be used in conjuction with L {z_transform}, arbitrarily function zero. @ Type A : No @ Ultimate M: slope of the line. @ Type B: Number @ PRM B: Line intercepts. Point of X {Y intercept} of a line on which it crosses the Y axis (M {x = 0}) . @ Type: number @ layer: x blocking of line M {y = m * x + b}. "" Return -b / m  

      This example is in many formats Can generate documentation, and create good graphs with their classes and call profiles.


Comments