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


Groups > comp.lang.python > #105875

Re: How to make Python interpreter a little more strict?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: How to make Python interpreter a little more strict?
Date Mon, 28 Mar 2016 07:59:32 +1100
Lines 53
Message-ID <mailman.96.1459114203.28225.python-list@python.org> (permalink)
References <20160325150608.21c3827a@fujitsu> <CAPTjJmqYuzLRGX6x6w5hpWQaB4UJ+-Dy=RXgotUxT-CO6rjYXA@mail.gmail.com> <mailman.67.1459037003.28225.python-list@python.org> <56f7536b$0$22140$c3e8da3$5496439d@news.astraweb.com> <mailman.94.1459110963.28225.python-list@python.org> <nd9gqh$rp$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de pILBsgyKLqCIIxsb5KJPGwUtWAP4QZgELW2J9D1q932g==
Return-Path <rosuav@gmail.com>
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; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'discard': 0.05; 'exist,': 0.07; 'cc:addr:python-list': 0.09; 'subject:How': 0.09; 'exist.': 0.09; 'nameerror:': 0.09; 'used"': 0.09; 'python': 0.10; 'exception': 0.13; 'syntax': 0.13; 'def': 0.13; 'explicitly': 0.15; 'headers': 0.15; '2016': 0.16; 'dummy': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'marker': 0.16; 'nameerror': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'shifts': 0.16; 'subject:make': 0.16; 'try/except': 0.16; 'useless.': 0.16; 'wrote:': 0.16; 'try:': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'assign': 0.22; 'am,': 0.23; '(or': 0.23; 'tim': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; "i've": 0.25; "doesn't": 0.26; 'least': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'chase': 0.29; 'raise': 0.29; 'code': 0.30; 'generally': 0.32; "d'aprano": 0.33; 'raised': 0.33; 'steven': 0.33; 'similar': 0.33; 'case,': 0.34; 'except': 0.34; 'received:google.com': 0.35; 'fail': 0.35; 'quite': 0.35; "isn't": 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'lines': 0.36; 'received:209.85': 0.36; '(and': 0.36; 'assigned': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'expect': 0.37; '(with': 0.38; 'received:209': 0.38; 'building': 0.38; 'test': 0.39; 'where': 0.40; 'some': 0.40; 'your': 0.60; 'subject:more': 0.61; 'places': 0.64; 'mar': 0.65; 'hints': 0.66; "they're": 0.66; 'useful.': 0.72; 'counts': 0.81; '(ie': 0.84; 'chrisa': 0.84; 'conscious': 0.84; 'to:none': 0.91; 'dozen': 0.91
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; bh=YriLMpOexLQA1zWPIARl68RwiDJ2HXuGa7FIFB755h4=; b=zDaurDhXpi64IRmoEtlJFDvXWf84b/j2+YRuC/jQiFLqwMoAwyDEEgi9TnKZwyFZ4K cRlfxnMXeApbOk0QcMeQupRKKfQmMpiKDMZGBc/+xA6DZtSy83XXCBY205GCbMyIPB5M EmcBQhYbTlkhv7W6HKqZTS9bYUqyWjLiu2vUI8c+5rqAqZIDL4ooX1RK4718DgUT3+17 0KZAziM8fC/SaHZGL2OlEs574hFF6y+XfHef9FuHPa0n4zke02xjk7OY3BgVn5jZcMYH L/ui6J3TymqBSNtmkIhAdmBrkqQO0p/Uuj4typECMjBVV5tCEFFoEWVNU/4qdug2WwTm ed7w==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=YriLMpOexLQA1zWPIARl68RwiDJ2HXuGa7FIFB755h4=; b=ArH4NdDwg++VlFXu2GSz59Ksb3DVpl5JK+SdIss9S9/4lMV59jl+6/T+ZDyXSkMwas J0fAZDfYwuXT+tHHgLVyjMWsQ2BRiq0v0rH0SKVfBhLMLSRQUJrPSspIXtexkXUqS5ZS BqumTtS72bR9/PrBPyTebj+QM0dyBpluKgc3AeBfPlPQvb7HUB1czouGuTReJcc++ktF zi/5Ga2tt8t5GTurO2eKZGZ23R1CZA44C3NXQ8peeouES+ThNvuxvhNKBch2xNpGKnUD n+5cC2S9HH1IKvjmV2D9snoH23azZCJYF6k05FiKszoAX/gxgweh5/UIrNGIf6sWARAK bfXQ==
X-Gm-Message-State AD7BkJLKAdLNLc0YiexsO9P7Q8C7iBJK6BBw2V7gPlCJEnFJy33WJFK+ENlDdvy2xGk3TP0rO8B0uY+/8xY3xQ==
X-Received by 10.107.63.139 with SMTP id m133mr21314123ioa.157.1459112373094; Sun, 27 Mar 2016 13:59:33 -0700 (PDT)
In-Reply-To <nd9gqh$rp$1@dont-email.me>
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>
Xref csiph.com comp.lang.python:105875

Show key headers only | View raw


On Mon, Mar 28, 2016 at 7:49 AM, BartC <bc@freeuk.com> wrote:
> On 27/03/2016 21:32, Tim Chase wrote:
>>
>> On 2016-03-27 14:28, Steven D'Aprano wrote:
>
>
>>> In this case, the two lines "fnc" and "next" simply look up the
>>> function names, but without actually calling them. They're not
>>> quite "no-ops", since they can fail and raise NameError if the name
>>> doesn't exist, but otherwise they might as well be no-ops.
>>
>>
>> Which is actually useful.  I've got some 2.4 code that reads
>>
>>    try:
>>      any
>>    except NameError:
>>      def any(...):
>>        ...
>>
>> (with a similar block for all() )
>>
>> I don't want to call any() or all(), I simply want to test whether
>> they exist.
>
>
> But would it have been much of an imposition to have typed:
>
>     try:
>       test = any
>     except NameError:
>       def any(...):
>         ...
>
> ? (Or any of the half dozen ways there must be to test the existence of a
> name.)

It shifts the uselessness to "why did you assign to that name?". While
that's not too bad (and nothing like as bad as a dummy function call),
it's generally reserved for the places where Python syntax mandates an
assignment:

for _ in range(4): next(iter) # discard the headers

If you're building a linter, I would expect "name assigned to and
never used" to be its own warning; but also, the try/except block
hints that this isn't useless. Generally, "dummy expressions" like
this are going to explicitly catch at least one exception that can be
raised only in that expression (ie a really small try block). That
pretty much counts as your language-level marker for conscious dummy
expression usage.

ChrisA

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


Thread

Re: How to make Python interpreter a little more strict? John Pote <johnhpote@o2.co.uk> - 2016-03-26 23:30 +0000
  Re: How to make Python interpreter a little more strict? BartC <bc@freeuk.com> - 2016-03-27 00:36 +0000
  Re: How to make Python interpreter a little more strict? Steven D'Aprano <steve@pearwood.info> - 2016-03-27 14:28 +1100
    Re: How to make Python interpreter a little more strict? Tim Chase <python.list@tim.thechases.com> - 2016-03-27 15:32 -0500
      Re: How to make Python interpreter a little more strict? BartC <bc@freeuk.com> - 2016-03-27 21:49 +0100
        Re: How to make Python interpreter a little more strict? Chris Angelico <rosuav@gmail.com> - 2016-03-28 07:59 +1100
        Re: How to make Python interpreter a little more strict? Steven D'Aprano <steve@pearwood.info> - 2016-03-28 12:24 +1100
  Re: How to make Python interpreter a little more strict? Nobody <nobody@nowhere.invalid> - 2016-03-28 00:26 +0100

csiph-web