Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'elif': 0.05; 'function:': 0.09; 'subject:Function': 0.09; 'way:': 0.09; 'def': 0.12; '"current': 0.16; '(actually': 0.16; '......': 0.16; "function's": 0.16; 'ivan': 0.16; 'skip:> 20': 0.16; 'subject: \n ': 0.16; 'subject:avoiding': 0.16; 'subject:combinations': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'separate': 0.22; 'instance,': 0.24; 'question': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '(possibly': 0.31; '25,': 0.31; 'bunch': 0.31; 'controlled': 0.31; 'file:': 0.31; 'common': 0.35; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'full': 0.61; 'such': 0.63; 'choose': 0.64; 'here': 0.66; 'mar': 0.68; 'on...': 0.68; 'default': 0.69; 'sharing': 0.69; 'behavior': 0.77; '2015': 0.84; 'condition.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=BPzze2HV+cHmBwsMkGmvzQxMYFNfWZYGS9wVQ3S+c7k=; b=AKysugpLItFA77Ghv1Z+4Cs6PDZ9NK798jau+g6kbnUHQGMiBS+lp7UuUnON3QpoZw UHQwpklIyHRPBep2c8jhXBx2/Yo+FjJ3e7vQBnXqAVeO89VcUw/4+/J/LZrhiSh2dJLU D4XAEc4g+o06E56Q3uvMtyDhW7K/fLpUsFkA9+7BJpkbwb/J1ArTcCBq6XXFV/3MW99j 7qaxdKOLc4GZ+2pusJ1XjsipDaPRH84xGvotKeaz7gwkXx2U2WsaRBJKK3uT7qeHyToH fOe/Ey+WK5z6GbMg7qG66HraNGOZRHcA1l9Lkfa/RyihKXz9n4fVmq0QiFyJ54f91fRP vhCg== X-Received: by 10.68.226.161 with SMTP id rt1mr18911969pbc.101.1427306442506; Wed, 25 Mar 2015 11:00:42 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <009d01d06723$38860d50$a99227f0$@gmail.com> References: <009d01d06723$38860d50$a99227f0$@gmail.com> From: Ian Kelly Date: Wed, 25 Mar 2015 12:00:02 -0600 Subject: Re: Function Defaults - avoiding unneccerary combinations of arguments at input To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 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: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427306867 news.xs4all.nl 2954 [2001:888:2000:d::a6]:41510 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87958 On Wed, Mar 25, 2015 at 11:43 AM, Ivan Evstegneev wrote: > Hello all , > > > Just a little question about function's default arguments. > > Let's say I have this function: > > def my_fun(history=False, built=False, current=False, topo=None, > full=False, file=None): > if currnet and full: > do something_1 > elif current and file: > do something_2 > elif history and full and file: > do something_3 > > > ...... some code here.............. > > and so on... > > I won't cover all the possibilities here (actually I don't use all of them > ^_^). > > The question is about avoiding the response for unnecessary combinations? > > For instance, if user will call function this way: > > >>>>my_fun(current=True, full=True, topo='some str', file="some_file") > > That will lead to function's misbehavior. As a particular case it will > choose "current and full" condition. > > > What is the common accepted way to deal with such unwanted situations? Don't try to combine all these into a single function whose behaviour is controlled by a bunch of booleans. Create a separate function instead for each unique intended behavior (possibly sharing a common non-public implementation).