Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; '"or': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'template': 0.14; '23,': 0.16; 'argument.': 0.16; 'dict': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'suggested,': 0.16; 'tuple': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'examples': 0.20; 'example': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; "d'aprano": 0.31; 'steven': 0.31; 'probably': 0.32; 'fri,': 0.33; 'problem': 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'possible': 0.36; 'should': 0.36; 'skip:m 40': 0.38; 'rather': 0.38; 'how': 0.40; 'skip:o 30': 0.61; 'kind': 0.63; 'subject:! ': 0.74; '2015': 0.84; 'sound.': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=gkyyS5mBtcA4P36GCDnWpTxm29r/AJkE5h4+QxPBIdo=; b=fpg2azllyHqefqhb6q5jLKLtNYw7w/h4EZmGKaoqKEu9Djxyml3TIQtbATWosrgsEW LPQHGom5xyNxICPSNQLF/swC+iVOcyLT3+mwSo0MjnSgzwpn59d5PyFU6iDh7ZMuj+j1 Dmw1mOYD0CNoKlBrP/VMmZ1vudnTlLsG58mtt9eAgT+u2vinLMKUQJ8gnEnlJOwEk8n4 feI1mqStguC/EYs9iL87EfS64DtFGiQNpGGOY/pnEN+UuRn0zJbbuYlN4Po5o2Yf4s7i 5JZnm/9cIQ+BI/5n+sV5wrtIN73a48bQ4LzNlui94HKM3f9KajjGHkcEwDr9T8LIkXl7 nQpg== MIME-Version: 1.0 X-Received: by 10.224.23.133 with SMTP id r5mr3503498qab.88.1421939605814; Thu, 22 Jan 2015 07:13:25 -0800 (PST) In-Reply-To: <54c10fe9$0$12988$c3e8da3$5496439d@news.astraweb.com> References: <54c07d04$0$13012$c3e8da3$5496439d@news.astraweb.com> <54c0a571$0$13002$c3e8da3$5496439d@news.astraweb.com> <54c10fe9$0$12988$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 23 Jan 2015 02:13:25 +1100 Subject: Re: Python is DOOMED! Again! From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421939608 news.xs4all.nl 2868 [2001:888:2000:d::a6]:48455 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:84234 On Fri, Jan 23, 2015 at 1:57 AM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> Hold on a moment, how often do you really do this kind of thing with >> "might be one of them or a sequence"? > > isinstance(obj, one_class_or_tuple_of_classes) > issubclass(cls, one_class_or_tuple_of_classes) > mystr.startswith(prefix_or_tuple_of_prefixes) > mystr.endswith(suffix_or_tuple_of_suffixes) > template % one_string_or_tuple_of_strings # or a dict :-) > > > I'm not suggesting that the specific example is a good one, but the > principle is sound. All of your examples are "might be one of them or a tuple". Not "sequence", "tuple". That gets around the problem of recognition, because in no case is a single tuple a valid argument. I suspect it would be possible to use TypeVar to create a nice "OneOrMore" like you suggested, but for reliability, it should probably be "or tuple" rather than "or sequence". ChrisA