[go: up one dir, main page]

Page MenuHomePhabricator

Add more fine-grained types for WikidataSPARQLPageGenerator
Open, LowPublicFeature

Description

Feature summary (what you would like to be able to do and where): pywikibot.pagegenerators has a WikidataSPARQLPageGenerator generator that returns either entity pages or normal pages depending on if the site given is a DataSite or just a normal Site.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution): Looking through the code, there are two cases:

Case 1: When the site is a DataSite, it will return an iterator of ItemPages, PropertyPages, and/or LexemePages, depending on the query

Case 2: Where the site is not a DataSite, it will return an iterator of Pages that are the sitelinks of any items that would be returned in Case 1.

This presents a very obvious opportunity for using @typing.overload and making two function type signatures.

Benefits (why should this be implemented?): Static type checkers would now have a much easier time when working with the first case, since there is very little one can do with an item when knowing it's a Page object since you cannot actually manipulate the item.

Event Timeline

I've no glue how this can be done. DataSite is a subclass from BaseSite but how can an overload be done for all site objects which are no DataSite objects? If the site parameter is None the Site type is determined during runtime and can be either DataSite, APISite, DrySite, DryDataSite or any other defined e.g. by Family.interface() method.

I've no glue how this can be done. DataSite is a subclass from BaseSite but how can an overload be done for all site objects which are no DataSite objects? If the site parameter is None the Site type is determined during runtime and can be either DataSite, APISite, DrySite, DryDataSite or any other defined e.g. by Family.interface() method.

In this case, I think we should keep the current behavior if the site parameter is not given. Only when it's provided should we have more specific overloads.

Xqt triaged this task as Low priority.Apr 3 2023, 1:31 PM