Skip to content

Commit 044671e

Browse files
committed
Configure mypy and fix mypy warnings (#4)
1 parent dad9b7f commit 044671e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

docstring_to_markdown/rst.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def looks_like_rst(value: str) -> bool:
103103
if re.search(directive.pattern, value):
104104
return True
105105
# allow "text::" or "text ::" but not "^::$" or "^:::$"
106-
return re.search(r'(\s|\w)::\n', value) or '\n>>> ' in value
106+
return bool(re.search(r'(\s|\w)::\n', value) or '\n>>> ' in value)
107107

108108

109109
class IBlockBeginning(SimpleNamespace):
@@ -146,7 +146,7 @@ def finish_consumption(self, final: bool) -> str:
146146

147147
class BlockParser(IParser):
148148
enclosure = '```'
149-
follower = None
149+
follower: Union['IParser', None] = None
150150
_buffer: List[str]
151151
_block_started: bool
152152

@@ -167,7 +167,7 @@ def consume(self, line: str):
167167
raise ValueError('Block has not started')
168168
self._buffer.append(line)
169169

170-
def finish_consumption(self, final: bool):
170+
def finish_consumption(self, final: bool) -> str:
171171
# if the last line is empty (e.g. a separator of intended block), discard it
172172
if self._buffer[len(self._buffer) - 1].strip() == '':
173173
self._buffer.pop()
@@ -196,7 +196,7 @@ def _start_block(self, language: str):
196196
def can_consume(self, line: str) -> bool:
197197
if self._is_block_beginning and line.strip() == '':
198198
return True
199-
return (len(line) > 0 and re.match(r'^\s', line[0])) or len(line) == 0
199+
return bool((len(line) > 0 and re.match(r'^\s', line[0])) or len(line) == 0)
200200

201201
def consume(self, line: str):
202202
if self._is_block_beginning:
@@ -296,6 +296,8 @@ def can_parse(self, line: str) -> bool:
296296

297297
def initiate_parsing(self, line: str, current_language: str) -> IBlockBeginning:
298298
match = re.match(CODE_BLOCK_PATTERN, line)
299+
# already checked in can_parse
300+
assert match
299301
self._start_block(match.group('language').strip() or current_language)
300302
return IBlockBeginning(remainder='')
301303

@@ -319,7 +321,7 @@ def initiate_parsing(self, line: str, current_language: str) -> IBlockBeginning:
319321
]
320322

321323

322-
def rst_to_markdown(text: str):
324+
def rst_to_markdown(text: str) -> str:
323325
"""
324326
Try to parse docstrings in following formats to markdown:
325327
- https://www.python.org/dev/peps/pep-0287/

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ project_urls =
2020
Source Code = https://github.com/krassowski/docstring-to-markdown
2121
version = attr: docstring_to_markdown.__version__
2222

23+
[mypy]
24+
warn_return_any = True
25+
warn_unused_configs = True
26+
2327
[options]
2428
packages = find:
2529
python_requires = >=3.6

0 commit comments

Comments
 (0)