expose the signatures as a signature object instead of `__dir__`

This commit is contained in:
Gabriel Pettier 2019-12-15 11:01:10 +01:00
parent 601dfa15fb
commit a5d3bb4069
3 changed files with 12 additions and 12 deletions

View File

@ -682,7 +682,7 @@ cdef class JavaMethod(object):
self.j_cls = NULL
self.j_self = None
def __dir__(self):
def signatures(self):
return list([readable_sig(self.definition, self.is_varargs)])
def __init__(self, definition, **kwargs):
@ -964,7 +964,7 @@ cdef class JavaMultipleMethod(object):
cdef bytes name
cdef bytes classname
def __dir__(self):
def signatures(self):
return [readable_sig(args, is_varargs) for args, static, is_varargs in self.definitions]
def __cinit__(self, definition, **kwargs):

View File

@ -403,6 +403,7 @@ cdef int calculate_score(sign_args, args, is_varargs=False) except *:
# change this method score
return score
cdef readable_sig(sig, is_var):
"""
Converts JNI signature to easily readable signature.
@ -477,4 +478,3 @@ cdef readable_sig(sig, is_var):
i += 1
return args, rtn

View File

@ -6,15 +6,15 @@ from jnius.reflect import autoclass
class DirTest(unittest.TestCase):
def test_varargs_dir(self):
def test_varargs_signatures(self):
# >>> from jnius import autoclass
# >>> cls = autoclass('java.lang.System')
# >>> dir(cls.out.printf)
# >>> cls.out.printf.signatures()
# [(['java/lang/String', 'java/lang/Object...'], 'java/io/PrintStream'),
# (['java/util/Locale', 'java/lang/String', 'java/lang/Object...'], 'java/io/PrintStream')]
cls = autoclass("java.lang.System")
result = dir(cls.out.printf)
result = cls.out.printf.signatures()
assert isinstance(result, list)
assert all(isinstance(f, tuple) for f in result)
@ -22,15 +22,15 @@ class DirTest(unittest.TestCase):
assert (['java/lang/String', 'java/lang/Object...'], 'java/io/PrintStream') in result
assert (['java/util/Locale', 'java/lang/String', 'java/lang/Object...'], 'java/io/PrintStream') in result
def test_array_dir(self):
def test_array_signatures(self):
# >>> from jnius import autoclass
# >>> cls = autoclass('java.util.List')
# >>> dir(cls.toArray)
# >>> cls.toArray.signatures()
# [([], 'java/lang/Object[]'),
# (['java/lang/Object[]'], 'java/lang/Object[]')]
cls = autoclass("java.util.List")
result = dir(cls.toArray)
result = cls.toArray.signatures()
assert isinstance(result, list)
assert all(isinstance(f, tuple) for f in result)
@ -38,10 +38,10 @@ class DirTest(unittest.TestCase):
assert ([], 'java/lang/Object[]') in result
assert (['java/lang/Object[]'], 'java/lang/Object[]') in result
def test_dir(self):
def test_signatures(self):
# >>> from jnius import autoclass
# >>> cls = autoclass('java.lang.String')
# >>> dir(cls.valueOf)
# >>> cls.valueOf.signatures()
# [(['boolean'], 'java/lang/String'),
# (['char'], 'java/lang/String'),
# (['char[]'], 'java/lang/String'),
@ -53,7 +53,7 @@ class DirTest(unittest.TestCase):
# (['long'], 'java/lang/String')]
cls = autoclass("java.lang.String")
result = dir(cls.valueOf)
result = cls.valueOf.signatures()
assert isinstance(result, list)
assert all(isinstance(f, tuple) for f in result)