File: function_self.py

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (85 lines) | stat: -rw-r--r-- 1,758 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# mode: run
# tag: pure2.7

# cython: binding=True

import cython
import sys

def regular(x):
    """
    >>> hasattr(regular, "__self__")
    False
    >>> nested = regular(10)
    >>> hasattr(nested, "__self__")
    False
    """
    def nested(y):
        return x+y
    return nested

@cython.locals(x=cython.floating)
def fused(x):
    """
    >>> nested = fused(10.)
    >>> hasattr(nested, "__self__")
    False

    >>> hasattr(fused, "__self__")
    False
    """
    def nested_in_fused(y):
        return x+y
    return nested_in_fused

# FIXME - doesn't currently work at all
#def get_nested_fused(x):
#    @cython.locals(x=cython.floating)
#    def nested_fused(y):
#        return x+y
#    return nested_fused

class C:
    """
    >>> c = C()
    >>> c.regular.__self__ is c
    True
    >>> c.fused.__self__ is c
    True
    """
    def regular(self):
        pass

    @cython.locals(x=cython.floating)
    def fused(self, x):
        return x

__doc__ = ""
if sys.version_info[0] > 2 or cython.compiled:
    __doc__ += """
    >>> hasattr(C.regular, "__self__")  # __self__==None on pure-python 2
    False

    # returns None on pure-python 2
    >>> C.fused.__self__  #doctest: +ELLIPSIS
    Traceback (most recent call last):
        ...
    AttributeError: 'function' object has no attribute '__self__'...
    """

if cython.compiled:
    __doc__ = """
    >>> hasattr(fused['double'], '__self__')
    False

    >>> hasattr(C.fused['double'], '__self__')
    False

    >>> c = C()
    >>> c.fused['double'].__self__ is c   #doctest: +ELLIPSIS
    True

    # The PR that changed __self__ also changed how __doc__ is set up slightly
    >>> fused['double'].__doc__ == fused.__doc__ and isinstance(fused.__doc__, str)
    True
    """