Re: [Python-ideas] fixing mutable default argument values

Other non-python stuff is taking my time, but I'll reply to this anyway. Better late than never (in this case). On Thu, 01 Feb 2007 16:19:00 +0100, Lucio Torre <lucio.torre@gmail.com> wrote:
That statement I can agree with, but it isn't really applicable here. The applicable statement reads: "Maybe it's better to annoy newbies that didn't read the python FAQ than python 2.x programmers who don't know anything about 3.0 and assume it's just another new version of python." And I don't agree with that one. :)
Then don't make the default depend on something you're going to change. Well, what this is really about is about closure vars changing when the outer scope changes them instead of the value of the closure vars being captured by the new lexical scope. This has been proposed before (to change this behaviour on closure variables in general) and rejected. (though I am in favour of it) Python is a late binding language in just about everything, and that is considered to be a good thing. The point you're making is exactly the early-vs-late binding discussion.
I'm not really sure if you can either. Anyway, the only cases I can think of when this makes sense is when there's a bug in '*' and you want to patch it, or if you're overloading '*' to work with other values, without changing the meaning for ints. In both of these cases it would be a good resp. neutral thing to late-bind '*'
On the other hand, i think that learning about compile time and run time is a great thing and should be encouraged.
Yup. But let's not fill the language with gotchas for the newbies to find and learn from :)
You'll get to like the new way :)
Please note that I'm not in favour of any of the possible new syntaxes, I am only in favour of changing the semantics without new syntax (cf the pre-pep). Since many newbie python programmers run into this, it seems that it is easier to learn that python evaluates the default expressions at calltime, because that is what the rest of python makes the newbies expect when they first try it. So for newbies, there would actually be less learning involved. You will have to remember this change when you start using py 3.0, but this won't be the only thing to remember. And there are still several other ways to make some python code evaluate the expression at deftime.
As the body is part of the def statement, the def is already doing exactly that (being both compile/def time and run/call time). Consider the ...'s to be part of the function body in the new semantics. Instead of part of the code in a def being executed at deftime and part at calltime, everything is just run at calltime. There are some pretty large warnings in the docs about this distinction currently, they can be taken out.
- Jan

"Jan Kanis" <jan.kanis@phil.uu.nl> wrote:
No. You cannot change the meaning of any operation on built-in types. You can subclass the built-in types and add your own implementation of a __magic__ method, or you can prefix your other operations with some other type that does something else (X*640*480), but you can't monkey-patch int to have a new __mul__ operation. In Python, the functions that get called when an operation is called on an object defined in C are "bound early", that is, they cannot be changed during runtime (unless you write some C code to monkey about with Python internals - which is a *bad* idea). The functions that get called when an operation is called on an object defined in Python may be "bound early", as is the case with properties and other descriptors on new-style classes, but classic classes, generally speaking, can be manipulated at will (though you sometimes need to be careful when adding or changing new instance, class, and static methods).
Yup. But let's not fill the language with gotchas for the newbies to find and learn from :)
No one is advocating for *adding* gotchas to the language; this thread is more or less a question of whether this particular default argument gotcha is worth changing the language.
You'll get to like the new way :)
And you will get used to and like the old way. - Josiah

"Jan Kanis" <jan.kanis@phil.uu.nl> wrote:
No. You cannot change the meaning of any operation on built-in types. You can subclass the built-in types and add your own implementation of a __magic__ method, or you can prefix your other operations with some other type that does something else (X*640*480), but you can't monkey-patch int to have a new __mul__ operation. In Python, the functions that get called when an operation is called on an object defined in C are "bound early", that is, they cannot be changed during runtime (unless you write some C code to monkey about with Python internals - which is a *bad* idea). The functions that get called when an operation is called on an object defined in Python may be "bound early", as is the case with properties and other descriptors on new-style classes, but classic classes, generally speaking, can be manipulated at will (though you sometimes need to be careful when adding or changing new instance, class, and static methods).
Yup. But let's not fill the language with gotchas for the newbies to find and learn from :)
No one is advocating for *adding* gotchas to the language; this thread is more or less a question of whether this particular default argument gotcha is worth changing the language.
You'll get to like the new way :)
And you will get used to and like the old way. - Josiah
participants (2)
-
Jan Kanis
-
Josiah Carlson