[Python-ideas] Documenting Python warts on Stack Overflow

Chris Angelico rosuav at gmail.com
Wed Jan 2 01:11:29 CET 2013


On Wed, Jan 2, 2013 at 10:57 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> You can't break a for loop between its assignment and iterable for the
> same reason you can't break any other statement at an arbitrary place.
> That's not how Python does things: statements must be on a single logical
> line.
>
> This is not a wart any more than the inability to write:
>
> y =
>  x +
>   1;
>
> is a wart. Maybe you're used to being able to do that in some (but not
> all) semi-colon languages)
>
> To some degree warts are in the eye of the beholder, but failure of
> Python to be "just like language Foo" is not a wart.

Of course. I'm just trying to find examples that have actually come up
on python-list, rather than contriving my own. As per my definition of
wart as given above, these are NOT things that need to be fixed - just
things that need to be understood.

Rule: One Python statement must be on one line. (This is the bit where
Python differs from, say, C.)

Modifying rule: Python statements can be broken across multiple lines,
given certain conditions.

Wart: There are other conditions that, though they seem superficially
similar to the legal ones, don't make for valid split points. Even
though a human might say that it's obvious and unambiguous that the
statement continues, the rules don't allow it.

>> eg int/int->float but sqrt(float) !->  complex).
>
> Are you talking about math.sqrt or cmath.sqrt or some other sqrt?
>
> In general, Python 3 now extends float to complex under regular arithmetic:
>
> py> (-100.0)**0.5
> (6.123031769111886e-16+10j)
>
>
> math.sqrt(-100.0) on the other hand continues to raise, because the math
> module is by design limited to producing real-values. cmath.sqrt(-100.0)
> continues to give a complex result, again by design.

Hmm, I was doing that one from memory. Since the ** operator happily
returns complex, it was probably math.sqrt that was in question. I
withdraw this one; the operators are consistent amongst themselves,
all will extend to the "next type up" if necessary. (Or at least, this
pair do. There might be a wart elsewhere, but this ain't it.)

ChrisA



More information about the Python-ideas mailing list