[Python-ideas] Extend module objects to support properties

Steven D'Aprano steve at pearwood.info
Fri Feb 1 00:26:33 CET 2013


On 01/02/13 09:00, Chris Angelico wrote:
> On Thu, Jan 31, 2013 at 12:53 PM, Larry Hastings<larry at hastings.org>  wrote:
>> 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.
>
> I've never actually been in the situation of doing it, but wouldn't it
> be reasonable to switch out math.pi to be (say) a decimal.Decimal
> rather than a float?


To what purpose? Monkey-patching math.pi doesn't affect any of the other math
functions. All it will do is break Python code that uses math.pi and expects
it to be a float.



-- 
Steven



More information about the Python-ideas mailing list