1
2cdef gobble(a, b):
3    print a, b
4
5cdef class Spam:
6    """
7    >>> s = Spam(12)
8    >>> s.eat()
9    12 42
10    """
11    cdef eggs
12    cdef int ham
13
14    def __cinit__(self, eggs):
15        self.eggs = eggs
16        self.ham = 42
17
18    def __dealloc__(self):
19        self.ham = 0
20
21    def eat(self):
22        gobble(self.eggs, self.ham)
23
24def f(Spam spam):
25    """
26    >>> s = Spam(12)
27    >>> f(s)   # doctest: +ELLIPSIS
28    Traceback (most recent call last):
29    AttributeError: '...Spam' object has no attribute 'foo'
30    >>> s.eat()
31    12 42
32    >>> class Spam2(Spam):
33    ...     foo = 1
34    >>> s = Spam2(12)
35    >>> s.eat()
36    12 42
37    >>> f(s)
38    >>> s.eat()
39    12 42
40    """
41    x = spam.eggs
42    y = spam.ham
43    z = spam.foo
44    spam.eggs = x
45    spam.ham = y
46    spam.foo = z
47