Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mypy type checking #4553

Merged
merged 4 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repos:
entry: mypy
language: python
types: [python]
args: [--scripts-are-modules]
args: [--scripts-are-modules, --warn-unused-ignores]
greschd marked this conversation as resolved.
Show resolved Hide resolved
require_serial: true
pass_filenames: true
files: >-
Expand Down
6 changes: 3 additions & 3 deletions aiida/common/progress_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_progress_reporter() -> Type[ProgressReporterAbstract]:

"""
global PROGRESS_REPORTER
return PROGRESS_REPORTER # type: ignore
return PROGRESS_REPORTER


def set_progress_reporter(reporter: Optional[Type[ProgressReporterAbstract]] = None, **kwargs: Any):
Expand All @@ -154,11 +154,11 @@ def set_progress_reporter(reporter: Optional[Type[ProgressReporterAbstract]] = N
"""
global PROGRESS_REPORTER
if reporter is None:
PROGRESS_REPORTER = ProgressReporterNull # type: ignore
PROGRESS_REPORTER = ProgressReporterNull
elif kwargs:
PROGRESS_REPORTER = partial(reporter, **kwargs) # type: ignore
else:
PROGRESS_REPORTER = reporter # type: ignore
PROGRESS_REPORTER = reporter


def set_progress_bar_tqdm(bar_format: Optional[str] = TQDM_BAR_FORMAT, leave: Optional[bool] = False, **kwargs: Any):
Expand Down
5 changes: 3 additions & 2 deletions aiida/tools/importexport/archive/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ def open(self):
# create a temporary folder in which to perform the write
self._temp_path: Path = Path(tempfile.mkdtemp())
# open a zipfile in in write mode to export to
self._zipinfo_cache: Optional[dict]
if self._cache_zipinfo:
self._zipinfo_cache = shelve.open(str(self._temp_path / 'zipinfo_cache'))
self._zipinfo_cache = shelve.open(str(self._temp_path / 'zipinfo_cache')) # type: ignore
else:
self._zipinfo_cache = None
self._archivepath: ZipPath = ZipPath(
Expand All @@ -289,7 +290,7 @@ def close(self, excepted: bool):
# close the zipfile to finalise write
self._archivepath.close()
if getattr(self, '_zipinfo_cache', None) is not None:
self._zipinfo_cache.close()
self._zipinfo_cache.close() # type: ignore
delattr(self, '_zipinfo_cache')
# move the compressed file to the final path
self._remove_filepath()
Expand Down
4 changes: 2 additions & 2 deletions aiida/tools/importexport/dbexport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ def _get_starting_node_ids(entities: List[Any]) -> Tuple[DefaultDict[str, Set[st
pks.append(pk)
uuids.append(uuid)

entities_starting_set[NODE_ENTITY_NAME].update(uuids) # type: ignore
given_node_entry_ids.update(pks) # type: ignore
entities_starting_set[NODE_ENTITY_NAME].update(uuids)
given_node_entry_ids.update(pks)

return entities_starting_set, given_node_entry_ids

Expand Down
5 changes: 4 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[mypy]
python_version = 3.6

follow_imports = skip
check_untyped_defs = True

; Strictness settings
Expand Down Expand Up @@ -31,6 +30,10 @@ check_untyped_defs = True
; allow_untyped_globals = False
; strict_equality = True

[mypy-aiida.*]
; can only follow these imports when more of the code is typed
follow_imports = skip

[mypy-tests.*]
check_untyped_defs = False

Expand Down