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 4088224
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:57:17+00:00 2026-05-20T18:57:17+00:00

While I am aware of the duck-typing concept of Python, I sometimes struggle with

  • 0

While I am aware of the duck-typing concept of Python, I sometimes struggle with the type of arguments of functions, or the type of the return value of the function.

Now, if I wrote the function myself, I DO know the types. But what if somebody wants to use and call my functions, how is he/she expected to know the types?
I usually put type information in the function’s docstring (like: "...the id argument should be an integer..." and "... the function will return a (string, [integer]) tuple.")

But is looking up the information in the docstring (and putting it there, as a coder) really the way it is supposed to be done?

Edit: While the majority of answers seem to direct towards “yes, document!” I feel this is not always very easy for ‘complex’ types.
For example: how to describe concisely in a docstring that a function returns a list of tuples, with each tuple of the form (node_id, node_name, uptime_minutes) and that the elements are respectively a string, string and integer?
The docstring PEP documentation doesn’t give any guidelines on that.
I guess the counterargument will be that in that case classes should be used, but I find python very flexible because it allows passing around these things using lists and tuples, i.e. without classes.

  • 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. Editorial Team
    Editorial Team
    2026-05-20T18:57:18+00:00Added an answer on May 20, 2026 at 6:57 pm

    This is how dynamic languages work. It is not always a good thing though, especially if the documentation is poor – anyone tried to use a poorly documented python framework? Sometimes you have to revert to reading the source.

    Here are some strategies to avoid problems with duck typing:

    • create a language for your problem domain
    • this will help you to name stuff properly
    • use types to represent concepts in your domain language
    • name function parameters using the domain language vocabulary

    Also, one of the most important points:

    • keep data as local as possible!

    There should only be a few well-defined and documented types being passed around. Anything else should be obvious by looking at the code: Don’t have weird parameter types coming from far away that you can’t figure out by looking in the vicinity of the code…

    Related, (and also related to docstrings), there is a technique in python called doctests. Use that to document how your methods are expected to be used – and have nice unit test coverage at the same time!

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

Sidebar

Related Questions

While aware of the appstore guidelines, specifically IAP usage. Our company is developing an
While I am well aware that it isn't possible for me to refer to
I am aware that it is not possible to echo the * while you
While I know some jQuery to simplify front-end manipulation programming, I also aware of
While developing an application using gwt in ecliplse crashed. Now the server is running
While I am aware of the differences between debug and release builds, I am
Is anyone aware how to configure nagle's algorithm (on or off) while using socket.io?
A while back I found that it's possible to write a C++ function that
Has anyone ever actually used stackalloc while programming in C#? I am aware of
While I'm aware that you can't reference self directly in a decorator, I was

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.