[Python-ideas] Extend module objects to support properties

Chris Angelico rosuav at gmail.com
Thu Jan 31 23:00:14 CET 2013


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?

ChrisA



More information about the Python-ideas mailing list