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


Groups > comp.lang.python > #111808

Re: Why not allow empty code blocks?

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Why not allow empty code blocks?
Date Sun, 24 Jul 2016 23:38:36 +1000
Lines 88
Message-ID <mailman.91.1469367519.22221.python-list@python.org> (permalink)
References <b80ae0ca-d8b2-4430-96a1-7a6768b177ef@googlegroups.com> <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <mailman.77.1469276992.22221.python-list@python.org> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <mailman.79.1469282085.22221.python-list@python.org> <nmvtlu$oqu$1@dont-email.me> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <nn25m4$4d1$1@dont-email.me> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmoG=qVAVEXK0pzbwYp13HBC-ROf2MbkF_3E2XbapihXvQ@mail.gmail.com> <CABbU2U-JmQgG-45oA4AOnCs85cZhcLoiWagjME4CZjZdhT9-rw@mail.gmail.com> <CAPTjJmqyzpVLDmRUrTbBSmfeW4Jr+Jeh=vM1eo08d+bgTbKZHA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de 0+TQVKx7hwg4jVz6vFM6aQ7gLJHDw3golv7HFSvVHyGA==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'warnings': 0.03; 'enabling': 0.05; 'python3': 0.05; 'subject:code': 0.07; 'trailing': 0.07; 'ignoring': 0.09; 'inserted': 0.09; 'script,': 0.09; 'subject:Why': 0.09; 'tuple': 0.09; 'python': 0.10; 'subject:not': 0.11; 'missed': 0.15; '2016': 0.16; '24,': 0.16; 'alchemy': 0.16; 'comma': 0.16; 'comma,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'loops': 0.16; 'need,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simple.': 0.16; 'skip:/ 70': 0.16; 'sqlalchemy': 0.16; 'subject:allow': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'integer': 0.18; 'language': 0.19; '>>>': 0.20; 'changes': 0.20; 'to:name:python-list@python.org': 0.20; 'parameter': 0.22; 'bit': 0.23; 'errors': 0.23; 'this:': 0.23; 'tried': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'linux': 0.26; 'chris': 0.26; 'error': 0.27; 'equivalent': 0.27; 'message-id:@mail.gmail.com': 0.27; 'said,': 0.27; 'tend': 0.27; 'function': 0.28; 'skip:( 20': 0.28; '"no': 0.29; 'there.': 0.30; "i'm": 0.30; 'putting': 0.30; "i'd": 0.31; 'error.': 0.31; 'probably': 0.31; 'skip:_ 10': 0.32; 'possibly': 0.32; 'statement': 0.32; 'maybe': 0.33; 'class': 0.33; 'problem': 0.33; 'common': 0.33; 'surprised': 0.33; 'case,': 0.34; 'list': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'could': 0.35; 'clear': 0.35; 'fail': 0.35; 'happened': 0.35; 'but': 0.36; 'too': 0.36; 'needed': 0.36; 'there': 0.36; '(and': 0.36; 'depends': 0.36; "wasn't": 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'display': 0.37; 'wanted': 0.37; 'version': 0.38; 'anything': 0.38; 'mean': 0.38; 'end': 0.39; 'enough': 0.39; 'easily': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'relationship': 0.61; "you'll": 0.61; 'spot': 0.63; 'more': 0.63; 'great': 0.63; 'pin': 0.66; 'here': 0.66; 'situation': 0.67; 'jul': 0.72; 'incredibly': 0.76; 'protect': 0.76; 'demand': 0.79; 'calls,': 0.84; 'chrisa': 0.84; 'examples.': 0.84; "it'd": 0.84; 'pip': 0.84; 'too:': 0.84; 'worried': 0.84; 'habit': 0.91; 'misleading': 0.91; 'sulla': 0.91
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; bh=+lF2r/BtpsDDVzCPSUdCV8aBjLSbm6JjXq5NEnzrHRg=; b=X0H1+B6D3g4YMJcyBPA/uiC17nH7vdWwBv2Q6eBYNPB7rXR55Z0X09ZoMfkjLPFmNU ypDMJiCRR+F5ipe0xnZ7y12h+67b25yWeKw3t1wNalD2i3bpJ3NbQv4ObDOmdMvZeQ5x J+ch+7RrtuoaK18WlA0iPsw31uP25pOQ/DXGilX/7Fx1vjWom30MaaLa4/FR+19JUyVX oU7V8NIUGFlru3k1KvuGJsTtgsrv81E3O+eLM5FRGm8L+IoOEk+8EXyrrJX+rm1eVNcg phCp+p1p0SqFb+SmQcQvtrnBSWV7fuFl1RxQRQKQN6Yu6pqi85oXXmzEdZC6mMEQ1ToO 41Sw==
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:from:date :message-id:subject:to; bh=+lF2r/BtpsDDVzCPSUdCV8aBjLSbm6JjXq5NEnzrHRg=; b=hVOQAUlmyRU93HWcfGC5ApZPwFyYkJADQVLPuztsyz+mgXKzpDBCmr+6S08RonEcl9 IoA9nzdle9fK3ImHYNEOgLJYMZD8DReDuOtbPPYfxPLeqXTPy0S5MbVIujNp/yxrlO8h sjTq1BSsw0B9yEjvsCP2Ig5OvUzX2ti+d0JZpQQnL8J5LGV/pb2ItgenoHe1LCyP9A72 OU99E5TRoR3pKZ+uFJn3WpcDUXgbM7Rz3ft3b7XfI3R/IjFeYpSXSOMKoR5P5Px94Ha6 gYO3FhU/A8ZWlW3hrdOLC1HRSE9/9T4397BPqf2JedFKvLwlpsjgsRguK6PTQIVrTzEx MXwg==
X-Gm-Message-State AEkoousvdz7AoQW4Eot10QMYEtxpdfx/HaiEtNUmD0B2zO1/Os/UgJYSzTTEDC+7okTxilB6rFcqkBBzQvgJ7w==
X-Received by 10.194.114.9 with SMTP id jc9mr10727550wjb.30.1469367516935; Sun, 24 Jul 2016 06:38:36 -0700 (PDT)
In-Reply-To <CABbU2U-JmQgG-45oA4AOnCs85cZhcLoiWagjME4CZjZdhT9-rw@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
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>
X-Mailman-Original-Message-ID <CAPTjJmqyzpVLDmRUrTbBSmfeW4Jr+Jeh=vM1eo08d+bgTbKZHA@mail.gmail.com>
X-Mailman-Original-References <b80ae0ca-d8b2-4430-96a1-7a6768b177ef@googlegroups.com> <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <mailman.77.1469276992.22221.python-list@python.org> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <mailman.79.1469282085.22221.python-list@python.org> <nmvtlu$oqu$1@dont-email.me> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <nn25m4$4d1$1@dont-email.me> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmoG=qVAVEXK0pzbwYp13HBC-ROf2MbkF_3E2XbapihXvQ@mail.gmail.com> <CABbU2U-JmQgG-45oA4AOnCs85cZhcLoiWagjME4CZjZdhT9-rw@mail.gmail.com>
Xref csiph.com comp.lang.python:111808

Show key headers only | View raw


On Sun, Jul 24, 2016 at 11:11 PM, Marco Sulla
<mail.python.org@marco.sulla.e4ward.com> wrote:
> On 24 July 2016 at 14:48, Chris Angelico <rosuav@gmail.com> wrote:
>> Maybe the people who are most worried about this can enact a
>> simple rule: no dedent without a blank line? That can easily be
>> verified by a script, and it'd protect against most of the given
>> examples. It's not too much effort (after any reasonable-sized block
>> you'll probably have a blank anyway, so it's only the tiniest of loops
>> that would be affected). And no language changes are needed :)
>
> I'm incredibly in favor of such a modification, but maybe this is work
> for a linter.

Sorry if I wasn't clear, but I definitely did mean for this to be the
work of a linter ("verified by a script", and "no language changes are
needed").

> Honestly, I find the "pass" statement very clear and simple. There's
> more misleading problems in Python syntax, like this:
>
> someFunction(
>     "param1"
>     "param2"  # comma missed, there will be only one parameter "param1param2"
> )

That can also be caught by a linter; it can also be caught by a
standard habit of ALWAYS putting trailing commas on anything that gets
wrapped. It's not so common with function calls, but the equivalent
situation with list display is:

colors = [
    "red",
    "green"
    "blue",
    "yellow",
    "cyan",
    "magenta"
]

Same problem with the missed comma, but it's also common enough to put
one after "magenta" too, and it's a great protection. Again, you could
have your linter demand this, if you wanted to (and put the linter
into your pre-commit hook or equivalent), or you could just eyeball it
("nothing at the end of the line? really?").

> and this one too:
>
> class Parent(Base):
>     __tablename__ = 'parent'
>     id = Column(Integer, primary_key=True)
>     children = relationship("Child"),  # comma inserted by error.
> children will be a tuple and SQLAlchemy will fail with misleading
> errors

Hmm, that's a bit harder to pin down, but since *none* of the members
will have commas here, I'd be surprised to spot one there. Though part
of the problem here is that SQLAlchemy is such a gigantic package that
its error messages tend to be a bit confusing. But that said, here's
what happened when I tried it:

rosuav@sikorsky:~$ python3
Python 3.6.0a3+ (default:bff31254a0f0, Jul 17 2016, 17:39:49)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sqlalchemy.ext.declarative import declarative_base
>>> from sqlalchemy import Column, Integer
>>> from sqlalchemy.orm import relationship
>>> Base = declarative_base()
>>> class Parent(Base):
...     __tablename__ = 'parent'
...     id = Column(Integer, primary_key=True)
...     children = relationship("Child"),
...
/usr/local/lib/python3.6/site-packages/sqlalchemy/ext/declarative/base.py:297:
SAWarning: Ignoring declarative-like tuple value of attribute
children: possibly a copy-and-paste error with a comma left at the end
of the line?
  "left at the end of the line?" % k)
>>> Parent
<class '__main__.Parent'>
>>>
rosuav@sikorsky:~$ python3 -m pip freeze|grep -i alchemy
SQLAlchemy==1.0.11

Maybe enabling warnings is all you need, or maybe it depends on the
version of SQLAlchemy. In any case, nice spot, declarative-base!

ChrisA

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


Thread

#111760 
  #111767 
  #111778 
    #111779 
    #111782 
      #111783 
        #111784 
        #111789 
          #111792 
          #112008 
          #112012 
            #112014 
              #112015 
              #112016 
                #112018 
                #112020 
                #112025 
                #112041 
                #112207 
                #112023 
              #112022 
          #112017 
          #112028 
            #112029 
              #112033 
              #112040 
                #112048 
                #112052 
                #112053 
                #112055 
                #112057 
                #112058 
                #112060 
                #112063 
                #112077 
                #112062 
                #112064 
                #112065 
                #112059 
                #112061 
                #112076 
                #112075 
                #112083 
                #112086 
                #112094 
                #112096 
                #112104 
                #112108 
                #112111 
                #112114 
                #112120 
                #112125 
                #112123 
                #112128 
                #112129 
                #112131 
                #112136 
                #112142 
                #112130 
                #112146 
                #112149 
                #112088 
                #112090 
                #112092 
                #112093 
                #112105 
                #112107 
                #112113 
                #112117 
                #112124 
                #112126 
                #112127 
                #112118 
                #112122 
                #112116 
                #112121 
                #112099 
                #112213 
                #112217 
                #112265 
                #112273 
                #112275 
                #112278 
                #112279 
                #112283 
                #112284 
                #112281 
                #112306 
                #112089 
                #112066 
                #112067 
                #112069 
                #112080 
                #112087 
                #112098 
                #112106 
                #112115 
                #112133 
                #112139 
                #112144 
                #112156 
                #112158 
                #112160 
                #112161 
                #112164 
                #112165 
                #112171 
                #112163 
                #112162 
                #112150 
                #112214 
                #112228 
                #112237 
                #112241 
                #112244 
                #112262 
                #112270 
                #112286 
                #112317 
                #112320 
                #112321 
                #112322 
                #112341 
                #112344 
                #112246 
                #112251 
                #112253 
                #112254 
                #112255 
                #112257 
                #112152 
                #112110 
                #112119 
                #112071 
                #112081 
                #112082 
                #112109 
                #112072 
                #112078 
                #112091 
                #112095 
                #112138 
                #112140 
                #112291 
                #112141 
                #112143 
                #112180 
                #112184 
                #112186 
                #112193 
                #112189 
                #112192 
                #112145 
                #112148 
                #112151 
                #112153 
                #112154 
                #112155 
                #112157 
                #112159 
                #112172 
                #112176 
                #112179 
                #112177 
                #112178 
                #112195 
                #112219 
                #112234 
                #112240 
                #112243 
                #112247 
                #112249 
                #112250 
                #112239 
                #112248 
                #112269 
                #112272 
                #112276 
                #112282 
                #112285 
                #112288 
                #112293 
                #112303 
                #112287 
                #112289 
                #112299 
                #112302 
                #112304 
                #112305 
                #112308 
                #112309 
                #112312 
                #112310 
                #112311 
                #112173 
                #112190 
                #112191 
                #112194 
        #111991 
          #111993 
      #111785 
        #111799 
          #111813 
      #111786 
        #111787 
          #111788 
            #111790 
              #111794 
                #111800 
                #111801 
                #111802 
                #111806 
                #111807 
                #111809 
                #111811 
                #111844 
                #111847 
                #111848 
                #111866 
                #111867 
                #111868 
                #111869 
                #111878 
                #111851 
                #111852 
                #111853 
                #111854 
                #111855 
                #111859 
                #111856 
                #111817 
                #111803 
                #111804 
                #111805 
                #111808 
                #111810 
                #111812 
                #111814 
                #111816 
                #111818 
                #111819 
                #111821 
                #111834 
                #111838 
                #111840 
                #111846 
                #111860 
                #111881 
                #111883 
                #111884 
                #111887 
                #111849 
                #111861 
                #111882 
                #111864 
                #111870 
                #111845 
                #111894 

csiph-web