Incorporate Guido's decision to go for '__iadd__' for the Python class

hooks, and trim the 'open isues': PyNumber_InPlacePower() is now a
trinary function, like PyNumber_Power(), and I'm working on the docs and the
library.
This commit is contained in:
Thomas Wouters 2000-08-23 11:32:01 +00:00
parent 057799b286
commit eed4c74a66
1 changed files with 21 additions and 38 deletions

View File

@ -62,12 +62,12 @@ Proposed semantics
x += y x += y
tries to call x.__add_ab__(y), which is the `in-place' variant of tries to call x.__iadd__(y), which is the `in-place' variant of
__add__. If __add_ab__ is not present, x.__add__(y) is __add__. If __iadd__ is not present, x.__add__(y) is
attempted, and finally y.__radd__(x) if __add__ is missing too. attempted, and finally y.__radd__(x) if __add__ is missing too.
There is no `right-hand-side' variant of __add_ab__, because that There is no `right-hand-side' variant of __iadd__, because that
would require for `y' to know how to in-place modify `x', which is would require for `y' to know how to in-place modify `x', which is
unsafe to say the least. The __add_ab__ hook should behave similar unsafe to say the least. The __add__ hook should behave similar
to __add__, returning the result of the operation (which could be to __add__, returning the result of the operation (which could be
`self') which is to be stored in the variable `x'. `self') which is to be stored in the variable `x'.
@ -139,22 +139,19 @@ New methods
which Python classes can implement to overload the augmented which Python classes can implement to overload the augmented
assignment operations: assignment operations:
__add_ab__ __iadd__
__sub_ab__ __isub__
__mul_ab__ __imul__
__div_ab__ __idiv__
__mod_ab__ __imod__
__pow_ab__ __ipow__
__lshift_ab__ __ilshift__
__rshift_ab__ __irshift__
__and_ab__ __iand__
__xor_ab__ __ixor__
__or_ab__ __ior__
The `__add_ab__' name is one proposed by Guido[1], and stands for The `i' in `__iadd__' stands for `in-place'.
`and becomes'. Other proposed names include `__iadd__',
`__add_in__' and `__inplace_add__'. A firm decision by the BDFL is
probably needed to finalize this issue.
For C extension types, the following struct members are added: For C extension types, the following struct members are added:
@ -260,20 +257,11 @@ Implementation
Open Issues Open Issues
The PyNumber_InPlacePower() function only takes two arguments, not The PyNumber_InPlace API is only a subset of the normal PyNumber
one like PyNumber_Power(). This is because there is no way to do API: only those functions that are required to support the
an inplace three-argument-power trough the augmented assignment augmented assignment syntax are included. If other in-place API
syntax or the power() function. functions are needed, they can be added later.
Possibly a more obvious name for the Python hooks can be found.
`_ab_' is what Guido proposed[1] as a working name, and comes from
an old Algol-68 naming convention.
Documentation needs to be written. The reference manual, the `dis'
section of the library manual, and possibly the tutorial.
The DUP_TOPX bytecode is a conveniency bytecode, and is not The DUP_TOPX bytecode is a conveniency bytecode, and is not
actually necessary. It should be considered whether this bytecode actually necessary. It should be considered whether this bytecode
@ -281,10 +269,6 @@ Open Issues
bytecode at this time. bytecode at this time.
The standard library should be adjusted to provide augmented
assignment hooks, where sensible.
It is not possible to do an inplace operation in the variant of It is not possible to do an inplace operation in the variant of
<builtin type> += <instance object> <builtin type> += <instance object>
@ -303,8 +287,7 @@ Copyright
References References
[1] http://www.python.org/pipermail/python-list/2000-June/059556.html [1] http://www.python.org/pipermail/python-list/2000-June/059556.html
[2] [2] http://sourceforge.net/patch?func=detailpatch&patch_id=100699&group_id=5470
http://sourceforge.net/patch?func=detailpatch&patch_id=100699&group_id=5470
[3] PEP 211, Adding New Linear Algebra Operators, [3] PEP 211, Adding New Linear Algebra Operators,
http://python.sourceforge.net/peps/pep-0211.html http://python.sourceforge.net/peps/pep-0211.html