Skip to content

Commit 4f2bcee

Browse files
authored
Upgrade to Python 3.8 (#558)
With "pyup-dirs --py38-plus --recursive ..."
1 parent 9e326de commit 4f2bcee

25 files changed

+240
-256
lines changed

.github/workflows/python-pytest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
strategy:
2929
matrix:
30-
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11', '3.12-dev' ]
30+
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12-dev' ]
3131

3232
steps:
3333
- uses: actions/checkout@v3.5.3

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The main differences between these two libraries are :
6868
* A complete rewrite of the library with a more object-oriented architecture allowing for easy interaction, data
6969
validation and extended functionality
7070
* Add support for reading and writing Lexeme, MediaInfo and Property entities
71-
* Python 3.7 to 3.11 support, validated with unit tests
71+
* Python 3.8 to 3.11 support, validated with unit tests
7272
* Type hints implementation for arguments and return, checked with mypy static type checker
7373
* Add OAuth 2.0 login method
7474
* Add logging module support
@@ -95,7 +95,7 @@ Here is a list of different projects that use the library:
9595
# Installation #
9696

9797
The easiest way to install WikibaseIntegrator is to use the `pip` package manager. WikibaseIntegrator supports Python
98-
3.7 and above. If Python 2 is installed, `pip` will lead to an error indicating missing dependencies.
98+
3.8 and above. If Python 2 is installed, `pip` will lead to an error indicating missing dependencies.
9999

100100
```bash
101101
python -m pip install wikibaseintegrator

docs/source/conf.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# If extensions (or modules to document with autodoc) are in another directory,
43
# add these directories to sys.path here. If the directory is relative to the
@@ -44,18 +43,18 @@
4443
master_doc = 'index'
4544

4645
# General information about the project.
47-
project = u'WikibaseIntegrator'
48-
copyright = u'%d, LeMyst' % datetime.now().year
49-
author = u'LeMyst and WikibaseIntegrator contributors'
46+
project = 'WikibaseIntegrator'
47+
copyright = f'{datetime.now().year}, LeMyst'
48+
author = 'LeMyst and WikibaseIntegrator contributors'
5049

5150
# The version info for the project you're documenting, acts as replacement for
5251
# |version| and |release|, also used in various other places throughout the
5352
# built documents.
5453
#
5554
# The short X.Y version.
56-
version = u'0.12.5.dev0'
55+
version = '0.12.5.dev0'
5756
# The full version, including alpha/beta/rc tags.
58-
release = u'0.12.5.dev0'
57+
release = '0.12.5.dev0'
5958

6059
# The language for content autogenerated by Sphinx. Refer to documentation
6160
# for a list of supported languages.

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ long_description_content_type = text/markdown
1616
platform = any
1717
classifiers =
1818
Programming Language :: Python
19-
Programming Language :: Python :: 3.7
2019
Programming Language :: Python :: 3.8
2120
Programming Language :: Python :: 3.9
2221
Programming Language :: Python :: 3.10
@@ -41,7 +40,7 @@ install_requires =
4140
requests>=2.27.1,<2.29.0
4241
requests-oauthlib~=1.3.1
4342
ujson>=5.4,<5.6
44-
python_requires = >=3.7, <3.13
43+
python_requires = >=3.8, <3.13
4544

4645
[options.extras_require]
4746
dev =

wikibaseintegrator/datatypes/basedatatype.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import re
4-
from typing import Any, List, Optional, Type, Union
4+
from typing import Any
55

66
from wikibaseintegrator.models import Claim
77

@@ -11,15 +11,15 @@ class BaseDataType(Claim):
1111
The base class for all Wikibase data types, they inherit from it
1212
"""
1313
DTYPE = 'base-data-type'
14-
subclasses: List[Type[BaseDataType]] = []
14+
subclasses: list[type[BaseDataType]] = []
1515
sparql_query: str = '''
1616
SELECT * WHERE {{
1717
?item_id <{wb_url}/prop/{pid}> ?s .
1818
?s <{wb_url}/prop/statement/{pid}> '{value}' .
1919
}}
2020
'''
2121

22-
def __init__(self, prop_nr: Optional[Union[int, str]] = None, **kwargs: Any):
22+
def __init__(self, prop_nr: int | str | None = None, **kwargs: Any):
2323
"""
2424
Constructor, will be called by all data types.
2525
@@ -36,7 +36,7 @@ def __init_subclass__(cls, **kwargs):
3636
super().__init_subclass__(**kwargs)
3737
cls.subclasses.append(cls)
3838

39-
def set_value(self, value: Optional[Any] = None):
39+
def set_value(self, value: Any | None = None):
4040
pass
4141

4242
def get_sparql_value(self) -> str:

wikibaseintegrator/entities/baseentity.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import logging
44
from copy import copy
5-
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, Union
5+
from typing import TYPE_CHECKING, Any
66

77
from wikibaseintegrator import wbi_fastrun
88
from wikibaseintegrator.datatypes import BaseDataType
@@ -20,10 +20,10 @@
2020

2121
class BaseEntity:
2222
ETYPE = 'base-entity'
23-
subclasses: List[Type[BaseEntity]] = []
23+
subclasses: list[type[BaseEntity]] = []
2424

25-
def __init__(self, api: Optional['WikibaseIntegrator'] = None, title: Optional[str] = None, pageid: Optional[int] = None, lastrevid: Optional[int] = None,
26-
type: Optional[str] = None, id: Optional[str] = None, claims: Optional[Claims] = None, is_bot: Optional[bool] = None, login: Optional[_Login] = None):
25+
def __init__(self, api: WikibaseIntegrator | None = None, title: str | None = None, pageid: int | None = None, lastrevid: int | None = None, type: str | None = None,
26+
id: str | None = None, claims: Claims | None = None, is_bot: bool | None = None, login: _Login | None = None):
2727
if not api:
2828
from wikibaseintegrator import WikibaseIntegrator
2929
self.api = WikibaseIntegrator()
@@ -57,30 +57,30 @@ def api(self, value: WikibaseIntegrator):
5757
self.__api = value
5858

5959
@property
60-
def title(self) -> Optional[str]:
60+
def title(self) -> str | None:
6161
return self.__title
6262

6363
@title.setter
64-
def title(self, value: Optional[str]):
64+
def title(self, value: str | None):
6565
self.__title = value
6666

6767
@property
68-
def pageid(self) -> Union[str, int, None]:
68+
def pageid(self) -> str | int | None:
6969
return self.__pageid
7070

7171
@pageid.setter
72-
def pageid(self, value: Union[str, int, None]):
72+
def pageid(self, value: str | int | None):
7373
if isinstance(value, str):
74-
self.__pageid: Union[str, int, None] = int(value)
74+
self.__pageid: str | int | None = int(value)
7575
else:
7676
self.__pageid = value
7777

7878
@property
79-
def lastrevid(self) -> Optional[int]:
79+
def lastrevid(self) -> int | None:
8080
return self.__lastrevid
8181

8282
@lastrevid.setter
83-
def lastrevid(self, value: Optional[int]):
83+
def lastrevid(self, value: int | None):
8484
self.__lastrevid = value
8585

8686
@property
@@ -92,11 +92,11 @@ def type(self, value: str):
9292
self.__type = value
9393

9494
@property
95-
def id(self) -> Optional[str]:
95+
def id(self) -> str | None:
9696
return self.__id
9797

9898
@id.setter
99-
def id(self, value: Optional[str]):
99+
def id(self, value: str | None):
100100
self.__id = value
101101

102102
@property
@@ -109,7 +109,7 @@ def claims(self, value: Claims):
109109
raise TypeError
110110
self.__claims = value
111111

112-
def add_claims(self, claims: Union[Claim, List[Claim], Claims], action_if_exists: ActionIfExists = ActionIfExists.APPEND_OR_REPLACE) -> BaseEntity:
112+
def add_claims(self, claims: Claim | list[Claim] | Claims, action_if_exists: ActionIfExists = ActionIfExists.APPEND_OR_REPLACE) -> BaseEntity:
113113
"""
114114
115115
:param claims: A Claim, list of Claim or just a Claims object to add to this Claims object.
@@ -125,13 +125,13 @@ def add_claims(self, claims: Union[Claim, List[Claim], Claims], action_if_exists
125125

126126
return self
127127

128-
def get_json(self) -> Dict[str, Union[str, Dict[str, List]]]:
128+
def get_json(self) -> dict[str, str | dict[str, list]]:
129129
"""
130130
To get the dict equivalent of the JSON representation of the entity.
131131
132132
:return:
133133
"""
134-
json_data: Dict = {
134+
json_data: dict = {
135135
'type': self.type,
136136
'claims': self.claims.get_json()
137137
}
@@ -140,7 +140,7 @@ def get_json(self) -> Dict[str, Union[str, Dict[str, List]]]:
140140

141141
return json_data
142142

143-
def from_json(self, json_data: Dict[str, Any]) -> BaseEntity:
143+
def from_json(self, json_data: dict[str, Any]) -> BaseEntity:
144144
"""
145145
Import a dictionary into BaseEntity attributes.
146146
@@ -163,8 +163,7 @@ def from_json(self, json_data: Dict[str, Any]) -> BaseEntity:
163163
return self
164164

165165
# noinspection PyMethodMayBeStatic
166-
def _get(self, entity_id: str, login: Optional[_Login] = None, allow_anonymous: bool = True, is_bot: Optional[bool] = None,
167-
**kwargs: Any) -> Dict: # pylint: disable=no-self-use
166+
def _get(self, entity_id: str, login: _Login | None = None, allow_anonymous: bool = True, is_bot: bool | None = None, **kwargs: Any) -> dict: # pylint: disable=no-self-use
168167
"""
169168
Retrieve an entity in json representation from the Wikibase instance
170169
@@ -187,7 +186,7 @@ def _get(self, entity_id: str, login: Optional[_Login] = None, allow_anonymous:
187186

188187
return mediawiki_api_call_helper(data=params, login=login, allow_anonymous=allow_anonymous, is_bot=is_bot, **kwargs)
189188

190-
def clear(self, **kwargs: Any) -> Dict[str, Any]:
189+
def clear(self, **kwargs: Any) -> dict[str, Any]:
191190
"""
192191
Use the `clear` parameter of `wbeditentity` API call to clear the content of the entity.
193192
The entity will be updated with an empty dictionary.
@@ -197,8 +196,8 @@ def clear(self, **kwargs: Any) -> Dict[str, Any]:
197196
"""
198197
return self._write(data={}, clear=True, **kwargs)
199198

200-
def _write(self, data: Optional[Dict] = None, summary: Optional[str] = None, login: Optional[_Login] = None, allow_anonymous: bool = False, limit_claims: Optional[List[Union[str, int]]] = None, clear: bool = False, as_new: bool = False,
201-
is_bot: Optional[bool] = None, **kwargs: Any) -> Dict[str, Any]:
199+
def _write(self, data: dict | None = None, summary: str | None = None, login: _Login | None = None, allow_anonymous: bool = False, limit_claims: list[str | int] | None = None,
200+
clear: bool = False, as_new: bool = False, is_bot: bool | None = None, **kwargs: Any) -> dict[str, Any]:
202201
"""
203202
Writes the entity JSON to the Wikibase instance and after successful write, returns the "entity" part of the response.
204203
@@ -249,7 +248,7 @@ def _write(self, data: Optional[Dict] = None, summary: Optional[str] = None, log
249248

250249
return json_result['entity']
251250

252-
def delete(self, login: Optional[_Login] = None, allow_anonymous: bool = False, is_bot: Optional[bool] = None, **kwargs: Any):
251+
def delete(self, login: _Login | None = None, allow_anonymous: bool = False, is_bot: bool | None = None, **kwargs: Any):
253252
"""
254253
Delete the current entity. Use the pageid first if available and fallback to the page title.
255254
@@ -276,7 +275,7 @@ def delete(self, login: Optional[_Login] = None, allow_anonymous: bool = False,
276275

277276
return delete_page(title=None, pageid=self.pageid, login=login, allow_anonymous=allow_anonymous, is_bot=is_bot, **kwargs)
278277

279-
def write_required(self, base_filter: Optional[List[BaseDataType | List[BaseDataType]]] = None, action_if_exists: ActionIfExists = ActionIfExists.REPLACE_ALL,
278+
def write_required(self, base_filter: list[BaseDataType | list[BaseDataType]] | None = None, action_if_exists: ActionIfExists = ActionIfExists.REPLACE_ALL,
280279
**kwargs: Any) -> bool:
281280
fastrun_container = wbi_fastrun.get_fastrun_container(base_filter=base_filter, **kwargs)
282281

@@ -292,7 +291,7 @@ def write_required(self, base_filter: Optional[List[BaseDataType | List[BaseData
292291

293292
return fastrun_container.write_required(data=claims_to_check, cqid=self.id, action_if_exists=action_if_exists)
294293

295-
def get_entity_url(self, wikibase_url: Optional[str] = None) -> str:
294+
def get_entity_url(self, wikibase_url: str | None = None) -> str:
296295
from wikibaseintegrator.wbi_config import config
297296
wikibase_url = wikibase_url or str(config['WIKIBASE_URL'])
298297
if wikibase_url and self.id:

wikibaseintegrator/entities/item.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import re
4-
from typing import Any, Dict, Optional, Union
4+
from typing import Any
55

66
from wikibaseintegrator.entities.baseentity import BaseEntity
77
from wikibaseintegrator.models import LanguageValues
@@ -14,7 +14,7 @@
1414
class ItemEntity(BaseEntity):
1515
ETYPE = 'item'
1616

17-
def __init__(self, labels: Optional[Labels] = None, descriptions: Optional[Descriptions] = None, aliases: Optional[Aliases] = None, sitelinks: Optional[Sitelinks] = None, **kwargs: Any) -> None:
17+
def __init__(self, labels: Labels | None = None, descriptions: Descriptions | None = None, aliases: Aliases | None = None, sitelinks: Sitelinks | None = None, **kwargs: Any) -> None:
1818
"""
1919
2020
:param api:
@@ -35,7 +35,7 @@ def __init__(self, labels: Optional[Labels] = None, descriptions: Optional[Descr
3535
self.sitelinks = sitelinks or Sitelinks()
3636

3737
@BaseEntity.id.setter # type: ignore
38-
def id(self, value: Union[None, str, int]):
38+
def id(self, value: None | str | int):
3939
if isinstance(value, str):
4040
pattern = re.compile(r'^(?:[a-zA-Z]+:)?Q?([0-9]+)$')
4141
matches = pattern.match(value)
@@ -96,7 +96,7 @@ def sitelinks(self, sitelinks: Sitelinks):
9696
def new(self, **kwargs: Any) -> ItemEntity:
9797
return ItemEntity(api=self.api, **kwargs)
9898

99-
def get(self, entity_id: Optional[Union[str, int]] = None, **kwargs: Any) -> ItemEntity:
99+
def get(self, entity_id: str | int | None = None, **kwargs: Any) -> ItemEntity:
100100
"""
101101
Request the MediaWiki API to get data for the entity specified in argument.
102102
@@ -126,7 +126,7 @@ def get(self, entity_id: Optional[Union[str, int]] = None, **kwargs: Any) -> Ite
126126
json_data = super()._get(entity_id=entity_id, **kwargs)
127127
return ItemEntity(api=self.api).from_json(json_data=json_data['entities'][entity_id])
128128

129-
def get_json(self) -> Dict[str, Union[str, Dict]]:
129+
def get_json(self) -> dict[str, str | dict]:
130130
"""
131131
To get the dict equivalent of the JSON representation of the Item.
132132
@@ -139,7 +139,7 @@ def get_json(self) -> Dict[str, Union[str, Dict]]:
139139
**super().get_json()
140140
}
141141

142-
def from_json(self, json_data: Dict[str, Any]) -> ItemEntity:
142+
def from_json(self, json_data: dict[str, Any]) -> ItemEntity:
143143
super().from_json(json_data=json_data)
144144

145145
self.labels = Labels().from_json(json_data['labels'])

0 commit comments

Comments
 (0)