From 208b3290cfc84899fb08f2a226e4e7577c4c9c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Fri, 15 Jul 2022 17:51:40 +0200 Subject: [PATCH 1/5] Replaced isfunction & ismethod with isroutine This pretty much returns exactly the same as before, but with the benefit of including C functions/methods. You can read more about that here: https://stackoverflow.com/a/17019998/6901146 --- baseplate/clients/thrift.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/baseplate/clients/thrift.py b/baseplate/clients/thrift.py index c20dad1d6..e2ca0c688 100644 --- a/baseplate/clients/thrift.py +++ b/baseplate/clients/thrift.py @@ -117,21 +117,14 @@ def _enumerate_service_methods(client: Any) -> Iterator[str]: """Return an iterable of service methods from a generated Iface class.""" ifaces_found = 0 - # python3 drops the concept of unbound methods, so they're just plain - # functions and we have to account for that here. see: - # https://stackoverflow.com/questions/17019949/why-is-there-a-difference-between-inspect-ismethod-and-inspect-isfunction-from-p # noqa: E501 - def predicate(x: Any) -> bool: - return inspect.isfunction(x) or inspect.ismethod(x) - for base_cls in inspect.getmro(client): if base_cls.__name__ == "Iface": - for name, _ in inspect.getmembers(base_cls, predicate): + for name, _ in inspect.getmembers(base_cls, inspect.isroutine): yield name ifaces_found += 1 - + assert ifaces_found > 0, "class is not a thrift client; it has no Iface" - class _PooledClientProxy: """A proxy which acts like a thrift client but uses a connection pool.""" From 27f255d7a3dca20ad78475a3f70596eb82a0c2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Fri, 15 Jul 2022 18:50:42 +0200 Subject: [PATCH 2/5] Update baseplate/clients/thrift.py Co-authored-by: Katie Atkinson --- baseplate/clients/thrift.py | 1 - 1 file changed, 1 deletion(-) diff --git a/baseplate/clients/thrift.py b/baseplate/clients/thrift.py index e2ca0c688..1dec5a9ca 100644 --- a/baseplate/clients/thrift.py +++ b/baseplate/clients/thrift.py @@ -122,7 +122,6 @@ def _enumerate_service_methods(client: Any) -> Iterator[str]: for name, _ in inspect.getmembers(base_cls, inspect.isroutine): yield name ifaces_found += 1 - assert ifaces_found > 0, "class is not a thrift client; it has no Iface" class _PooledClientProxy: From b3bc89e0b1fff6dfaed5189497579248000c49df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Fri, 15 Jul 2022 18:52:51 +0200 Subject: [PATCH 3/5] Update thrift.py --- baseplate/clients/thrift.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/baseplate/clients/thrift.py b/baseplate/clients/thrift.py index 1dec5a9ca..c32048d5e 100644 --- a/baseplate/clients/thrift.py +++ b/baseplate/clients/thrift.py @@ -122,8 +122,10 @@ def _enumerate_service_methods(client: Any) -> Iterator[str]: for name, _ in inspect.getmembers(base_cls, inspect.isroutine): yield name ifaces_found += 1 + assert ifaces_found > 0, "class is not a thrift client; it has no Iface" + class _PooledClientProxy: """A proxy which acts like a thrift client but uses a connection pool.""" From 83969c6a1b93b04b8bfb6695e6ff0447f00a48b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Fri, 15 Jul 2022 18:53:14 +0200 Subject: [PATCH 4/5] Update thrift.py --- baseplate/clients/thrift.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baseplate/clients/thrift.py b/baseplate/clients/thrift.py index c32048d5e..a860252fa 100644 --- a/baseplate/clients/thrift.py +++ b/baseplate/clients/thrift.py @@ -122,7 +122,7 @@ def _enumerate_service_methods(client: Any) -> Iterator[str]: for name, _ in inspect.getmembers(base_cls, inspect.isroutine): yield name ifaces_found += 1 - + assert ifaces_found > 0, "class is not a thrift client; it has no Iface" From f647cd59ac528e0dabc4cf30875c4097d1c8e7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=BChrig?= Date: Tue, 19 Jul 2022 17:38:10 +0200 Subject: [PATCH 5/5] Update thrift.py --- baseplate/clients/thrift.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/baseplate/clients/thrift.py b/baseplate/clients/thrift.py index a860252fa..256252eba 100644 --- a/baseplate/clients/thrift.py +++ b/baseplate/clients/thrift.py @@ -119,8 +119,9 @@ def _enumerate_service_methods(client: Any) -> Iterator[str]: for base_cls in inspect.getmro(client): if base_cls.__name__ == "Iface": - for name, _ in inspect.getmembers(base_cls, inspect.isroutine): - yield name + for name in base_cls.__dict__: + if callable(getattr(base_cls, name)): + yield name ifaces_found += 1 assert ifaces_found > 0, "class is not a thrift client; it has no Iface"