Commit 1a7cc17bb3a86c2fa27ca8d5a0d5749f60e281f7

Authored by Miguel Barão
1 parent b7624fcd
Exists in master and in 1 other branch dev

more type annotations.

adds [mypy] section in mypy.ini
aprendizations/learnapp.py
@@ -138,8 +138,10 @@ class LearnApp(object): @@ -138,8 +138,10 @@ class LearnApp(object):
138 138
139 else: 139 else:
140 name, hashed_pw = found 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 if pw_ok: 146 if pw_ok:
145 if uid in self.online: 147 if uid in self.online:
aprendizations/main.py
@@ -62,7 +62,7 @@ def parse_cmdline_arguments(): @@ -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 if debug: 66 if debug:
67 filename, level = 'logger-debug.yaml', 'DEBUG' 67 filename, level = 'logger-debug.yaml', 'DEBUG'
68 else: 68 else:
aprendizations/models.py
1 1
  2 +# python standard library
  3 +from typing import Any
  4 +
2 # third party libraries 5 # third party libraries
3 from sqlalchemy import Column, ForeignKey, Integer, Float, String 6 from sqlalchemy import Column, ForeignKey, Integer, Float, String
4 from sqlalchemy.ext.declarative import declarative_base 7 from sqlalchemy.ext.declarative import declarative_base
@@ -7,7 +10,8 @@ from sqlalchemy.orm import relationship @@ -7,7 +10,8 @@ from sqlalchemy.orm import relationship
7 10
8 # =========================================================================== 11 # ===========================================================================
9 # Declare ORM 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
@@ -8,7 +8,7 @@ import mimetypes @@ -8,7 +8,7 @@ import mimetypes
8 from os import path 8 from os import path
9 import signal 9 import signal
10 import sys 10 import sys
11 -from typing import List, Optional, Tuple, Union 11 +from typing import List, Optional, Union
12 import uuid 12 import uuid
13 13
14 # third party libraries 14 # third party libraries
aprendizations/student.py
@@ -99,7 +99,7 @@ class StudentState(object): @@ -99,7 +99,7 @@ class StudentState(object):
99 questions = t['questions'][:k] 99 questions = t['questions'][:k]
100 logger.debug(f'selected questions: {", ".join(questions)}') 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 for ref in questions] 103 for ref in questions]
104 104
105 n = len(self.questions) 105 n = len(self.questions)
aprendizations/tools.py
@@ -127,7 +127,7 @@ markdown = MarkdownWithMath(HighlightRenderer(escape=True)) @@ -127,7 +127,7 @@ markdown = MarkdownWithMath(HighlightRenderer(escape=True))
127 127
128 128
129 def md_to_html(text: str, strip_p_tag: bool = False) -> str: 129 def md_to_html(text: str, strip_p_tag: bool = False) -> str:
130 - md = markdown(text) 130 + md: str = markdown(text)
131 if strip_p_tag and md.startswith('<p>') and md.endswith('</p>'): 131 if strip_p_tag and md.startswith('<p>') and md.endswith('</p>'):
132 return md[3:-5] 132 return md[3:-5]
133 else: 133 else:
  1 +[mypy]
  2 +python_version = 3.7
  3 +warn_return_any = True
  4 +warn_unused_configs = True
  5 +
1 [mypy-sqlalchemy.*] 6 [mypy-sqlalchemy.*]
2 ignore_missing_imports = True 7 ignore_missing_imports = True
3 8
@@ -12,7 +17,3 @@ ignore_missing_imports = True @@ -12,7 +17,3 @@ ignore_missing_imports = True
12 17
13 [mypy-mistune.*] 18 [mypy-mistune.*]
14 ignore_missing_imports = True 19 ignore_missing_imports = True
15 -  
16 -[mypy-setuptools.*]  
17 -ignore_missing_imports = True  
18 -