[Python-ideas] Add additional special method lookups to math module

Jim Jewett jimjjewett at gmail.com
Wed Nov 9 20:43:41 CET 2011


I like the idea, but there is a question of namespace size,
particularly if there may be other meanings for some of the names.

I would therefore prefer __math_sin__, __math_arctan__, etc.  (Does it
need to be even more specific than math?)

-jJ

On 11/9/11, Case Van Horsen <casevh at gmail.com> wrote:
> Currently the functions round(), math.ceil(), math.floor(), and
> math.trunc() all check for the existence of a special method
> (__round__, __ceil__, __floor__, and __trunc__). Would it be possible
> to enhance the math and cmath modules to check for the existence of a
> special method for (almost) functions? For example, math.sin(obj)
> would first check for obj.__sin__.
>
> Rationale
>
> I'm in the final stages of adding support for the MPFR
> (multiple-precision floating point) and MPC (multiple-precision
> complex) libraries to the next-generation of gmpy, currently known as
> gmpy2. If the special method checks are added to the math and cmath
> modules, then the new mpfr() and mpc() types can easily substitute for
> the existing float/complex types in code that uses the math or cmath
> module.
>
> Thoughts?
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



More information about the Python-ideas mailing list