Repository: sympy/sympy

Issue:
nargs attribute of custom function not inherited
When I make a subclass of custom function, `nargs` attribute is not inherited.

```
>>> class MyFunc1(Function):
...     nargs = 1
>>> MyFunc1.nargs
{1}

>>> class MyFunc2(MyFunc1):
... pass
>>> MyFunc2.nargs
Naturals0
```

Wouldn't it be better if it is inherited?

Discussion:

Patch:
diff --git a/sympy/core/function.py b/sympy/core/function.py
index 02d53d2d58..8a4c719083 100644
--- a/sympy/core/function.py
+++ b/sympy/core/function.py
@@ -171,6 +171,13 @@ def __init__(cls, *args, **kwargs):
         # honor kwarg value or class-defined value before using
         # the number of arguments in the eval function (if present)
         nargs = kwargs.pop('nargs', cls.__dict__.get('nargs', arity(cls)))
+        if nargs is None and 'nargs' not in cls.__dict__:
+            for supcls in cls.__mro__:
+                if hasattr(supcls, '_nargs'):
+                    nargs = supcls._nargs
+                    break
+                else:
+                    continue
 
         # Canonicalize nargs here; change to set in nargs.
         if is_sequence(nargs):


Test patch:
diff --git a/sympy/core/tests/test_function.py b/sympy/core/tests/test_function.py
index 3276cb83d2..2a9d2a46a3 100644
--- a/sympy/core/tests/test_function.py
+++ b/sympy/core/tests/test_function.py
@@ -160,6 +160,40 @@ def test_nargs():
     assert Function('f', nargs=None).nargs == S.Naturals0
     raises(ValueError, lambda: Function('f', nargs=()))
 
+def test_nargs_inheritance():
+    class f1(Function):
+        nargs = 2
+    class f2(f1):
+        pass
+    class f3(f2):
+        pass
+    class f4(f3):
+        nargs = 1,2
+    class f5(f4):
+        pass
+    class f6(f5):
+        pass
+    class f7(f6):
+        nargs=None
+    class f8(f7):
+        pass
+    class f9(f8):
+        pass
+    class f10(f9):
+        nargs = 1
+    class f11(f10):
+        pass
+    assert f1.nargs == FiniteSet(2)
+    assert f2.nargs == FiniteSet(2)
+    assert f3.nargs == FiniteSet(2)
+    assert f4.nargs == FiniteSet(1, 2)
+    assert f5.nargs == FiniteSet(1, 2)
+    assert f6.nargs == FiniteSet(1, 2)
+    assert f7.nargs == S.Naturals0
+    assert f8.nargs == S.Naturals0
+    assert f9.nargs == S.Naturals0
+    assert f10.nargs == FiniteSet(1)
+    assert f11.nargs == FiniteSet(1)
 
 def test_arity():
     f = lambda x, y: 1