Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106575

Re: Checking function's parameters (type, value) or not ?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Newsgroups comp.lang.python
Subject Re: Checking function's parameters (type, value) or not ?
Date Wed, 6 Apr 2016 14:29:02 +0100
Lines 36
Message-ID <mailman.131.1459949361.32530.python-list@python.org> (permalink)
References <57050a05$0$4546$426a34cc@news.free.fr> <ne32v4$sfl$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de KJdyST9wWUhqR1RIkXrb/QaCfsoQEzqaTI837WpiL0tw==
Return-Path <python-python-list@m.gmane.org>
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; 'from:addr:yahoo.co.uk': 0.05; 'used.': 0.05; 'tests,': 0.07; 'ast': 0.09; 'int)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'str)': 0.09; 'worse': 0.09; 'example:': 0.10; 'stored': 0.10; 'python': 0.10; 'subject:not': 0.11; 'def': 0.13; 'interpreter': 0.15; 'result.': 0.15; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:parameters': 0.16; 'subject:type': 0.16; 'url:ftp': 0.16; 'wrote:': 0.16; 'later': 0.16; 'language': 0.19; 'library': 0.20; 'lawrence': 0.22; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'parameters': 0.27; 'subject: ?': 0.27; 'function': 0.28; 'crash': 0.29; 'language.': 0.32; 'subject:) ': 0.32; 'url:python': 0.33; 'running': 0.34; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'test': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'provide': 0.61; 'url:t': 0.62; 'charset:windows-1252': 0.62; 'our': 0.64; 'designers': 0.72; 'pythonistas,': 0.84; 'subject:value': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host 80.234.189.93
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2
In-Reply-To <57050a05$0$4546$426a34cc@news.free.fr>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <ne32v4$sfl$1@ger.gmane.org>
X-Mailman-Original-References <57050a05$0$4546$426a34cc@news.free.fr>
Xref csiph.com comp.lang.python:106575

Show key headers only | View raw


On 06/04/2016 14:07, ast wrote:
> Hello
>
> I would like to know if it is advised or not to test
> a function's parameters before running it, e.g
> for functions stored on a public library ?
>
> Example:
>
> def to_base(nber, base=16, use_af=True, sep=''):
>
>     assert isinstance(nber, int) and nber >= 0
>     assert isinstance(base, int) and base >= 2
>     assert isinstance(use_af, bool)
>     assert isinstance(sep, str) and len(sep) == 1
>
>    tbc
>
> With these tests, you are sure that the function to_base is
> well used. But it slows down the program.
> Without, python interpreter may crash later in the function
> or worse provide a meaningless result.
>
> What library designers do ?
>


Please see 
http://ftp.dev411.com/t/python/python-list/13bhcknhan/when-to-use-assert

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Checking function's parameters (type, value) or not ? "ast" <nomail@com.invalid> - 2016-04-06 15:07 +0200
  Re: Checking function's parameters (type, value) or not ? Chris Angelico <rosuav@gmail.com> - 2016-04-06 23:27 +1000
  Re: Checking function's parameters (type, value) or not ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-04-06 14:29 +0100
    Re: Checking function's parameters (type, value) or not ? "ast" <nomail@com.invalid> - 2016-04-06 16:18 +0200
      Re: Checking function's parameters (type, value) or not ? "ast" <nomail@com.invalid> - 2016-04-06 19:49 +0200
  Re: Checking function's parameters (type, value) or not ? Steven D'Aprano <steve@pearwood.info> - 2016-04-07 02:30 +1000

csiph-web