Skip to content

Commit

Permalink
Resolve a few straightforward mypy type errors. (#1492)
Browse files Browse the repository at this point in the history
* Add missing type hint to resolve mypy type inference failure.

* Suppress conditional ujson/json import-related mypy errors.
  • Loading branch information
obi1kenobi authored Jan 10, 2021
1 parent 4208df8 commit 910e781
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion arviz/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
try:
import ujson as json
except ImportError:
import json
# mypy struggles with conditional imports expressed as catching ImportError:
# https://github.com/python/mypy/issues/1153
import json # type: ignore

from .. import __version__, utils

Expand Down
4 changes: 3 additions & 1 deletion arviz/data/inference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
try:
import ujson as json
except ImportError:
import json
# mypy struggles with conditional imports expressed as catching ImportError:
# https://github.com/python/mypy/issues/1153
import json # type: ignore

SUPPORTED_GROUPS = [
"posterior",
Expand Down
4 changes: 3 additions & 1 deletion arviz/data/io_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import ujson as json
except ImportError:
# Can't find ujson using json
import json
# mypy struggles with conditional imports expressed as catching ImportError:
# https://github.com/python/mypy/issues/1153
import json # type: ignore


def from_json(filename):
Expand Down
4 changes: 3 additions & 1 deletion arviz/data/io_pystan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import ujson as json
except ImportError:
# Can't find ujson using json
import json
# mypy struggles with conditional imports expressed as catching ImportError:
# https://github.com/python/mypy/issues/1153
import json # type: ignore


class PyStanConverter:
Expand Down
2 changes: 1 addition & 1 deletion arviz/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def check_multiple_attrs(
in ``sample_stats``, also against what was expected.
"""
failed_attrs = []
failed_attrs: List[Union[str, Tuple[str, str]]] = []
for dataset_name, attributes in test_dict.items():
if dataset_name.startswith("~"):
if hasattr(parent, dataset_name[1:]):
Expand Down

0 comments on commit 910e781

Please sign in to comment.