cython
1# mode: run
2# cython: language_level=3
3
4# This file tests that methodmangling is applied correctly to
5# pure Python decorated classes.
6
7import cython
8
9if cython.compiled:
10# don't run in Python mode since a significant number of the tests
11# are only for Cython features
12
13def declare(**kwargs):
14return kwargs['__x']
15
16class RegularClass:
17@cython.locals(__x=cython.int)
18def f1(self, __x, dummy=None):
19"""
20Is the locals decorator correctly applied
21>>> c = RegularClass()
22>>> c.f1(1)
231
24>>> c.f1("a")
25Traceback (most recent call last):
26...
27TypeError: an integer is required
28>>> c.f1(_RegularClass__x = 1)
291
30"""
31return __x
32
33def f2(self, x):
34"""
35Is the locals decorator correctly applied
36>>> c = RegularClass()
37>>> c.f2(1)
381
39>>> c.f2("a")
40Traceback (most recent call last):
41...
42TypeError: an integer is required
43"""
44__x = cython.declare(cython.int, x)
45
46return __x
47
48def f3(self, x):
49"""
50Is the locals decorator correctly applied
51>>> c = RegularClass()
52>>> c.f3(1)
531
54>>> c.f3("a")
55Traceback (most recent call last):
56...
57TypeError: an integer is required
58"""
59cython.declare(__x=cython.int)
60__x = x
61
62return __x
63
64def f4(self, x):
65"""
66We shouldn't be tripped up by a function called
67"declare" that is nothing to do with cython
68>>> RegularClass().f4(1)
691
70"""
71return declare(__x=x)
72else:
73__doc__ = """
74>>> True
75True
76""" # stops Python2 from failing
77