From 90dd831f8d43966a8f97d4536295082c3353f29e Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Tue, 25 Jan 2022 13:26:37 -0800 Subject: [PATCH] Fix python client attribute output to handle None (#265) In testing 3.3.0 with the Python SDK, turns out routes without the attribute defined have values of "None". This PR tweaks the logic from #262 to handle None, and adds a regression test. Also updates the version to so as a follow I can publish the fix. --- setup.py | 2 +- stone/backends/python_client.py | 2 +- test/test_python_client.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 79164928..5977589a 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ dist = setup( name='stone', - version='3.3.0', + version='3.3.1', install_requires=install_reqs, setup_requires=setup_requires, tests_require=test_reqs, diff --git a/stone/backends/python_client.py b/stone/backends/python_client.py index 225c57c8..f9957da4 100644 --- a/stone/backends/python_client.py +++ b/stone/backends/python_client.py @@ -396,7 +396,7 @@ def _generate_docstring_for_func(self, namespace, arg_data_type, attrs_lines = [] if self.args.attribute_comment and attrs: for attribute in self.args.attribute_comment: - if attribute in attrs: + if attribute in attrs and attrs[attribute] is not None: attrs_lines.append('{}: {}'.format(attribute, attrs[attribute])) if not fields and not overview and not attrs_lines: diff --git a/test/test_python_client.py b/test/test_python_client.py index 6f4faa41..9ac8aee6 100644 --- a/test/test_python_client.py +++ b/test/test_python_client.py @@ -253,6 +253,37 @@ def files_get_metadata(self): ''') self.assertEqual(result, expected) + def test_route_with_none_attribute_in_docstring(self): + # type: () -> None + + route = ApiRoute('get_metadata', 1, None) + route.set_attributes(None, None, Void(), Void(), Void(), { + 'scope': 'events.read', 'another_attribute': None + }) + ns = ApiNamespace('files') + ns.add_route(route) + + result = self._evaluate_namespace(ns) + expected = textwrap.dedent('''\ + def files_get_metadata(self): + """ + Route attributes: + scope: events.read + + :rtype: None + """ + arg = None + r = self.request( + files.get_metadata, + 'files', + arg, + None, + ) + return None + + ''') + self.assertEqual(result, expected) + def test_route_with_attributes_and_doc_in_docstring(self): # type: () -> None """