|
|
|
|
|
by klyrs
805 days ago
|
|
> # Are these two lines actually faster than the
# interpreter creating defaults at call time?
You're proposing that the interpreter add a check for every default parameter in every function signature; that it should optionally fire off arbitrary code for each and every one. And when you consider that high-performance Python involves writing C extensions, your proposal would be to move that check out of the compiled code and into the slow interpreted space is, yes, a major performance hit. |
|
No, that's not what I'm proposing. Why would it check anything? Just evaluate the given default expression at call time. If you don't want the overhead of an expression, don't put a default.
You can also do defaults like:
...if you want the other behavior. This does add a variable lookup (oh no!).