Skip to content

Commit 9ef172d

Browse files
committed
Add some typings informations and typecheck
Mostly make it a bit clearer what is allowed/expected where. In particular many of the decode fucntions allow already decoded objects.
1 parent 5bf61ef commit 9ef172d

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ matrix:
3333
- python: 3.8
3434
dist: xenial
3535
sudo: true
36+
env: MYPY_CHECK='true'
3637

3738
before_install:
3839
- docker pull arafato/azurite
@@ -42,11 +43,12 @@ before_script:
4243
- mongo mydb_test --eval 'db.createUser({user:"travis",pwd:"test",roles:["readWrite"]});'
4344

4445
install:
45-
- pip install -U pip setuptools wheel tox-travis coveralls
46+
- pip install -U pip setuptools wheel tox-travis coveralls mypy
4647

4748
script:
4849
- tox
4950
- if [[ $BUILD_DOCS == 'true' ]]; then tox -e docs; fi
51+
- if [[ $MYPY_CHECK == 'true' ]]; then mypy zarr; fi
5052

5153
after_success:
5254
- coveralls --service=travis-pro

mypy.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[mypy]
2+
python_version = 3.6
3+
ignore_missing_imports = True
4+
follow_imports = silent

zarr/codecs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
22
# flake8: noqa
33
from numcodecs import *
4+
from numcodecs import get_codec, Blosc, Zlib, Delta, AsType, BZ2
45
from numcodecs.registry import codec_registry

zarr/meta.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
from zarr.errors import MetadataError
88
from zarr.util import json_dumps, json_loads
99

10+
from typing import Union, Any
11+
1012
ZARR_FORMAT = 2
1113

1214

13-
def parse_metadata(s):
15+
def parse_metadata(s: Union[Mapping, str]) -> Mapping[str, Any]:
1416

1517
# Here we allow that a store may return an already-parsed metadata object,
1618
# or a string of JSON that we will parse here. We allow for an already-parsed
@@ -28,7 +30,7 @@ def parse_metadata(s):
2830
return meta
2931

3032

31-
def decode_array_metadata(s):
33+
def decode_array_metadata(s: Union[Mapping, str]) -> Mapping[str, Any]:
3234
meta = parse_metadata(s)
3335

3436
# check metadata format
@@ -56,7 +58,7 @@ def decode_array_metadata(s):
5658
return meta
5759

5860

59-
def encode_array_metadata(meta):
61+
def encode_array_metadata(meta: Mapping[str, Any]) -> str:
6062
dtype = meta['dtype']
6163
sdshape = ()
6264
if dtype.subdtype is not None:
@@ -74,7 +76,7 @@ def encode_array_metadata(meta):
7476
return json_dumps(meta)
7577

7678

77-
def encode_dtype(d):
79+
def encode_dtype(d) -> str:
7880
if d.fields is None:
7981
return d.str
8082
else:

0 commit comments

Comments
 (0)