|
|
|
|
|
by eiopa
3826 days ago
|
|
This kills it for me too. I rely on pypy, and I just can't see myself sacrificing my productivity by using Six. Also, Python 3 neglected to fix one of the most annoying things about the language - default arg value def foo(x=[]):
x.append(1)
print x
foo() # 1
foo() # 1 1
Why is this still busted?? |
|
This is intentional behavior. It's the result of one-time evaluation of default args, which is important for memoization. It's also really useful in combination with late-binding closures. For example, using a lambda as a generator function:
This doesn't work, you'll get all 8's. Instead you need to: Late-binding closures and memoization strategies are pretty core language features; I wouldn't expect them to change (and many python devs would be pretty pissed if they did). Yes, this can be confusing with mutable default objects, but the alternative is to have disparate behavior depending on the mutability of the defaults, which would be an utter catastrophe.http://docs.python-guide.org/en/latest/writing/gotchas/