How to get argument names and __annotations__ from Cython method descriptor?
<p>If I define method in <code>cdef class</code>, method has no any info about arguments and annotations:</p>

<p>Python class:</p>

<pre><code>class MyClass:
   def test(self, arg: int):
      pass
print(dir(MyClass.test))

['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']
</code></pre>

<p>Cython class:</p>

<pre><code>cdef class MyClass:
   def test(self, arg: int):
      pass
print(dir(MyClass.test))
['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__name__', '__ne__', '__new__', '__objclass__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__text_signature__']
</code></pre>

<p>Are there any ways to get argumnets with annotations from Cython method?</p>

<p>P.S. type of Cython's class method is not a method: <code>&lt;class 'method_descriptor'&gt;</code>, not a <code>&lt;class 'cython_function_or_method'&gt;</code></p>

<p>According to <a href="https://github.com/cython/cython/issues/1053" rel="nofollow">this issue</a> on the Cython github repo, annotations were added but only for <code>cdef</code> functions:</p>

<pre><code>%%cython
def test2(arg: int): pass
cpdef test1(arg: int): pass
cdef test(arg: int): pass

print(['__annotations__' in dir(i) for i in [test2, test1, test]])
[False, False, True]
</code></pre>

<p>Apart from that, getting <code>__annotations__</code> simply returns an empty dictionary. It seems annotations are only used when generating the <code>C</code> code (haven't verified) and not meant to be available for the user.</p>

python methods annotations cython inspect