Commit 1a7cc17bb3a86c2fa27ca8d5a0d5749f60e281f7
1 parent
b7624fcd
Exists in
master
and in
1 other branch
more type annotations.
adds [mypy] section in mypy.ini
Showing
7 changed files
with
18 additions
and
11 deletions
Show diff stats
aprendizations/learnapp.py
... | ... | @@ -138,8 +138,10 @@ class LearnApp(object): |
138 | 138 | |
139 | 139 | else: |
140 | 140 | name, hashed_pw = found |
141 | - pw_ok = await loop.run_in_executor(None, bcrypt.checkpw, | |
142 | - pw.encode('utf-8'), hashed_pw) | |
141 | + pw_ok: bool = await loop.run_in_executor(None, | |
142 | + bcrypt.checkpw, | |
143 | + pw.encode('utf-8'), | |
144 | + hashed_pw) | |
143 | 145 | |
144 | 146 | if pw_ok: |
145 | 147 | if uid in self.online: | ... | ... |
aprendizations/main.py
... | ... | @@ -62,7 +62,7 @@ def parse_cmdline_arguments(): |
62 | 62 | |
63 | 63 | |
64 | 64 | # ---------------------------------------------------------------------------- |
65 | -def get_logger_config(debug: bool = False) -> Dict[str, Any]: | |
65 | +def get_logger_config(debug: bool = False) -> Any: | |
66 | 66 | if debug: |
67 | 67 | filename, level = 'logger-debug.yaml', 'DEBUG' |
68 | 68 | else: | ... | ... |
aprendizations/models.py
1 | 1 | |
2 | +# python standard library | |
3 | +from typing import Any | |
4 | + | |
2 | 5 | # third party libraries |
3 | 6 | from sqlalchemy import Column, ForeignKey, Integer, Float, String |
4 | 7 | from sqlalchemy.ext.declarative import declarative_base |
... | ... | @@ -7,7 +10,8 @@ from sqlalchemy.orm import relationship |
7 | 10 | |
8 | 11 | # =========================================================================== |
9 | 12 | # Declare ORM |
10 | -Base = declarative_base() | |
13 | +# FIXME Any is a workaround for mypy static type checking (see https://github.com/python/mypy/issues/6372) | |
14 | +Base: Any = declarative_base() | |
11 | 15 | |
12 | 16 | |
13 | 17 | # --------------------------------------------------------------------------- | ... | ... |
aprendizations/serve.py
aprendizations/student.py
... | ... | @@ -99,7 +99,7 @@ class StudentState(object): |
99 | 99 | questions = t['questions'][:k] |
100 | 100 | logger.debug(f'selected questions: {", ".join(questions)}') |
101 | 101 | |
102 | - self.questions = [await self.factory[ref].generate_async() | |
102 | + self.questions: List[Question] = [await self.factory[ref].generate_async() | |
103 | 103 | for ref in questions] |
104 | 104 | |
105 | 105 | n = len(self.questions) | ... | ... |
aprendizations/tools.py
... | ... | @@ -127,7 +127,7 @@ markdown = MarkdownWithMath(HighlightRenderer(escape=True)) |
127 | 127 | |
128 | 128 | |
129 | 129 | def md_to_html(text: str, strip_p_tag: bool = False) -> str: |
130 | - md = markdown(text) | |
130 | + md: str = markdown(text) | |
131 | 131 | if strip_p_tag and md.startswith('<p>') and md.endswith('</p>'): |
132 | 132 | return md[3:-5] |
133 | 133 | else: | ... | ... |
mypy.ini
1 | +[mypy] | |
2 | +python_version = 3.7 | |
3 | +warn_return_any = True | |
4 | +warn_unused_configs = True | |
5 | + | |
1 | 6 | [mypy-sqlalchemy.*] |
2 | 7 | ignore_missing_imports = True |
3 | 8 | |
... | ... | @@ -12,7 +17,3 @@ ignore_missing_imports = True |
12 | 17 | |
13 | 18 | [mypy-mistune.*] |
14 | 19 | ignore_missing_imports = True |
15 | - | |
16 | -[mypy-setuptools.*] | |
17 | -ignore_missing_imports = True | |
18 | - | ... | ... |