Fix mypy violations (with mypy-0.790)

This commit is contained in:
Takeshi KOMIYA 2020-10-24 14:14:11 +09:00
parent 3b1c48f3b6
commit ccc77b8305
4 changed files with 9 additions and 9 deletions

View File

@ -44,7 +44,7 @@ extras_require = {
'lint': [ 'lint': [
'flake8>=3.5.0', 'flake8>=3.5.0',
'flake8-import-order', 'flake8-import-order',
'mypy>=0.780', 'mypy>=0.790',
'docutils-stubs', 'docutils-stubs',
], ],
'test': [ 'test': [

View File

@ -1725,7 +1725,7 @@ class TypeVarDocumenter(DataDocumenter):
@classmethod @classmethod
def can_document_member(cls, member: Any, membername: str, isattr: bool, parent: Any def can_document_member(cls, member: Any, membername: str, isattr: bool, parent: Any
) -> bool: ) -> bool:
return isinstance(member, TypeVar) and isattr # type: ignore return isinstance(member, TypeVar) and isattr
def add_directive_header(self, sig: str) -> None: def add_directive_header(self, sig: str) -> None:
self.options.annotation = SUPPRESS # type: ignore self.options.annotation = SUPPRESS # type: ignore

View File

@ -297,8 +297,8 @@ class IndexBuilder:
frozen.get('envversion') != self.env.version: frozen.get('envversion') != self.env.version:
raise ValueError('old format') raise ValueError('old format')
index2fn = frozen['docnames'] index2fn = frozen['docnames']
self._filenames = dict(zip(index2fn, frozen['filenames'])) # type: ignore self._filenames = dict(zip(index2fn, frozen['filenames']))
self._titles = dict(zip(index2fn, frozen['titles'])) # type: ignore self._titles = dict(zip(index2fn, frozen['titles']))
def load_terms(mapping: Dict[str, Any]) -> Dict[str, Set[str]]: def load_terms(mapping: Dict[str, Any]) -> Dict[str, Set[str]]:
rv = {} rv = {}
@ -359,13 +359,13 @@ class IndexBuilder:
def get_terms(self, fn2index: Dict) -> Tuple[Dict[str, List[str]], Dict[str, List[str]]]: def get_terms(self, fn2index: Dict) -> Tuple[Dict[str, List[str]], Dict[str, List[str]]]:
rvs = {}, {} # type: Tuple[Dict[str, List[str]], Dict[str, List[str]]] rvs = {}, {} # type: Tuple[Dict[str, List[str]], Dict[str, List[str]]]
for rv, mapping in zip(rvs, (self._mapping, self._title_mapping)): for rv, mapping in zip(rvs, (self._mapping, self._title_mapping)):
for k, v in mapping.items(): # type: ignore for k, v in mapping.items():
if len(v) == 1: if len(v) == 1:
fn, = v fn, = v
if fn in fn2index: if fn in fn2index:
rv[k] = fn2index[fn] # type: ignore rv[k] = fn2index[fn]
else: else:
rv[k] = sorted([fn2index[fn] for fn in v if fn in fn2index]) # type: ignore # NOQA rv[k] = sorted([fn2index[fn] for fn in v if fn in fn2index])
return rvs return rvs
def freeze(self) -> Dict[str, Any]: def freeze(self) -> Dict[str, Any]:

View File

@ -57,14 +57,14 @@ Inventory = Dict[str, Dict[str, Tuple[str, str, str, str]]]
def is_system_TypeVar(typ: Any) -> bool: def is_system_TypeVar(typ: Any) -> bool:
"""Check *typ* is system defined TypeVar.""" """Check *typ* is system defined TypeVar."""
modname = getattr(typ, '__module__', '') modname = getattr(typ, '__module__', '')
return modname == 'typing' and isinstance(typ, TypeVar) # type: ignore return modname == 'typing' and isinstance(typ, TypeVar)
def stringify(annotation: Any) -> str: def stringify(annotation: Any) -> str:
"""Stringify type annotation object.""" """Stringify type annotation object."""
if isinstance(annotation, str): if isinstance(annotation, str):
return annotation return annotation
elif isinstance(annotation, TypeVar): # type: ignore elif isinstance(annotation, TypeVar):
return annotation.__name__ return annotation.__name__
elif not annotation: elif not annotation:
return repr(annotation) return repr(annotation)