Application Programming Interface

The generic function package provides means to define generic functions and multi-methods. Additionally classes are provided that enable the user to implement nearly all of Python’s special methods as multi-methods.

Basic Usage

One can define generic functions are generics and multi-methods with Python`s special method support with juts two decorator functions and optionally one decorator method.

Defining Generic Functions

Generic functions must be defined with the generic()-function.

@gf.generic(default_function)

Create a generic function with a default implementation provided by default_function.

Parameters:default_function (callable_object) – The generic’s default implementation.

The generic’s name and docstring are taken from the default_function.

Specialisations for different call signatures can be added with the method() and <generic>.method() decorators.

Note

callable_object can be a function or a type (a new style class).

For example the generic foo()‘s default implemenations just answers the arguments passed as a tuple:

>>> from gf import generic
>>> @generic
... def foo(*arguments):
...     """Answers its arguments."""
...     return arguments

foo() can be called just like an ordinary function.

>>> foo(1, 2, 3)
(1, 2, 3)
gf.generic()

Create an unnamed generic function with no default function and no implementation.

Defining a generic function in this way has the same effect as defining a generic function with a default function that raised a NotImplementedError.

This form is the simplest way to define a generic:

>>> bar = generic()

If this generic function is called a NotImplementedError is raised:

>>> bar("Hello", U"World")
Traceback (most recent call last):
...
NotImplementedError: Generic None has no implementation for type(s): __builtin__.str, __builtin__.unicode

Note

The name is added later when the first multi-method is added with method().

gf.generic(name)

Create a generic function with a name and no default implementation.

Parameters:name (basestring) – The generic’s name assessable with the .__name__ attribute.

If you define bar`in this may the `NotImplementedError() raised will contain the generics name:

>>> bar = generic("bar")
>>> bar("Hello", U"World")
Traceback (most recent call last):
...
NotImplementedError: Generic 'bar' has no implementation for type(s): __builtin__.str, __builtin__.unicode

The docstring however is still None:

>>> print bar.__doc__
None
gf.generic(name, doc)

Create a generic function with a name and a docstring, but no default implementation.

Parameters:
  • name (basestring) – The generic’s name accessible with the .__name__ attribute.
  • doc (basestring) –
    The generic’s docstring accessible with
    the .__doc__ attribute.
    >>> bar = generic("bar", "A silly generic function for demonstration purposes")
    

The generic now also has a docstring:

>>> print bar.__doc__
A silly generic function for demonstration purposes

Adding Multi-Methods

Multi-methods can be added to a generic function with the method()-function or the <generic>.method() method.

@gf.method(*types)(implementation_function)

Add a multi-method for the types given to the generic decorated.

Parameters:
  • types (type) – An optionally empty list of built-in types or new-style classes.
  • implementation_function (FunctionType) – The function implementing the multi-method.

A multi-method specialising the foo() generic for two integers can be added as such:

>>> from gf import method
>>> @method(int, int)
... def foo(i0, i1):
...     return i0 + i1

This makes foo() answer 3 for the following call:

>>> foo(1, 2)
3

Caution

The generic function the multi-method is added to, must be defined in the multi-method’s implementation function’s global name-space.

If this is not the case use the <generic>.method() decorator.

@gf.variadic_method(*types)(implementation_function)

Add a multi-method with a variable number of arguments to the generic decorated.

Parameters:
  • types (type) – An optionally empty list of built-in types or new-style classes.
  • implementation_function (FunctionType) – The function implementing the multi-method.

This does essentially the same as method(), but accepts additional arguments to ones the specified by types. This is done by virtually adding an infinite set of of method defintions with the type object used for the unspecified types.

This decorator can be used to implement functions like this:

@variadic_method(TC)
def varfun1(tc, *arguments):
    return (tc,) + tuple(reversed(arguments))

This function can be called like this:

varfun1(to, "a", "b", "c")

and behaves in this case like being defined as:

@method(TC, object, object, object)
def varfun1(tc, *arguments):
    return (tc,) + tuple(reversed(arguments))

Overlaps of variadic method definitions are always resolved toward the method with more specified types being selected.

This means, that this this function:

@variadic_method(object)
def foo(*arguments):
    return arguments

is always perferred over that function:

@variadic_method()
def foo(*arguments):
    return list(reversed(arguments))

when called like:

foo("Sepp")
<generic>.method(*types)(implementation_function)

Directly define a multi-method for the types given to <generic>.

Parameters:
  • types (type) – An optionally empty list of built-in types or new-style classes.
  • implementation_function (FunctionType) – The function implementing the multi-method.

<generic> needs not to be available in the implementation function’s name-space. Additionally implementation_function can have a different name than the generic. The later leads to defining an alias of the generic function.

For example a multi-method also available as bar can be defined as such:

>>> @foo.method(str)
... def foobar(a_string):
...     return "<%s>" % a_string

With this definition one can either call foo() with a string as follows:

>>> foo("Hi")
'<Hi>'

Or foobar():

>>> foobar("Hi")
'<Hi>'
<generic>.variadic_method(*types)(implementation_function)

Directly define a multi-method with a variable number of arguments for the types given to <generic>.

Parameters:
  • types (type) – An optionally empty list of built-in types or new-style classes.
  • implementation_function (FunctionType) – The function implementing the multi-method.

This decorator is the variadic variant of <generic>.method().

Calling Other Multi-Methods of The Same Generic

As it is sometimes necessary with ordinary single dispatch methods to call methods defined in a base class, it it is sometimes necessary to reuse other implementations of a generic. For this purpose the generic has super()-method.

<generic>.super(*types)(*arguments)
Parameters:
  • types (type) – An optionally empty list of built-in types or new-style classes.
  • arguments – An optionally empty list of Python objects.

Directly retrieve and call the multi-method that implements the generic’s functionally for types.

One can add a (silly) implementation for unicode objects to foo() like this:

>>> @method(unicode)
... def foo(a_string):
...     return foo.super(object)(a_string)

With this definition the generic’s default implementation will be called for unicode-objects:

>>> foo(U"Sepp")
(u'Sepp',)

While calling foo() wthit a string still yields the old result:

>>> foo("Sepp")
'<Sepp>'

Caution

It is not checked whether the arguments passed are actually instances of types. This is consistent with Python’s notion of duck typing.

Advanced Usage

The gf-package also provides an abstract base class called gf.AbstractObject and class called gf.Object.

Both classes map nearly all of Python’s special methods to generic functions.

There is also a Writer-class and some convenience and helper generics like as_string(), spy(), __out__() and __spy__().

The implementation of the aforementioned objects is contained in the gf.go, but the objects are also available for direct import from gf.

The following text is generated from the docstring in gf.go.

gf.go.__abs__(*arguments)

abs(a) – Same as abs(a).

Called by the AbstractObject.__abs__() special method.

gf.go.__add__(*arguments)

add(a, b) – Same as a + b.

Called by the AbstractObject.__add__() special method. Also called by AbstractObject.__radd__() with arguments reversed.

gf.go.__and__(*arguments)

and_(a, b) – Same as a & b.

Called by the AbstractObject.__and__() special method. Also called by AbstractObject.__rand__() with arguments reversed.

gf.go.__concat__(*arguments)

concat(a, b) – Same as a + b, for a and b sequences.

Called by the AbstractObject.__concat__() special method.

gf.go.__contains__(*arguments)

contains(a, b) – Same as b in a (note reversed operands).

Called by the AbstractObject.__contains__() special method.

gf.go.__delitem__(*arguments)

delitem(a, b) – Same as del a[b].

Called by the AbstractObject.__delitem__() special method.

gf.go.__delslice__(*arguments)

delslice(a, b, c) – Same as del a[b:c].

Called by the AbstractObject.__delslice__() special method.

gf.go.__div__(*arguments)

div(a, b) – Same as a / b when __future__.division is not in effect.

Called by the AbstractObject.__div__() special method. Also called by AbstractObject.__rdiv__() with arguments reversed.

gf.go.__divmod__(*arguments)

divmod(x, y) -> (quotient, remainder)

Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.

Called by the AbstractObject.__divmod__() special method. Also called by AbstractObject.__rdivmod__() with arguments reversed.

gf.go.__eq__(*arguments)

eq(a, b) – Same as a==b.

Called by the AbstractObject.__eq__() special method.

gf.go.__floordiv__(*arguments)

floordiv(a, b) – Same as a // b.

Called by the AbstractObject.__floordiv__() special method. Also called by AbstractObject.__rfloordiv__() with arguments reversed.

gf.go.__ge__(*arguments)

ge(a, b) – Same as a>=b.

Called by the AbstractObject.__ge__() special method.

gf.go.__getitem__(*arguments)

getitem(a, b) – Same as a[b].

Called by the AbstractObject.__getitem__() special method.

gf.go.__getslice__(*arguments)

getslice(a, b, c) – Same as a[b:c].

Called by the AbstractObject.__getslice__() special method.

gf.go.__gt__(*arguments)

gt(a, b) – Same as a>b.

Called by the AbstractObject.__gt__() special method.

gf.go.__iadd__(*arguments)

a = iadd(a, b) – Same as a += b.

Called by the AbstractObject.__iadd__() special method.

gf.go.__iand__(*arguments)

a = iand(a, b) – Same as a &= b.

Called by the AbstractObject.__iand__() special method.

gf.go.__iconcat__(*arguments)

a = iconcat(a, b) – Same as a += b, for a and b sequences.

Called by the AbstractObject.__iconcat__() special method.

gf.go.__idiv__(*arguments)

a = idiv(a, b) – Same as a /= b when __future__.division is not in effect.

Called by the AbstractObject.__idiv__() special method.

gf.go.__ifloordiv__(*arguments)

a = ifloordiv(a, b) – Same as a //= b.

Called by the AbstractObject.__ifloordiv__() special method.

gf.go.__ilshift__(*arguments)

a = ilshift(a, b) – Same as a <<= b.

Called by the AbstractObject.__ilshift__() special method.

gf.go.__imod__(*arguments)

a = imod(a, b) – Same as a %= b.

Called by the AbstractObject.__imod__() special method.

gf.go.__imul__(*arguments)

a = imul(a, b) – Same as a *= b.

Called by the AbstractObject.__imul__() special method.

gf.go.__index__(*arguments)

index(a) – Same as a.__index__()

Called by the AbstractObject.__index__() special method.

gf.go.__inv__(*arguments)

inv(a) – Same as ~a.

Called by the AbstractObject.__inv__() special method.

gf.go.__invert__(*arguments)

invert(a) – Same as ~a.

Called by the AbstractObject.__invert__() special method.

gf.go.__ior__(*arguments)

a = ior(a, b) – Same as a |= b.

Called by the AbstractObject.__ior__() special method.

gf.go.__ipow__(*arguments)

a = ipow(a, b) – Same as a **= b.

Called by the AbstractObject.__ipow__() special method.

gf.go.__irepeat__(*arguments)

a = irepeat(a, b) – Same as a *= b, where a is a sequence, and b is an integer.

Called by the AbstractObject.__irepeat__() special method.

gf.go.__irshift__(*arguments)

a = irshift(a, b) – Same as a >>= b.

Called by the AbstractObject.__irshift__() special method.

gf.go.__isub__(*arguments)

a = isub(a, b) – Same as a -= b.

Called by the AbstractObject.__isub__() special method.

gf.go.__iter__(*arguments)

iter(collection) -> iterator iter(callable, sentinel) -> iterator

Get an iterator from an object. In the first form, the argument must supply its own iterator, or be a sequence. In the second form, the callable is called until it returns the sentinel.

Called by the AbstractObject.__iter__() special method.

gf.go.__itruediv__(*arguments)

a = itruediv(a, b) – Same as a /= b when __future__.division is in effect.

Called by the AbstractObject.__itruediv__() special method.

gf.go.__ixor__(*arguments)

a = ixor(a, b) – Same as a ^= b.

Called by the AbstractObject.__ixor__() special method.

gf.go.__le__(*arguments)

le(a, b) – Same as a<=b.

Called by the AbstractObject.__le__() special method.

gf.go.__lshift__(*arguments)

lshift(a, b) – Same as a << b.

Called by the AbstractObject.__lshift__() special method. Also called by AbstractObject.__rlshift__() with arguments reversed.

gf.go.__lt__(*arguments)

lt(a, b) – Same as a<b.

Called by the AbstractObject.__lt__() special method.

gf.go.__mod__(*arguments)

mod(a, b) – Same as a % b.

Called by the AbstractObject.__mod__() special method. Also called by AbstractObject.__rmod__() with arguments reversed.

gf.go.__mul__(*arguments)

mul(a, b) – Same as a * b.

Called by the AbstractObject.__mul__() special method. Also called by AbstractObject.__rmul__() with arguments reversed.

gf.go.__ne__(*arguments)

ne(a, b) – Same as a!=b.

Called by the AbstractObject.__ne__() special method.

gf.go.__neg__(*arguments)

neg(a) – Same as -a.

Called by the AbstractObject.__neg__() special method.

gf.go.__not__(*arguments)

not_(a) – Same as not a.

Called by the AbstractObject.__not__() special method.

gf.go.__or__(*arguments)

or_(a, b) – Same as a | b.

Called by the AbstractObject.__or__() special method. Also called by AbstractObject.__ror__() with arguments reversed.

gf.go.__pos__(*arguments)

pos(a) – Same as +a.

Called by the AbstractObject.__pos__() special method.

gf.go.__pow__(*arguments)

pow(a, b) – Same as a ** b.

Called by the AbstractObject.__pow__() special method. Also called by AbstractObject.__rpow__() with arguments reversed.

gf.go.__repeat__(*arguments)

repeat(a, b) – Return a * b, where a is a sequence, and b is an integer.

Called by the AbstractObject.__repeat__() special method.

gf.go.__rshift__(*arguments)

rshift(a, b) – Same as a >> b.

Called by the AbstractObject.__rshift__() special method. Also called by AbstractObject.__rrshift__() with arguments reversed.

gf.go.__setitem__(*arguments)

setitem(a, b, c) – Same as a[b] = c.

Called by the AbstractObject.__setitem__() special method.

gf.go.__setslice__(*arguments)

setslice(a, b, c, d) – Same as a[b:c] = d.

Called by the AbstractObject.__setslice__() special method.

gf.go.__sub__(*arguments)

sub(a, b) – Same as a - b.

Called by the AbstractObject.__sub__() special method. Also called by AbstractObject.__rsub__() with arguments reversed.

gf.go.__truediv__(*arguments)

truediv(a, b) – Same as a / b when __future__.division is in effect.

Called by the AbstractObject.__truediv__() special method. Also called by AbstractObject.__rtruediv__() with arguments reversed.

gf.go.__xor__(*arguments)

xor(a, b) – Same as a ^ b.

Called by the AbstractObject.__xor__() special method. Also called by AbstractObject.__rxor__() with arguments reversed.

gf.go.__spy__(*arguments)[source]

Create a print string of an object using a Writer.

Note

The function’s name was taken from Prolog’s spy debugging aid.

Multi methods:

gf.go.__spy__(self: object, write: Writer)

Write a just repr() of self.

gf.go.__spy__(self: AbstractObject, write: Writer)

Write a just repr() of self by directly calling object.__repr__().

gf.go.__out__(*arguments)[source]

Create a print string of an object using a Writer.

Multi methods:

gf.go.__out__(self: object, write: Writer)

Write a just str() of self.

gf.go.__out__(self: AbstractObject, write: Writer)

Write a just str() of self by directly calling object.__str__().

gf.go.__init__(*arguments)[source]

__init__() initializes instantiates instances of AbstractObject and it’s subclasses.

It has a multi method for Object. This multi-method does not accept any additional parameters and has no effect. There is no method for AbstractObject, therefore this class can not be instantiated.

Multi methods:

gf.go.__init__(an_object: Object)

Do nothing for Object.

gf.go.__call__(*arguments)

__call__() is called when instances of AbstractObject are called.

gf.go.__del__(*arguments)

__del__() is called when instances of FinalizingMixin are about to be destroyed.

gf.go.__float__(*arguments)

Convert an AbstractObject to a float.

gf.go.__int__(*arguments)

Convert an AbstractObject to an int.

class gf.go.Writer(file_like=None)[source]

A simple wrapper around a file like object.

Writer‘s purpose is to simplify the implementation of the generics __out__() and __spy__().

Writer instances are initialised either with a file_like object or with no arguments. In the later case ab instance of StringIO is used.

Output is done by simply calling the writer with at least one string object. The first argument acts as a %-template for formating the other arguments.

The class is intended to be sub-classed for formatted output.

__call__(text=None, *arguments)[source]

Write text % arguments on the file-like objects.

If no arguments are passed write a newline.

__init__(file_like=None)[source]

Initialize the Write with a file like object.

Parameters:file_like – An optional file-like object.
__weakref__

list of weak references to the object (if defined)

get_text()[source]

Get the text written so far.

Caution

This method is only supported if the file-like object implements StringIO‘s getvalue() method.

class gf.go.AbstractObject(*arguments)[source]

An abstract (mixin) class that maps all the python magic functions to generics.

__abs__(*arguments)

abs(a) – Same as abs(a).

Calls the __abs__()-generic with its arguments.

__add__(*arguments)

add(a, b) – Same as a + b.

Calls the __add__()-generic with its arguments.

__and__(*arguments)

and_(a, b) – Same as a & b.

Calls the __and__()-generic with its arguments.

__call__(*arguments)

Call the __call__() generic function.

__concat__(*arguments)

concat(a, b) – Same as a + b, for a and b sequences.

Calls the __concat__()-generic with its arguments.

__contains__(*arguments)

contains(a, b) – Same as b in a (note reversed operands).

Calls the __contains__()-generic with its arguments.

__delitem__(*arguments)

delitem(a, b) – Same as del a[b].

Calls the __delitem__()-generic with its arguments.

__delslice__(*arguments)

delslice(a, b, c) – Same as del a[b:c].

Calls the __delslice__()-generic with its arguments.

__div__(*arguments)

div(a, b) – Same as a / b when __future__.division is not in effect.

Calls the __div__()-generic with its arguments.

__divmod__(*arguments)

divmod(x, y) -> (quotient, remainder)

Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.

Calls the __divmod__()-generic with its arguments.

__eq__(*arguments)

eq(a, b) – Same as a==b.

Calls the __eq__()-generic with its arguments.

__float__()[source]

Convert the object to a float by calling the __float__() generic.

__floordiv__(*arguments)

floordiv(a, b) – Same as a // b.

Calls the __floordiv__()-generic with its arguments.

__ge__(*arguments)

ge(a, b) – Same as a>=b.

Calls the __ge__()-generic with its arguments.

__getitem__(*arguments)

getitem(a, b) – Same as a[b].

Calls the __getitem__()-generic with its arguments.

__getslice__(*arguments)

getslice(a, b, c) – Same as a[b:c].

Calls the __getslice__()-generic with its arguments.

__gt__(*arguments)

gt(a, b) – Same as a>b.

Calls the __gt__()-generic with its arguments.

__iadd__(*arguments)

a = iadd(a, b) – Same as a += b.

Calls the __iadd__()-generic with its arguments.

__iand__(*arguments)

a = iand(a, b) – Same as a &= b.

Calls the __iand__()-generic with its arguments.

__iconcat__(*arguments)

a = iconcat(a, b) – Same as a += b, for a and b sequences.

Calls the __iconcat__()-generic with its arguments.

__idiv__(*arguments)

a = idiv(a, b) – Same as a /= b when __future__.division is not in effect.

Calls the __idiv__()-generic with its arguments.

__ifloordiv__(*arguments)

a = ifloordiv(a, b) – Same as a //= b.

Calls the __ifloordiv__()-generic with its arguments.

__ilshift__(*arguments)

a = ilshift(a, b) – Same as a <<= b.

Calls the __ilshift__()-generic with its arguments.

__imod__(*arguments)

a = imod(a, b) – Same as a %= b.

Calls the __imod__()-generic with its arguments.

__imul__(*arguments)

a = imul(a, b) – Same as a *= b.

Calls the __imul__()-generic with its arguments.

__index__(*arguments)

index(a) – Same as a.__index__()

Calls the __index__()-generic with its arguments.

__init__(*arguments)[source]

Call the __init__() generic function.

__int__()[source]

Convert the object to an int by calling the __int__() generic.

__inv__(*arguments)

inv(a) – Same as ~a.

Calls the __inv__()-generic with its arguments.

__invert__(*arguments)

invert(a) – Same as ~a.

Calls the __invert__()-generic with its arguments.

__ior__(*arguments)

a = ior(a, b) – Same as a |= b.

Calls the __ior__()-generic with its arguments.

__ipow__(*arguments)

a = ipow(a, b) – Same as a **= b.

Calls the __ipow__()-generic with its arguments.

__irepeat__(*arguments)

a = irepeat(a, b) – Same as a *= b, where a is a sequence, and b is an integer.

Calls the __irepeat__()-generic with its arguments.

__irshift__(*arguments)

a = irshift(a, b) – Same as a >>= b.

Calls the __irshift__()-generic with its arguments.

__isub__(*arguments)

a = isub(a, b) – Same as a -= b.

Calls the __isub__()-generic with its arguments.

__iter__(*arguments)

iter(collection) -> iterator iter(callable, sentinel) -> iterator

Get an iterator from an object. In the first form, the argument must supply its own iterator, or be a sequence. In the second form, the callable is called until it returns the sentinel.

Calls the __iter__()-generic with its arguments.

__itruediv__(*arguments)

a = itruediv(a, b) – Same as a /= b when __future__.division is in effect.

Calls the __itruediv__()-generic with its arguments.

__ixor__(*arguments)

a = ixor(a, b) – Same as a ^= b.

Calls the __ixor__()-generic with its arguments.

__le__(*arguments)

le(a, b) – Same as a<=b.

Calls the __le__()-generic with its arguments.

__lshift__(*arguments)

lshift(a, b) – Same as a << b.

Calls the __lshift__()-generic with its arguments.

__lt__(*arguments)

lt(a, b) – Same as a<b.

Calls the __lt__()-generic with its arguments.

__mod__(*arguments)

mod(a, b) – Same as a % b.

Calls the __mod__()-generic with its arguments.

__mul__(*arguments)

mul(a, b) – Same as a * b.

Calls the __mul__()-generic with its arguments.

__ne__(*arguments)

ne(a, b) – Same as a!=b.

Calls the __ne__()-generic with its arguments.

__neg__(*arguments)

neg(a) – Same as -a.

Calls the __neg__()-generic with its arguments.

__not__(*arguments)

not_(a) – Same as not a.

Calls the __not__()-generic with its arguments.

__or__(*arguments)

or_(a, b) – Same as a | b.

Calls the __or__()-generic with its arguments.

__pos__(*arguments)

pos(a) – Same as +a.

Calls the __pos__()-generic with its arguments.

__pow__(*arguments)

pow(a, b) – Same as a ** b.

Calls the __pow__()-generic with its arguments.

__radd__(argument0, argument1)

add(a, b) – Same as a + b.

Calls the __add__()-generic with its arguments reversed.

__rand__(argument0, argument1)

and_(a, b) – Same as a & b.

Calls the __and__()-generic with its arguments reversed.

__rdiv__(argument0, argument1)

div(a, b) – Same as a / b when __future__.division is not in effect.

Calls the __div__()-generic with its arguments reversed.

__rdivmod__(argument0, argument1)

divmod(x, y) -> (quotient, remainder)

Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.

Calls the __divmod__()-generic with its arguments reversed.

__repeat__(*arguments)

repeat(a, b) – Return a * b, where a is a sequence, and b is an integer.

Calls the __repeat__()-generic with its arguments.

__repr__()[source]

Answer the objects debug-string by calling spy().

__rfloordiv__(argument0, argument1)

floordiv(a, b) – Same as a // b.

Calls the __floordiv__()-generic with its arguments reversed.

__rlshift__(argument0, argument1)

lshift(a, b) – Same as a << b.

Calls the __lshift__()-generic with its arguments reversed.

__rmod__(argument0, argument1)

mod(a, b) – Same as a % b.

Calls the __mod__()-generic with its arguments reversed.

__rmul__(argument0, argument1)

mul(a, b) – Same as a * b.

Calls the __mul__()-generic with its arguments reversed.

__ror__(argument0, argument1)

or_(a, b) – Same as a | b.

Calls the __or__()-generic with its arguments reversed.

__rpow__(argument0, argument1)

pow(a, b) – Same as a ** b.

Calls the __pow__()-generic with its arguments reversed.

__rrshift__(argument0, argument1)

rshift(a, b) – Same as a >> b.

Calls the __rshift__()-generic with its arguments reversed.

__rshift__(*arguments)

rshift(a, b) – Same as a >> b.

Calls the __rshift__()-generic with its arguments.

__rsub__(argument0, argument1)

sub(a, b) – Same as a - b.

Calls the __sub__()-generic with its arguments reversed.

__rtruediv__(argument0, argument1)

truediv(a, b) – Same as a / b when __future__.division is in effect.

Calls the __truediv__()-generic with its arguments reversed.

__rxor__(argument0, argument1)

xor(a, b) – Same as a ^ b.

Calls the __xor__()-generic with its arguments reversed.

__setitem__(*arguments)

setitem(a, b, c) – Same as a[b] = c.

Calls the __setitem__()-generic with its arguments.

__setslice__(*arguments)

setslice(a, b, c, d) – Same as a[b:c] = d.

Calls the __setslice__()-generic with its arguments.

__str__()[source]

Answer the objects print-string by calling as_string().

__sub__(*arguments)

sub(a, b) – Same as a - b.

Calls the __sub__()-generic with its arguments.

__truediv__(*arguments)

truediv(a, b) – Same as a / b when __future__.division is in effect.

Calls the __truediv__()-generic with its arguments.

__weakref__

list of weak references to the object (if defined)

__xor__(*arguments)

xor(a, b) – Same as a ^ b.

Calls the __xor__()-generic with its arguments.

class gf.go.Object(*arguments)[source]

Just like AbstractObject, but can be instantiated.

class gf.go.FinalizingMixin

A mixin class with __del__ implemented as a generic function.

Note

This functionality was separated into mixin class, because Python’s cycle garbage collector does not collect classes with a __del__() method. Inherit from this class if you really need __del__().

__del__()

Call the __del__() generic function.

__weakref__

list of weak references to the object (if defined)

gf.go.spy(*arguments)[source]

Answer an object’s debug string.

This is done by creating a Writer instance and calling the __spy__() generic with the object and the writer. The using Writer.get_text() to retrieve the text written.

Note

The function’s name was taken from Prolog’s spy debugging aid.

gf.go.as_string(*arguments)[source]

Answer an object’s print string.

This is done by creating a Writer instance and calling the __out__() generic with the object and the writer. The using Writer.get_text() to retrieve the text written.