PEP0238 lament

Tim Hochberg tim.hochberg at ieee.org
Mon Jul 23 15:01:56 EDT 2001


"Steve Horne" <sh at ttsoftware.co.uk> wrote:
[SNIP]
> Obviously - if complex numbers are considered valid inputs then that
> function is wrong. What you are saying, though, is that integer inputs
> are invalid and should be coerced to floats. That *CAN* be tested for
> and done now without ANY changes to the language. If it's too awkward,
> then what is needed is a simpler way to do achieve that. I have
> suggested several ways to achieve this kind of result, and one that
> achieves EXACTLY that. NONE of those suggestions would break old code.
> NOBODY has replied in any way to any of them though.

In my case at least they've been lost in the sound and fury. For a while I
tried to follow all of the posts in this thread, but they were quite
prolific and half were wrong (arguing about things not in the PEP), half
were hysterical (I'm afraid that I'm not all that concerned if those evil
Perl guys really laugh at us) and half were talking about things that have
been discussed to death. Oh yeah, I forgot the half that discussed how only
the feeble of mind could possibly want something like this. That left very
few posts that had any interesting arguments about why this was or was not a
bad idea. So now I skim for interesting posts, but it's easy to miss stuff.

>how about...
>
>def simple_func(x, y):
>  $coerce x, y : $integer -> $float
>  return y / x**2

Wouldn't help me much since I'm also concerned about arrays.  I don't like
the syntax much either. At the end of the day, it doesn't seem to be much
better than doing:

def simple_func(x, y):
   if isinstance(y, types.IntType):
      y = float(y)
   if isinstance(y, Numeric.ArrayType) and y.typecode() in ('i','l'):
      y = y.astype('d')
   return y / x**2

Now I'm not sure that it deserves to be called simple_func anymore.

It seems you would be better served proposing:

def simple_func(x, y):
   directive use_float_division
   return y / x**2

Maybe you already have and it was lost in the noise? However, I suspect that
your more likely to get more mileage out of pushing for the ability to use:

directive old_style_division

at the top of a file to force the use of the current division style for that
file. That depends on PEP 244 getting accepted of course.

>Notice I even used my simple prefix-to-indicate-keywords idea to avoid
>breaking any 'coerce' identifiers anyone might be using. I admit the
>syntax hasn't been thought through - I'll bet there's a dozen holes
>picked in it before tomorrow morning - but the principle is simple,
>clear, effective and non-destructive.

I'm afraid I disagree with 1-3 here. Four might be true, but since I don't
think helps the problems for which PEP 238 was proposed for, this is no
better (worse since it adds kruft) than doing nothing.

-tim








More information about the Python-list mailing list