Skip to content

Commit

Permalink
Add some types
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jun 22, 2022
1 parent 4b60af0 commit 9f1c009
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion test/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def test_newline_at_end(self):


class EvalTest(unittest.TestCase):
def _eval(self, template):
def _eval(self, template: str):
values = {
'foo': 'bar',
'baz': 'BaR',
Expand Down
14 changes: 7 additions & 7 deletions tmep/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
from tmep import functions
import textwrap
import typing
Functions = functions.Functions


Expand All @@ -27,10 +28,11 @@ def __init__(self):
)
self.functions.sort()

def prepare_docstrings(self, string):
def prepare_docstrings(self, string: str) -> str:
return re.sub(r' {2,}', ' ', string)

def extract_value(self, string, key, inline_code=True):
def extract_value(self, string: str, key: str,
inline_code: bool = True) -> typing.Optional[str]:
"""Extract strings from the docstrings
.. code-block:: text
Expand All @@ -40,24 +42,22 @@ def extract_value(self, string, key, inline_code=True):
* description: Shorten “text” on word boundarys.
"""
regex = r'\* ' + key + ': '
regex: str = r'\* ' + key + ': '
if inline_code:
regex = regex + '``(.*)``'
else:
regex = regex + '(.*)'
value = re.findall(regex, string)
if value:
return value[0].replace('``', '')
else:
return False

def underline(self, text, indent=4):
def underline(self, text: str, indent: int = 4) -> str:
"""Underline a given text"""
length = len(text)
indentation = (' ' * indent)
return indentation + text + '\n' + indentation + ('-' * length)

def format(self, text, width=78, indent=4):
def format(self, text: str, width: int = 78, indent: int = 4) -> str:
"""Apply textwrap to a given text string"""
return textwrap.fill(
text,
Expand Down

0 comments on commit 9f1c009

Please sign in to comment.