[pypy-svn] r32558 - pypy/dist/pypy/annotation
arigo at codespeak.net
arigo at codespeak.net
Thu Sep 21 11:34:50 CEST 2006
Author: arigo
Date: Thu Sep 21 11:34:49 2006
New Revision: 32558
Modified:
pypy/dist/pypy/annotation/pairtype.py
Log:
Added docstring.
Modified: pypy/dist/pypy/annotation/pairtype.py
==============================================================================
--- pypy/dist/pypy/annotation/pairtype.py (original)
+++ pypy/dist/pypy/annotation/pairtype.py Thu Sep 21 11:34:49 2006
@@ -1,5 +1,30 @@
"""
-XXX A docstring should go here.
+Two magic tricks for classes:
+
+ class X:
+ __metaclass__ = extendabletype
+ ...
+
+ # in some other file...
+ class __extend__(X):
+ ... # and here you can add new methods and class attributes to X
+
+Mostly useful together with the second trick, which lets you build
+methods whose 'self' is a pair of objects instead of just one:
+
+ class __extend__(pairtype(X, Y)):
+ attribute = 42
+ def method((x, y), other, arguments):
+ ...
+
+ pair(x, y).attribute
+ pair(x, y).method(other, arguments)
+
+This finds methods and class attributes based on the actual
+class of both objects that go into the pair(), with the usual
+rules of method/attribute overriding in (pairs of) subclasses.
+
+For more information, see test_pairtype.
"""
class extendabletype(type):
More information about the Pypy-commit
mailing list