Skip to content

Commit

Permalink
Fix python client attribute output to handle None (#265)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sderickson committed Jan 25, 2022
1 parent f84a8a7 commit 90dd831
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion stone/backends/python_client.py
Expand Up @@ -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:
Expand Down
31 changes: 31 additions & 0 deletions test/test_python_client.py
Expand Up @@ -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
"""
Expand Down

0 comments on commit 90dd831

Please sign in to comment.