Page MenuHomePhabricator

WbQuantity now expects a 'site' parameter
Closed, ResolvedPublic

Description

Now when writing statements to wd using pwb I get

WbQuantity now expects a 'site' parameter. This is needed to ensure correct handling of error bounds.
Unspecified exception raised. Waiting 1 minute.
^CTraceback (most recent call last):
  File "elobot.py", line 109, in bot
    elo_claim.setTarget(pwb.WbQuantity(rating))
  File "/core/pywikibot/__init__.py", line 680, in __init__
    self.upperBound = self.amount + upperError
UnboundLocalError: local variable 'upperError' referenced before assignment

Running

Pywikibot: [ssh] pywikibot-core.git (f94a8e9, g7635, 2016/11/27, 02:42:43, n/a)
Release version: 3.0-dev
requests version: 2.12.1
Python 3.5.2

Event Timeline

I believe there is other issue here. The

WbQuantity now expects a 'site' parameter. This is needed to ensure correct handling of error bounds.

is just a warning. After this warning code goes here:

if error is None:
    self.upperBound = self.lowerBound = Decimal(0)
elif isinstance(error, tuple):
    upperError = self._todecimal(error[0])
    lowerError = self._todecimal(error[1])
else:
    upperError = lowerError = self._todecimal(error)

self.upperBound = self.amount + upperError
self.lowerBound = self.amount - lowerError

as You can see at the end we have 2 assigments that use upperError and lowerError, but in 3-way if-stattement above we set these 2 variables only in elif, first if doesn't set any of these variables and else sets only upperError.

I occurs that Your code @Wesalius went through if error is None: path so there is no local upperError defined.

According to comment of @Lokal_Profil at T151706 I have to wait for the patch to be merged or modify the code. I am a coding dilettante, so I guess I will first try my luck with the upcoming patch and then try to fix my code. Thank you for taking a look at it, @Magul.

The default has now changed (see T150210) so that you only need the site parameter on older Wikibase installations. I.e. you don't need it on Wikidata. So running the latest version of the master branch should resolve the issue.

Now I still get the warning but I can proceed to edit wd without a problem.

Now I still get the warning but I can proceed to edit wd without a problem.

True. It will still ask for it but if it can't find it it will assume that you are running on a newer Wikibase (i.e. on Wikidata).

Okay thanks. From my POV it is resolved, feel free to close the bug whenever.

Lokal_Profil claimed this task.