Skip to content

Commit

Permalink
Clarify typing for Wikibase write methods
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matejsuchanek committed Oct 11, 2023
1 parent 9a52cdf commit b054b02
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pywikibot/page/_wikibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1114,15 +1116,16 @@ 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.
A site can either be a Site object, or it can be a dbName.
"""
self.removeSitelinks([site], **kwargs)

def removeSitelinks(self, sites, **kwargs) -> None:
def removeSitelinks(self, sites: List[LANGUAGE_IDENTIFIER], **kwargs
) -> None:
"""
Remove sitelinks.
Expand Down

0 comments on commit b054b02

Please sign in to comment.