Python’s Special Methods

@method(object,Rational)def__add__(a,b):"""Add an object and a rational number.
`a` is converted to a `Rational` and then both are added."""returnRational(a)+b@method(Rational,object)def__add__(a,b):"""Add a rational number and an object.
`b` is converted to a `Rational` and then both are added."""returna+Rational(b)

gf.Object also has a more Smalltalk means of overwriting
object.__str__ and object.__repr__ using a file like object.
Again the rational example is instructive about its usage.

@method(Rational,Writer)def__out__(rational,writer):"""Write a nice representation of the rational.
Denominators that equal 1 are not printed."""writer("%d",rational.numerator)ifrational.denominator!=1:writer(" / %d",rational.denominator)@method(Rational,Writer)def__spy__(rational,writer):"""Write a debug representation of the rational."""writer("%s(",rational.__class__.__name__)ifrational.numerator!=0:writer("%r",rational.numerator)ifrational.denominator!=1:writer(", %r",rational.denominator)writer(")")

Changes

A short sketch of the changes done in each release.

Release 0.1.4

The following was fixed in Release 0.1.4:

Fixed an issue with variadic methods. Sometimes definitions
of variadic methods added after the method was already called
where not added.

Specified and implemented a precedence rule for overlapping
variadic methods of generic functions.

Improved generated documentation for variadic methods.

Fixed the markup of some notes in the documentation.

Release 0.1.3

The following was changed in Release 0.1.3:

Added variadic methods, e.g. multi-methods with a
variable number of arguments.

Improved the long description text a bit
and fixed bug in its markup.

Fixed invalid references in the long description.

Release 0.1.2

The following was changed in Release 0.1.2:

Added a generic functions for gf.Object.__call__.

Added a gf.go.FinalizingMixin.

gf.generic now also accepts a type.

Improved the exception information for ambiguous calls.

Fixed some documentation glitches.

Release 0.1.1

This was the initial release.

Acknowledgements

Guido van Rossum created the core of this package. I just renamed some things
and added some convenience stuff. Thank you Guido!