From a5d3bb4069c268ce618ac6124d763bd24b85cef4 Mon Sep 17 00:00:00 2001 From: Gabriel Pettier Date: Sun, 15 Dec 2019 11:01:10 +0100 Subject: [PATCH] expose the signatures as a signature object instead of `__dir__` --- jnius/jnius_export_class.pxi | 4 ++-- jnius/jnius_utils.pxi | 2 +- tests/test_dir.py | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/jnius/jnius_export_class.pxi b/jnius/jnius_export_class.pxi index 89e4852..53e8e15 100644 --- a/jnius/jnius_export_class.pxi +++ b/jnius/jnius_export_class.pxi @@ -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): diff --git a/jnius/jnius_utils.pxi b/jnius/jnius_utils.pxi index a5684bf..55cbc25 100644 --- a/jnius/jnius_utils.pxi +++ b/jnius/jnius_utils.pxi @@ -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 - diff --git a/tests/test_dir.py b/tests/test_dir.py index dbe57ac..e5fff69 100644 --- a/tests/test_dir.py +++ b/tests/test_dir.py @@ -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)