Topic on Manual talk:Pywikibot

removing references from wikidata doesn't work

5
Summary by Soued031

false alarm

Soued031 (talkcontribs)

Hello, I found a bug in pywikibot but I am not sure if I use the method correctly. Deleting a reference does not seem to work. I'm using the last version from git. If you want I have a fix, but since I cannot find any documentation about pywikibot or an explanation of how a method should be written the fix seems out of place. Link with diff and the code that I'm right now using to modify wikidata: https://drive.google.com/drive/folders/1SgQym9-Gv0FGKw8tUuUyDEIIViEN_Eak?usp=sharing

Matěj Suchánek (talkcontribs)

The docstring of Claim.removeSources says: @type sources: list of pywikibot.Claim, which item.claims['P1082'][i].sources is not. That is a list of key: list of pywikibot.Claim mappings.

Soued031 (talkcontribs)

Thanks for you answer! So how does the code need to be changed as I haven't seen any example of removeSource(s)?I mean I understand that the type is wrong but how do I achieve the "right" type?

Matěj Suchánek (talkcontribs)

I hope this will work (it should remove all references attached to a statement):

sources = []
for source in claim.sources:
    for value in source.values():
        sources.extend(value)
item.removeSources(sources)
Soued031 (talkcontribs)

Thanks a lot your code snippet works!