Skip to content

Commit

Permalink
Upgrade to Python 3.8 (#558)
Browse files Browse the repository at this point in the history
With "pyup-dirs --py38-plus --recursive ..."
  • Loading branch information
LeMyst authored Jun 24, 2023
1 parent 9e326de commit 4f2bcee
Show file tree
Hide file tree
Showing 25 changed files with 240 additions and 256 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

strategy:
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11', '3.12-dev' ]
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12-dev' ]

steps:
- uses: actions/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The main differences between these two libraries are :
* A complete rewrite of the library with a more object-oriented architecture allowing for easy interaction, data
validation and extended functionality
* Add support for reading and writing Lexeme, MediaInfo and Property entities
* Python 3.7 to 3.11 support, validated with unit tests
* Python 3.8 to 3.11 support, validated with unit tests
* Type hints implementation for arguments and return, checked with mypy static type checker
* Add OAuth 2.0 login method
* Add logging module support
Expand All @@ -95,7 +95,7 @@ Here is a list of different projects that use the library:
# Installation #

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

```bash
python -m pip install wikibaseintegrator
Expand Down
11 changes: 5 additions & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -44,18 +43,18 @@
master_doc = 'index'

# General information about the project.
project = u'WikibaseIntegrator'
copyright = u'%d, LeMyst' % datetime.now().year
author = u'LeMyst and WikibaseIntegrator contributors'
project = 'WikibaseIntegrator'
copyright = f'{datetime.now().year}, LeMyst'
author = 'LeMyst and WikibaseIntegrator contributors'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'0.12.5.dev0'
version = '0.12.5.dev0'
# The full version, including alpha/beta/rc tags.
release = u'0.12.5.dev0'
release = '0.12.5.dev0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ long_description_content_type = text/markdown
platform = any
classifiers =
Programming Language :: Python
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Expand All @@ -41,7 +40,7 @@ install_requires =
requests>=2.27.1,<2.29.0
requests-oauthlib~=1.3.1
ujson>=5.4,<5.6
python_requires = >=3.7, <3.13
python_requires = >=3.8, <3.13

[options.extras_require]
dev =
Expand Down
8 changes: 4 additions & 4 deletions wikibaseintegrator/datatypes/basedatatype.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import re
from typing import Any, List, Optional, Type, Union
from typing import Any

from wikibaseintegrator.models import Claim

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

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

def set_value(self, value: Optional[Any] = None):
def set_value(self, value: Any | None = None):
pass

def get_sparql_value(self) -> str:
Expand Down
49 changes: 24 additions & 25 deletions wikibaseintegrator/entities/baseentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from copy import copy
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, Union
from typing import TYPE_CHECKING, Any

from wikibaseintegrator import wbi_fastrun
from wikibaseintegrator.datatypes import BaseDataType
Expand All @@ -20,10 +20,10 @@

class BaseEntity:
ETYPE = 'base-entity'
subclasses: List[Type[BaseEntity]] = []
subclasses: list[type[BaseEntity]] = []

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

@property
def title(self) -> Optional[str]:
def title(self) -> str | None:
return self.__title

@title.setter
def title(self, value: Optional[str]):
def title(self, value: str | None):
self.__title = value

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

@pageid.setter
def pageid(self, value: Union[str, int, None]):
def pageid(self, value: str | int | None):
if isinstance(value, str):
self.__pageid: Union[str, int, None] = int(value)
self.__pageid: str | int | None = int(value)
else:
self.__pageid = value

@property
def lastrevid(self) -> Optional[int]:
def lastrevid(self) -> int | None:
return self.__lastrevid

@lastrevid.setter
def lastrevid(self, value: Optional[int]):
def lastrevid(self, value: int | None):
self.__lastrevid = value

@property
Expand All @@ -92,11 +92,11 @@ def type(self, value: str):
self.__type = value

@property
def id(self) -> Optional[str]:
def id(self) -> str | None:
return self.__id

@id.setter
def id(self, value: Optional[str]):
def id(self, value: str | None):
self.__id = value

@property
Expand All @@ -109,7 +109,7 @@ def claims(self, value: Claims):
raise TypeError
self.__claims = value

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

return self

def get_json(self) -> Dict[str, Union[str, Dict[str, List]]]:
def get_json(self) -> dict[str, str | dict[str, list]]:
"""
To get the dict equivalent of the JSON representation of the entity.
:return:
"""
json_data: Dict = {
json_data: dict = {
'type': self.type,
'claims': self.claims.get_json()
}
Expand All @@ -140,7 +140,7 @@ def get_json(self) -> Dict[str, Union[str, Dict[str, List]]]:

return json_data

def from_json(self, json_data: Dict[str, Any]) -> BaseEntity:
def from_json(self, json_data: dict[str, Any]) -> BaseEntity:
"""
Import a dictionary into BaseEntity attributes.
Expand All @@ -163,8 +163,7 @@ def from_json(self, json_data: Dict[str, Any]) -> BaseEntity:
return self

# noinspection PyMethodMayBeStatic
def _get(self, entity_id: str, login: Optional[_Login] = None, allow_anonymous: bool = True, is_bot: Optional[bool] = None,
**kwargs: Any) -> Dict: # pylint: disable=no-self-use
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
"""
Retrieve an entity in json representation from the Wikibase instance
Expand All @@ -187,7 +186,7 @@ def _get(self, entity_id: str, login: Optional[_Login] = None, allow_anonymous:

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

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

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,
is_bot: Optional[bool] = None, **kwargs: Any) -> Dict[str, Any]:
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,
clear: bool = False, as_new: bool = False, is_bot: bool | None = None, **kwargs: Any) -> dict[str, Any]:
"""
Writes the entity JSON to the Wikibase instance and after successful write, returns the "entity" part of the response.
Expand Down Expand Up @@ -249,7 +248,7 @@ def _write(self, data: Optional[Dict] = None, summary: Optional[str] = None, log

return json_result['entity']

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

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

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

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

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

def get_entity_url(self, wikibase_url: Optional[str] = None) -> str:
def get_entity_url(self, wikibase_url: str | None = None) -> str:
from wikibaseintegrator.wbi_config import config
wikibase_url = wikibase_url or str(config['WIKIBASE_URL'])
if wikibase_url and self.id:
Expand Down
12 changes: 6 additions & 6 deletions wikibaseintegrator/entities/item.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import re
from typing import Any, Dict, Optional, Union
from typing import Any

from wikibaseintegrator.entities.baseentity import BaseEntity
from wikibaseintegrator.models import LanguageValues
Expand All @@ -14,7 +14,7 @@
class ItemEntity(BaseEntity):
ETYPE = 'item'

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

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

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

def get_json(self) -> Dict[str, Union[str, Dict]]:
def get_json(self) -> dict[str, str | dict]:
"""
To get the dict equivalent of the JSON representation of the Item.
Expand All @@ -139,7 +139,7 @@ def get_json(self) -> Dict[str, Union[str, Dict]]:
**super().get_json()
}

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

self.labels = Labels().from_json(json_data['labels'])
Expand Down
Loading

0 comments on commit 4f2bcee

Please sign in to comment.