Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26956
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: in-place exponentiation incongruities |
| Date | 2012-08-12 17:53 -0400 |
| References | <a0d2c349-6792-4c80-8aa5-af13dbaac039@googlegroups.com> <502730da$0$29983$c3e8da3$5496439d@news.astraweb.com> <5bc4e58c-c587-46c3-93cc-95dea97d89e8@googlegroups.com> <50278d6b$0$29978$c3e8da3$5496439d@news.astraweb.com> <3118027d-0c13-425e-a874-4593b608cf45@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3212.1344808442.4697.python-list@python.org> (permalink) |
On 8/12/2012 7:55 AM, Giacomo Alzetta wrote: > What I mean is: when you implement a new type as a C extension you > have to provide special methods through the NumberMethods struct. In > this struct both the power and in-place power operations have three > arguments. I am not really sure why the latter is true. Probably 'consistency' at the special method level, with __pow__. As Steven points out, it is not needed to implement normal Python code. This is one area of Python where the design is a bit messy. I believe the very existence of __ipow__ is a matter of consistency than of known use cases. Guido was not sure which __ixxx__ would ever be needed (for mutable objects), so he just put them all in. At the Python level, both __pow__ and __ipow__ are also documented in the manual as having an optional, third, modulo parameter. __rpow__ is defined as binary, but that is a mistake >>> int.__rpow__(3, 5, 4) 1 > Now, suppose I implement the three argument variant of the > in-place power in a class. Are you actually planning to do this, or is this purely theoretical? > No user would be able to call my C > function with a non-None third argument, Not true. Whether the function is coded in Python or C cls.__ipow__(base, exp, mod) # or base.__ipow__(exp, mod) > while he would be able to > call the normal version with the third argument. That can also be done directly >>> int.__pow__(5, 3, 4) 1 -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
in-place exponentiation incongruities Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-11 09:54 -0700
Re: in-place exponentiation incongruities Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-12 04:28 +0000
Re: in-place exponentiation incongruities Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-12 00:14 -0700
Re: in-place exponentiation incongruities Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-12 11:03 +0000
Re: in-place exponentiation incongruities Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-12 04:55 -0700
Re: in-place exponentiation incongruities Terry Reedy <tjreedy@udel.edu> - 2012-08-12 17:53 -0400
Re: in-place exponentiation incongruities Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-14 00:14 -0700
Re: in-place exponentiation incongruities Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-14 00:14 -0700
csiph-web