Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 129105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:44:23+00:00 2026-05-11T05:44:23+00:00

I have seen several standards for writing comments about the kind of data a

  • 0

I have seen several standards for writing comments about the kind of data a function expects and returns in Python. Is there a consensus on which one is best-practice?

Is the new functionality in http://www.python.org/dev/peps/pep-3107/ something I should start using for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:44:24+00:00Added an answer on May 11, 2026 at 5:44 am

    Function annotations are not for a specific use, they can be used for anything.

    Tools can be written to extract information from the annotations and do anything you want, including checking types or generating documentation. But python itself does not do anything with the information. You could use to a completely different purpose, i.e. to provide a function that will be called on the parameter or to declare a string of possible return values.

    Annotations can be any object:

    def somefunc(param1: 'string annotation',               param2: 151631,                param3: any_object): -> 'some information here': 

    and you can retrieve the objects using:

    print (somefunc.func_annotations) {'param1': 'string annotation',   'param2': 151631,    'param3': <object any_object>,  'return': 'some information here'} 

    Use case suggestions provided by the PEP:

    • Providing typing information
      • Type checking
      • Let IDEs show what types a function expects and returns
      • Function overloading / generic functions
      • Foreign-language bridges
      • Adaptation
      • Predicate logic functions
      • Database query mapping
      • RPC parameter marshaling
    • Other information
      • Documentation for parameters and return values

    Since function annotation syntax is too new, it is really not used for any production tools.

    I suggest using other methods to document that. I use epydoc to generate my documentation, and it can read parameter typing information from docstrings:

    def x_intercept(m, b):     '''     Return the x intercept of the line M{y=m*x+b}.  The X{x intercept}     of a line is the point at which it crosses the x axis (M{y=0}).      This function can be used in conjuction with L{z_transform} to     find an arbitrary function's zeros.      @type  m: number     @param m: The slope of the line.     @type  b: number     @param b: The y intercept of the line.  The X{y intercept} of a               line is the point at which it crosses the y axis (M{x=0}).     @rtype:   number     @return:  the x intercept of the line M{y=m*x+b}.     '''     return -b/m 

    This example is from epydoc’s website. It can generate documentation in a variety of formats, and can generate good graphs from your classes and call profiles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen several questions with people asking about the same problem but none
I've seen this format function referenced on several sites, but none of them have
I have seen several sites where there is a form, starting with a dropdown
I have seen in several SAAS sites where people store data and the site
I have seen several posts on the subject, but seems like there is little
I have seen several places that Class.getClassLoader() returns the ClassLoader used to load that
I have seen several places in stackoverflow where folks have elegantly and easily turned
I have seen several sites where these social share buttons looks perfectly horizontal aligned.
I have seen several apps that make use of a UISplitViewController inside a tab.
I have seen several posts on how to dismiss a dialog by clicking on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.