This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author albert.neu
Recipients albert.neu
Date 2011-01-18.10:54:35
SpamBayes Score 3.3424687e-05
Marked as misclassified No
Message-id <1295348078.83.0.563667045333.issue10930@psf.upfronthosting.co.za>
In-reply-to
Content
Hello!

Is it intentional, that the default argument is ALWAYS evaluated, even if it is not needed???

Is it not a bug, that this method has no short-circuit eval (http://en.wikipedia.org/wiki/Short-circuit_evaluation)
??

Example1:
=========
infinite = 1e100

one_div_by = {0.0 : infinite}

def func(n):
    return one_div_by.setdefault(float(n), 1/float(n))

for i in [1, 2, 3, 4]:
    print i, func(i)
print one_div_by
# works!!

for i in [0, 1, 2, 3, 4]:     # added 0 -> FAIL!
    print i, func(i)
print one_div_by
# fail!!



Example2:
=========
fib_d = {0 : 0, 1 : 1}

def fibonacci(n):
    return fib_d.setdefault(n, fibonacci(n-1) + fibonacci(n-2))

for i in range(10):
    print i, fibonacci(i)
print fib_d
History
Date User Action Args
2011-01-18 10:54:38albert.neusetrecipients: + albert.neu
2011-01-18 10:54:38albert.neusetmessageid: <1295348078.83.0.563667045333.issue10930@psf.upfronthosting.co.za>
2011-01-18 10:54:36albert.neulinkissue10930 messages
2011-01-18 10:54:35albert.neucreate