list and implicit continuation may cause bugs in Python programs

François Pinard pinard at iro.umontreal.ca
Thu Jul 12 11:13:47 EDT 2001


[Andreas Jung]

> From: "Roman Suzi" <rnd at onego.ru>
> > Do not forget commas:
> >
> > list =[ "update", "y", "m", "d", "y1", "m1", "d1", "event", "url",
> >          "preview" ]
> >
> > list =[ "update", "y", "m", "d", "y1", "m1", "d1", "event", "url"
> >          "preview" ]
> >
> > Or Python will silently make:
> > ['update', 'y', 'm', 'd', 'y1', 'm1', 'd1', 'event', 'urlpreview']
> >
> > Does PyChecker check for these kind of things?

> For what reason should it check ?  Both is valid Python code.  In the
> second case 'url' and 'preview' are concatenated.  This is dedicated
> behaviour.

It should check because this is poor writing style to have concatenation
of strings written with such a vertical alignment.  "url" and "previews"
have no kind of logical vertical alignment, and a good checker should
consider this as suspicious.

> Also the following is correct Python code:

> print "url" "preview"
> print "url","preview"

> So there is no way to determine the programmers intention at this point.

This time, we have a comma not followed by a space, which is dubious style.
My ideal checker would tell me if do such stylistic mistakes. :-)

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Python-list mailing list