Bizarre method keyword-arg bug.
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Mon Aug 18 10:27:30 EDT 2008
On Mon, 18 Aug 2008 03:20:11 -0700, Jasper wrote:
> It doesn't help that the solution to get the expected behavior involves
> adding boiler-plate code all over.
Expected by who?
Please don't assume that everyone has had their intuition shaped by
exposure to the same languages yours has been shaped by. What surprises
you is obvious to me.
In a previous post, you asserted that the alternative behaviour (having
default arguments re-evaluated each time the function is called) can't
possibly be surprising. You wrote:
"And no, the alternative /does not/ have an equivalent set of surprises
-- it's not like Python is unique in having default arguments."
That's simply not true. I would find this behaviour very surprising, and
I bet you would too:
>>> x = "parrot"
>>> def foo(obj=x):
... print obj
...
>>> foo() # this is the current behaviour
parrot
>>> x = "shrubbery"
>>> foo() # but this is not
shrubbery
>>> del x
>>> foo() # nor is this
Traceback (most recent call last):
...
NameError: name 'x' is not defined
--
Steven
More information about the Python-list
mailing list