Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion with-statement syntactic quirk

Received: by 10.180.86.97 with SMTP id o1mr782278wiz.2.1351704398825;
        Wed, 31 Oct 2012 10:26:38 -0700 (PDT)
X-BeenThere: python-ideas@googlegroups.com
Received: by 10.180.77.130 with SMTP id s2ls3646959wiw.4.gmail; Wed, 31 Oct
 2012 10:26:38 -0700 (PDT)
Received: by 10.180.86.97 with SMTP id o1mr782271wiz.2.1351704398684;
        Wed, 31 Oct 2012 10:26:38 -0700 (PDT)
Received: by 10.180.86.97 with SMTP id o1mr782269wiz.2.1351704398668;
        Wed, 31 Oct 2012 10:26:38 -0700 (PDT)
Return-Path: <python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org>
Received: from mail.python.org (mail.python.org. [2001:888:2000:d::a6])
        by gmr-mx.google.com with ESMTPS id e5si774516wiw.0.2012.10.31.10.26.38
        (version=TLSv1/SSLv3 cipher=OTHER);
        Wed, 31 Oct 2012 10:26:38 -0700 (PDT)
Received-SPF: pass (google.com: domain of python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org designates 2001:888:2000:d::a6 as permitted sender) client-ip=2001:888:2000:d::a6;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org designates 2001:888:2000:d::a6 as permitted sender) smtp.mail=python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org; dkim=pass header...@python.org
Received: from albatross.python.org (localhost [127.0.0.1])
	by mail.python.org (Postfix) with ESMTP id 3XsGgL2mXjzPhw
	for <python-ideas-garchive-35620@googlegroups.com>; Wed, 31 Oct 2012 18:26:38 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901;
	t=1351704398; bh=VeqrhAEPcgUk2PFuoIC+adhkMOQaJ5ed0cs7+HS8ekA=;
	h=Message-ID:Date:From:MIME-Version:To:References:In-Reply-To:
	 Subject:Reply-To:List-Id:List-Unsubscribe:List-Archive:List-Post:
	 List-Help:List-Subscribe:Content-Transfer-Encoding:Content-Type:
	 Sender;
	b=MDjWr6iK2eJD8oWl+wuYOxtw42X5M8PMuP4RqX8RUoNVlnWLZCv/ZXeuiY7c2cHX+
	 kFfPFVWG4TpprUAVRIC0WUl9YNYdxTxeaFjlHjOmVJ9WzBgr9txHssFX7QGMfYuqWX
	 1YllSY8n5vlJhS7vOGbo7jIFlRUBjgAUasxleo8o=
X-Original-To: python-id...@python.org
Delivered-To: python-id...@mail.python.org
Received: from albatross.python.org (localhost [127.0.0.1])
	by mail.python.org (Postfix) with ESMTP id 3XsGf31ls0zPg9
	for <python-id...@python.org>; Wed, 31 Oct 2012 18:25:31 +0100 (CET)
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject::
	[': 0.03; 'syntax': 0.03; 'subject:Python': 0.05; 'context': 0.05;
	'advocate': 0.07; 'parameter': 0.07; 'parser': 0.07; 'parsing':
	0.07; 'plenty': 0.07; 'trailing': 0.07; '(it': 0.09; 'accepted,':
	0.09; 'ambiguity': 0.09; 'precedence': 0.09; 'tuple': 0.09;
	'suggest': 0.11; 'sections': 0.13; 'ignore': 0.13; 'cases': 0.15;
	'":"': 0.16; '"if"': 0.16; "(it's": 0.16; '*should*': 0.16;
	'duplicating': 0.16; 'expression.': 0.16; 'expressions,': 0.16;
	'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16;
	'from:name:mrab': 0.16; 'ignores': 0.16; 'message-
	id:@mrabarnett.plus.com': 0.16; 'newlines': 0.16; 'nick': 0.16;
	'oct': 0.16; 'parentheses': 0.16; 'singleton': 0.16;
	'subject:ideas': 0.16; 'syntactical': 0.16; 'token,': 0.16;
	'tuples,': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'handles': 0.18;
	'>>>': 0.18; 'subject:] ': 0.19; 'file.': 0.20; 'import': 0.21;
	'meant': 0.21; '31,': 0.22; "python's": 0.23; 'statement': 0.23;
	'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1':
	0.26; 'looks': 0.26; 'am,': 0.27; 'guess': 0.27; 'possibility':
	0.27; 'rules': 0.27; 'change,': 0.27; 'skip:( 20': 0.28;
	'grouping': 0.29; 'mind,': 0.29; 'received:192.168.1.3': 0.29;
	'to:name:python-ideas': 0.29; 'definition': 0.29; 'probably':
	0.29; 'class': 0.29; 'relative': 0.30; 'function': 0.30; 'point':
	0.31; 'gets': 0.32; 'could': 0.32; "aren't": 0.33; 'control,':
	0.33; 'agreed': 0.33; 'another': 0.33; 'clear': 0.35; 'pm,': 0.35;
	'there': 0.35; 'but': 0.36; 'subject:with': 0.36; 'should': 0.36;
	'skip:p 20': 0.36; 'why': 0.37; 'quite': 0.37; 'fact': 0.38;
	'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'received:192':
	0.39; 'called': 0.39; 'where': 0.40; 'received:192.168': 0.40;
	'subject:-': 0.40; 'managers': 0.60; 'places': 0.61; 'between':
	0.63; 'different': 0.63; 'more': 0.63; 'treat': 0.65; 'header
	:Reply-To:1': 0.68; 'to:addr:python-ideas': 0.69; 'bendersky':
	0.84; 'calls,': 0.84; 'it"': 0.84; 'reply-to:addr:python.org':
	0.84; 'treats': 0.84; 'slipped': 0.91; 'eli': 0.93
Received: from localhost (HELO mail.python.org) (127.0.0.1)
	by albatross.python.org with SMTP; 31 Oct 2012 18:25:31 +0100
Received: from avasout04.plus.net (avasout04.plus.net [212.159.14.19])
	by mail.python.org (Postfix) with ESMTP
	for <python-id...@python.org>; Wed, 31 Oct 2012 18:25:31 +0100 (CET)
Received: from [192.168.1.3] ([84.92.122.60]) by avasout04 with smtp
	id HtRP1k00A1JHTmU01tRQXw; Wed, 31 Oct 2012 17:25:25 +0000
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.0 cv=A/DuztqG c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17
	a=b2nRVtXOy8EA:10 a=yUImSZUSGokA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10
	a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=W3204vjVee0A:10
	a=pGLkceISAAAA:8 a=G_FLL6VyQbZZNOwbEnMA:9 a=wPNLvfGTeEIA:10
	a=MSl-tDqOz04A:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH: mrabarnett:2500
Message-ID: <50915F06.8020...@mrabarnett.plus.com>
Date: Wed, 31 Oct 2012 17:25:26 +0000
From: MRAB <pyt...@mrabarnett.plus.com>
User-Agent: Mozilla/5.0 (Windows NT 5.1;
	rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: python-ideas <python-id...@python.org>
References: <20121031113853.66fb0514@resist>
	<CABicbJJWSHvyFNh4BBkTczZ9=gSLCaP59LqMN4dhAYao1pE...@mail.gmail.com>
	<CAF-Rda-7RhbEm+xHJ_P7xda_6y2nMRYVxPJ8_ZcfuGOsg9-...@mail.gmail.com>
	<CABicbJL-NFXYgKxTVJZLcUZ7Y1-dbCs3rV_mbEWaVqh=WMJ...@mail.gmail.com>
	<CAF-Rda_EQ4Es+jA7qEu_0TNnih-3md2CToihyfaGQLZL28n...@mail.gmail.com>
	<CADiSq7dXZ29F_ifKQQO9w+1x-GGW+o+xEYnp2viA3f7-UcX...@mail.gmail.com>
In-Reply-To: <CADiSq7dXZ29F_ifKQQO9w+1x-GGW+o+xEYnp2viA3f7-UcX...@mail.gmail.com>
Subject: Re: [Python-ideas] with-statement syntactic quirk
X-BeenThere: python-id...@python.org
X-Mailman-Version: 2.1.15
Precedence: list
Reply-To: python-ideas <python-id...@python.org>
List-Id: Discussions of speculative Python language ideas
	<python-ideas.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/options/python-ideas>,
	<mailto:python-ideas-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-ideas/>
List-Post: <mailto:python-id...@python.org>
List-Help: <mailto:python-ideas-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-ideas>,
	<mailto:python-ideas-requ...@python.org?subject=subscribe>
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Errors-To: python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org
Sender: "Python-ideas"
	<python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org>

On 2012-10-31 13:22, Nick Coghlan wrote:
> On Wed, Oct 31, 2012 at 10:52 PM, Eli Bendersky <eli...@gmail.com> wrote:
>> On Wed, Oct 31, 2012 at 5:45 AM, Devin Jeanpierre <jeanpierr...@gmail.com>
>> wrote:
>>> Anyway, it looks like this isn't how the tokenizer treats
>>> braces/brackets (it ignores indent/dedent, but not newlines (I guess
>>> the grammar handles those)). What I meant to suggest was, treat "with
>>> ... :" similarly to how the OP suggests treating "with (...) :".
>>
>> If this gets accepted, then, is there a reason to stop at "with"? Why not
>> ignore newlines between "if" and its trailing ":" as well? [playing devil's
>> advocate here]
>
> Note that I agreed with Barry that we probably *should* change it from
> a principle-of-least-surprise point of view. I just called "not it" on
> actually figuring out how to make it work given the current Grammar
> definition as a starting point :)
>
> Between expression precedence control, singleton tuples, generator
> expressions, function calls, function parameter declarations, base
> class declarations, import statement grouping and probably a couple of
> other cases that have slipped my mind, parentheses already have plenty
> of different meanings in Python, and we also have plenty of places
> where the syntactical rules aren't quite the same as those in an
> ordinary expression.
>
> The thing that makes Python's parser simple is the fact that we have
> *prefixes* in the Grammar that make it clear when the parsing rules
> should change, so you don't need much lookahead at parsing time (it's
> deliberately limited to only 1 token, in fact). The challenge in this
> particular case is to avoid a Grammar ambiguity relative to ordinary
> expression syntax without duplicating large sections of the grammar
> file.
>
Another possibility could be to allow a tuple of context managers and a
tuple of names:

with (open('/etc/passwd'), open('/etc/passwd')) as (p1, p2):
     pass

meaning:

with open('/etc/passwd') as p1:
     with open('/etc/passwd')) as p2:
         pass

or perhaps more correctly:

with open('/etc/passwd') as temp_1:
     with open('/etc/passwd')) as temp_2:
         p1, p2 = temp_1, temp_2
         pass

It would also allow:

with (cmA, cmB):
     pass

meaning:

with cmA:
     with cmB:
         pass

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas