Debian Codegraph @

tests/example-project/src/pypackage/wrap_c_ext_module.pyx

raw
1
2 cdef extern from "../clib/sqrc.c":
3 int isqr(int a)
4 double dsqr(double a)
5
6
7 def sqr(a):
8 """
9 >>> sqr(2)
10 4
11 >>> '%.3g' % round(sqr(2.2), 2)
12 '4.84'
13 >>> sqr("asd")
14 Traceback (most recent call last):
15 ...
16 TypeError: Expected int or float type input.
17 """
18 if isinstance(a, (int, )):
19 return isqr(a)
20
21 elif isinstance(a, (float, )):
22 return dsqr(a)
23
24 else:
25 raise TypeError("Expected int or float type input.")