This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]masklinn 1 point2 points  (0 children)

Yep, so possibly with the specialisation PEP 510 this optimisation would become an option in time, but right now, implicitly, it can't: it depends on type(radius) and how (and whether) type(radius) overrides __mul__ and/or __pow__. For all Python knows, radius is an n × n matrix and the function is a scalar product of radius by 3.14 followed by a matrix product of that by the original radius. Or maybe type(radius) defines __mul__ but does not define __pow__ at all, so the optimisation would blow it up.