Skip to content

Commit 5b24a58

Browse files
committed
feat: add support for single-quoted doc
fix #84
1 parent 808c872 commit 5b24a58

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tap/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,21 @@ def get_class_variables(cls: type) -> OrderedDict:
235235
if token['token'].strip() == '':
236236
continue
237237

238-
# Extract multiline comments
238+
# Extract multiline comments in triple quote
239239
if (class_variable is not None
240240
and token['token_type'] == tokenize.STRING
241241
and token['token'][:3] in {'"""', "'''"}):
242242
sep = ' ' if variable_to_comment[class_variable]['comment'] else ''
243243
variable_to_comment[class_variable]['comment'] += sep + token['token'][3:-3].strip()
244+
continue
245+
246+
# Extract multiline comments in single quote
247+
if (class_variable is not None
248+
and token['token_type'] == tokenize.STRING
249+
and token['token'][:1] in {'"', "'"}):
250+
sep = ' ' if variable_to_comment[class_variable]['comment'] else ''
251+
variable_to_comment[class_variable]['comment'] += sep + token['token'][1:-1].strip()
252+
continue
244253

245254
# Match class variable
246255
class_variable = None

tests/test_utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,30 @@ class TrickyMultiline:
281281
class_variables['foo'] = {'comment': comment}
282282
self.assertEqual(get_class_variables(TrickyMultiline), class_variables)
283283

284+
def test_triple_quote_multiline(self):
285+
class TripleQuoteMultiline:
286+
bar: int = 0
287+
'''biz baz'''
288+
289+
hi: str
290+
"""Hello there"""
291+
292+
class_variables = OrderedDict()
293+
class_variables['bar'] = {'comment': 'biz baz'}
294+
class_variables['hi'] = {'comment': 'Hello there'}
295+
self.assertEqual(get_class_variables(TripleQuoteMultiline), class_variables)
296+
284297
def test_single_quote_multiline(self):
285298
class SingleQuoteMultiline:
286299
bar: int = 0
287-
'''biz baz'''
300+
'biz baz'
301+
302+
hi: str
303+
"Hello there"
288304

289305
class_variables = OrderedDict()
290306
class_variables['bar'] = {'comment': 'biz baz'}
307+
class_variables['hi'] = {'comment': 'Hello there'}
291308
self.assertEqual(get_class_variables(SingleQuoteMultiline), class_variables)
292309

293310
def test_functions_with_docs_multiline(self):

0 commit comments

Comments
 (0)