22
33import logging
44from copy import copy
5- from typing import TYPE_CHECKING , Any , Dict , List , Optional , Type , Union
5+ from typing import TYPE_CHECKING , Any
66
77from wikibaseintegrator import wbi_fastrun
88from wikibaseintegrator .datatypes import BaseDataType
2020
2121class 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 :
0 commit comments