Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'parameters': 0.04; 'base.': 0.05; '(especially': 0.07; 'defaults': 0.07; 'nested': 0.07; 'string': 0.09; 'arguments': 0.09; 'bytes,': 0.09; 'literal': 0.09; 'parameter': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'surrounded': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'itself.': 0.14; "'+'": 0.16; "'-'": 0.16; '(default': 0.16; 'bytearray': 0.16; 'given,': 0.16; 'integer,': 0.16; 'len(c)': 0.16; 'literal.': 0.16; 'preceded': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'stdlib.': 0.16; 'subject:etc.': 0.16; 'subject:parameters': 0.16; 'truncates': 0.16; 'types,': 0.16; 'whitespace.': 0.16; 'zero.': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'module': 0.19; '>>>': 0.22; 'example': 0.22; 'header:User-Agent:1': 0.23; 'integer': 0.24; 'interpret': 0.24; 'specify': 0.24; 'string,': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'code': 0.31; 'comments': 0.31; 'towards': 0.31; 'coded': 0.31; 'doc': 0.31; 'prints': 0.31; 'convert': 0.35; 'representing': 0.36; 'sequence': 0.36; 'should': 0.36; 'expected': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'number,': 0.60; 'received:173': 0.61; "you're": 0.61; 'here': 0.66; "else's": 0.84; 'given.': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: python function parameters, debugging, comments, etc. Date: Tue, 01 Oct 2013 19:56:41 -0400 References: <524B5288.1050709@mail.usask.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0 In-Reply-To: <524B5288.1050709@mail.usask.ca> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380671823 news.xs4all.nl 15920 [2001:888:2000:d::a6]:38902 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55260 On 10/1/2013 6:54 PM, Chris Friesen wrote: > Given the fact that function parameters do not specify types, when you're looking at someone else's code how the heck do you know what is expected for a given argument? (Especially in a nontrivial system where the parameter is just passed on to some other function and may not be evaluated for several nested function calls.) > > Is the recommendation to have comments for each function describing the expected args? Here is an example from the stdlib. >>> print(int.__doc__) int(x=0) -> integer int(x, base=10) -> integer Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero. If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int('0b100', base=0) 4 help(int) prints the above plus the int methods. Functions coded in Python should not have the signature in the doc string because help() can get it from the function object itself. >>> def f(a, b=3, *, c='abc'): '''return (a + b) / len(c) a and b (default 3) are numbers. c must be a sequence (default 'abc').''' >>> help(f) Help on function f in module __main__: f(a, b=3, *, c='abc') return (a + b) / len(c) a and b (default 3) are numbers. c must be a sequence (default 'abc'). >>> -- Terry Jan Reedy