Skip to content

Commit 667bef4

Browse files
committed
Add arity() method
1 parent 854aa3a commit 667bef4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cypari2/gen.pyx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,6 +4021,23 @@ cdef class Gen(Gen_base):
40214021
set_gel(v, i+1, pol_x(fetch_user_var(varname)))
40224022
return new_gen(gsubstvec(self.g, v, t0.g))
40234023

4024+
def arity(self):
4025+
"""
4026+
Return the number of arguments of this ``t_CLOSURE``.
4027+
4028+
>>> from cypari2 import Pari
4029+
>>> pari = Pari()
4030+
>>> pari("() -> 42").arity()
4031+
0
4032+
>>> pari("(x) -> x").arity()
4033+
1
4034+
>>> pari("(x,y,z) -> x+y+z").arity()
4035+
3
4036+
"""
4037+
if typ(self.g) != t_CLOSURE:
4038+
raise TypeError(f"arity() requires a t_CLOSURE")
4039+
return closure_arity(self.g)
4040+
40244041
def factorpadic(self, p, long r=20):
40254042
"""
40264043
p-adic factorization of the polynomial ``pol`` to precision ``r``.

0 commit comments

Comments
 (0)