Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'override': 0.07; 'variant': 0.07; 'enhancements': 0.09; 'global,': 0.09; 'naturally': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'specifying': 0.09; 'itself.': 0.11; 'argument': 0.15; 'explicitly': 0.15; 'importing': 0.15; '"use': 0.16; 'constants': 0.16; 'function"': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wary': 0.16; 'wrote:': 0.16; 'thoughts': 0.18; 'meant': 0.22; 'module': 0.23; 'split': 0.23; 'import': 0.24; 'second': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'not.': 0.27; '(such': 0.27; "i'm": 0.29; 'methods.': 0.29; 'function': 0.30; 'keyword': 0.31; 'url:python': 0.33; "d'aprano": 0.33; 'enhanced': 0.33; 'flags': 0.33; 'steven': 0.33; 'subject:?': 0.34; 'to:addr:python-list': 0.35; 'false': 0.35; 'filter': 0.35; 'really': 0.35; 'url:org': 0.36; 'there': 0.36; 'two': 0.37; 'should': 0.37; 'setting': 0.37; 'subject:: ': 0.37; 'version': 0.38; 'received:org': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.39; 'skip:e 20': 0.39; 'received:de': 0.40; 'subject:the': 0.40; 'some': 0.40; 'default': 0.61; 'more': 0.62; 'different': 0.64; 'believe': 0.67; 'obvious': 0.72; 'url:search': 0.83; 'alone,': 0.84; 'routines': 0.84; 'subject:Set': 0.91; 'not:': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Set a flag on the function or a global? Date: Tue, 16 Jun 2015 15:59:32 +0200 Organization: None References: <557f6676$0$21718$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd937e.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 1434463188 news.xs4all.nl 2873 [2001:888:2000:d::a6]:34410 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:92679 Steven D'Aprano wrote: > I have a function in a module which is intended to be used by importing > that name alone, then used interactively: > > from module import edir > edir(args) > > > edir is an enhanced version of dir, and one of the enhancements is that > you can filter out dunder methods. I have reason to believe that people > are split on their opinion on whether dunder methods should be shown by > default or not: some people want to see them, others do not. Since edir > is meant to be used interactively, I want to give people a setting to > control whether they get dunders by default or not. > > I have two ideas for this, a module-level global, or a flag set on the > function object itself. Remember that the usual way of using this will be > "from module import edir", there are two obvious ways to set the global: > > import module > module.dunders = False > > # -or- > > edir.__globals__['dunders'] = False > > > Alternatively, I can use a flag set on the function object itself: > > edir.dunders = False > > > Naturally you can always override the default by explicitly specifying a > keyword argument edir(obj, dunders=flag). > > Thoughts and feedback? Please vote: a module global, or a flag on the > object? Please give reasons, and remember that the function is intended > for interactive use. """ In general I'm wary of routines that take flags (such as 'swapped') that really mean "use a different version of the function" -- these flags are almost always passed from constants and so it would be more efficient to have a second name for the variant function. """ http://legacy.python.org/search/hypermail/python-1994q2/0852.html