On 01/30/2013 04:45 PM, Steven D'Aprano wrote:
On 31/01/13 03:42, Larry Hastings wrote:
Also, I'm not sure there are any existing globals that we'd want to convert into properties.
How about this?
math.pi = 3
which really should give an exception.
(I'm sure there are many others.)
Well, hmm. The thing is, properties--at least the existing implementation with classes--doesn't mesh well with direct access via the dict. So, right now,
If we change math.pi to be a property it wouldn't be in the dict anymore. So that has the possibility of breaking code.
We could ameliorate it with
math.__dict__['pi'] = math.pi
But if the user assigns a different value to math.__dict__['pi'], math.pi will diverge, which again could break code. (Who might try to assign a different value to pi? The 1897 House Of Representatives of Indiana for one!)
More generally, it's often useful to monkeypatch "constants" at runtime, for testing purposes (and for less justifiable purposes). Why prevent that? I cite the Consenting Adults rule.