From 3d670d28d341f19aaaced35c2e708d49ce921d0d Mon Sep 17 00:00:00 2001 From: David Doukhan Date: Fri, 5 Jul 2024 17:38:40 +0200 Subject: [PATCH 1/5] management of time precision=10 --- wikidata/datavalue.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wikidata/datavalue.py b/wikidata/datavalue.py index 5356a6e..5fed283 100644 --- a/wikidata/datavalue.py +++ b/wikidata/datavalue.py @@ -198,6 +198,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])) From ddb0483179f3e44e0e5f7b8d760119e4b1cce1b7 Mon Sep 17 00:00:00 2001 From: David Doukhan Date: Fri, 5 Jul 2024 17:54:48 +0200 Subject: [PATCH 2/5] tox-pip-version makes the testing fail! --- CONTRIBUTING.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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:: From 2a7ed1675e1ca435721ca46899e3bfe9a9e986ff Mon Sep 17 00:00:00 2001 From: David Doukhan Date: Fri, 5 Jul 2024 18:00:13 +0200 Subject: [PATCH 3/5] update tests for the new precision --- tests/datavalue_test.py | 4 ++-- wikidata/datavalue.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 5fed283..ecf35cd 100644 --- a/wikidata/datavalue.py +++ b/wikidata/datavalue.py @@ -211,7 +211,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 ) From c677b18c73d77831eaf956fd27444f254fc642eb Mon Sep 17 00:00:00 2001 From: David Doukhan Date: Sat, 6 Jul 2024 08:22:40 +0200 Subject: [PATCH 4/5] typing modif to make "tox -e mypy" working --- wikidata/datavalue.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wikidata/datavalue.py b/wikidata/datavalue.py index ecf35cd..c3b83f4 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, Union, Tuple 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): From 25eea551bf2aaeca5ffb7674827311f9699e5351 Mon Sep 17 00:00:00 2001 From: David Doukhan Date: Sat, 6 Jul 2024 08:36:40 +0200 Subject: [PATCH 5/5] flake argument order --- wikidata/datavalue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wikidata/datavalue.py b/wikidata/datavalue.py index c3b83f4..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, Tuple +from typing import TYPE_CHECKING, Any, Mapping, Tuple, Union from .client import Client from .commonsmedia import File