diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 79b8481..7d09234 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -36,7 +36,7 @@ on all of them. The easiest to install ``tox`` is to use ``pip`` [#]_:: - pip install tox tox-pip-version + pip install tox Once you've installed ``tox``, it's very simple to run the test suite on all Python versions this project aims to support:: diff --git a/tests/datavalue_test.py b/tests/datavalue_test.py index b97b06c..9426f43 100644 --- a/tests/datavalue_test.py +++ b/tests/datavalue_test.py @@ -130,11 +130,11 @@ def other_value(**kwargs) -> Dict[str, object]: d(fx_client, datatype, other_value(precision=None)) # precision field is missing for p in range(1, 15): - if p in (7, 9, 11, 14): + if p in (7, 9, 10, 11, 14): continue with raises(DatavalueError): d(fx_client, datatype, other_value(precision=p)) - # precision (other than 7, 9, 11 or 14) is unsupported + # precision (other than 7, 9, 10, 11 or 14) is unsupported def test_decoder_monolingualtext(fx_client: Client): diff --git a/wikidata/datavalue.py b/wikidata/datavalue.py index 5356a6e..f3571e4 100644 --- a/wikidata/datavalue.py +++ b/wikidata/datavalue.py @@ -11,7 +11,7 @@ """ import collections.abc import datetime -from typing import TYPE_CHECKING, Any, Mapping, Union +from typing import TYPE_CHECKING, Any, Mapping, Tuple, Union from .client import Client from .commonsmedia import File @@ -147,6 +147,7 @@ def time(self, client: Client, datavalue: Mapping[str, object]) -> Union[datetime.date, datetime.datetime, + Tuple[int, int], int]: value = datavalue['value'] if not isinstance(value, collections.abc.Mapping): @@ -198,6 +199,9 @@ def time(self, if precision == 9: # The time only specifies the year. return int(time[1:5]) + if precision == 10: + # this time only specifies year and month (no day) + return (int(time[1:5]), int(time[6:8])) if precision == 11: return datetime.date(int(time[1:5]), int(time[6:8]), int(time[9:11])) @@ -208,7 +212,7 @@ def time(self, ).replace(tzinfo=datetime.timezone.utc) else: raise DatavalueError( - '{!r}: time precision other than 7, 9, 11 or 14 is ' + '{!r}: time precision other than 7, 9, 10, 11 or 14 is ' 'unsupported'.format(precision), datavalue )