power TypeErrors

Tim Peters tim.one at comcast.net
Tue Nov 5 16:35:14 EST 2002


[anton wilson]
> I'm trying to understand the possible type errors for **
>
> The language reference states that
>
>
> The power operator has the same semantics as the built-in pow() function,
> when called with two arguments: it yields its left argument raised to the
> power of its right argument. The numeric arguments are first
> converted to a
> common type. The result type is that of the arguments after
> coercion; if the
> result is not expressible in that type (as in raising an integer to a
> negative power, or a negative floating point number to a broken power), a
> TypeError exception is raised.

The docs are out of date here.  I opened a bug report:

<http://sf.net/tracker/index.php?func=detail&aid=634069&group_id=5470&atid=1
05470>


> I'm running code such as:
>
> 1 ** -2

int to negative int returns a float now.

> -1.2 ** 0.5

That doesn't do what you think, but (-1.2) ** 0.5 would (and raises
ValueError, not TypeError).

> and there is no type error.
>
> How do I generate a type error?

For example, try

    3 ** 'a'





More information about the Python-list mailing list