From b054b020180c276321e49d0ff1d0360d5b48db90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Wed, 11 Oct 2023 11:14:58 +0200 Subject: [PATCH] Clarify typing for Wikibase write methods The type for WikibaseEntity.editEntity(data) was incorrect. Data is either None, or always dict with strings as keys. The values can be a union of the other types. Change-Id: I09e7206222b9f89afc24fe74905bb81c0e52d0d7 --- pywikibot/page/_wikibase.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py index 5141e0033c..c0530eb366 100644 --- a/pywikibot/page/_wikibase.py +++ b/pywikibot/page/_wikibase.py @@ -64,10 +64,12 @@ ) -ALIASES_TYPE = Dict[Union[str, pywikibot.APISite], List[str]] -LANGUAGE_TYPE = Dict[Union[str, pywikibot.APISite], str] +LANGUAGE_IDENTIFIER = Union[str, pywikibot.APISite] +ALIASES_TYPE = Dict[LANGUAGE_IDENTIFIER, List[str]] +LANGUAGE_TYPE = Dict[LANGUAGE_IDENTIFIER, str] SITELINK_TYPE = Union['pywikibot.page.BasePage', 'pywikibot.page.BaseLink', Dict[str, str]] +ENTITY_DATA_TYPE = Dict[str, Union[LANGUAGE_TYPE, ALIASES_TYPE, SITELINK_TYPE]] class WikibaseEntity: @@ -283,7 +285,7 @@ def get(self, force: bool = False) -> dict: def editEntity( self, - data: Union[LANGUAGE_TYPE, ALIASES_TYPE, SITELINK_TYPE, None] = None, + data: Union[ENTITY_DATA_TYPE, None] = None, **kwargs ) -> None: """Edit an entity using Wikibase ``wbeditentity`` API. @@ -648,7 +650,7 @@ def latest_revision_id(self) -> None: @allow_asynchronous def editEntity( self, - data: Union[LANGUAGE_TYPE, ALIASES_TYPE, SITELINK_TYPE, None] = None, + data: Union[ENTITY_DATA_TYPE, None] = None, **kwargs: Any ) -> None: """Edit an entity using Wikibase ``wbeditentity`` API. @@ -1114,7 +1116,7 @@ def setSitelink(self, sitelink: SITELINK_TYPE, **kwargs) -> None: """ self.setSitelinks([sitelink], **kwargs) - def removeSitelink(self, site, **kwargs) -> None: + def removeSitelink(self, site: LANGUAGE_IDENTIFIER, **kwargs) -> None: """ Remove a sitelink. @@ -1122,7 +1124,8 @@ def removeSitelink(self, site, **kwargs) -> None: """ self.removeSitelinks([site], **kwargs) - def removeSitelinks(self, sites, **kwargs) -> None: + def removeSitelinks(self, sites: List[LANGUAGE_IDENTIFIER], **kwargs + ) -> None: """ Remove sitelinks.