Am 23.08.2020 um 10:05 schrieb info(a)gno.de:
Digging a bit more. I guess you are still using Python 2. There was a change made in
3.0.30190430 due to T219095 which expects unicode strings for categoryFormat but
'B' is a str in Python 2. Either you have to use the u prefix like u'B' or
you have to add this line on top of your scripts:
from __future__ Import unicode_literals
By the way the last release supporting Python 2 is 3.0.20200703.
Best
xqt
>> Am 23.08.2020 um 08:38 schrieb info(a)gno.de:
>>
> Hi Jean-Frederic,
>
> strings are allowed for the textlib.categoryFormat. But are you trying to run
pywikibot 4.0+ with Python 2? The related code line is
> xqt e4115af 2020-07-24 11:31:05 +0200 [diff] [blame] 1539 if
isinstance(category, str)
> Obviously this check fails for your given 'B'.
>
> Best
> xqt
>
>>> Am 22.08.2020 um 14:32 schrieb Maarten Dammers <maarten(a)mdammers.nl>nl>:
>>>
>>
>> Hi Jean-Frédéric,
>>
>> I see new_categories = ["B"] in your code. I believe this should be a
list of Category objects, not a list of strings.
>>
>> Maarten
>>
>> On 19-08-2020 21:48, Jean-Frédéric wrote:
>>> Hi,
>>>
>>> In the heritage repo [1], I have pywikibot pinned to 3.0.20180823.
>>>
>>> Upgrading to latest version leads to two of my unit tests to fail [2]
>>> (I’m not 100% sure, but I do believe the same errors popped up last time I
tried upgrading in August 2019.)
>>>
>>> The unit tests are at [3], the method tested at [4], and the stack trace at
[5].
>>>
>>> I have been digging a bit in the git history to understand what happened
between August 2018 and August 2019 / August 2020 in textlib but nothing jumped.
>>>
>>> Would anyone know what the change is caused by, and how I should update my
code?
>>>
>>> Thanks!
>>>
>>> [1]
https://phabricator.wikimedia.org/diffusion/THER/
>>> [2]
https://integration.wikimedia.org/ci/job/labs-tools-heritage-tox-docker/509…
>>> [3]
https://phabricator.wikimedia.org/diffusion/THER/browse/master/tests/test_c…
>>> [4]
https://phabricator.wikimedia.org/diffusion/THER/browse/master/erfgoedbot/c…
>>> [5] Stack trace:
>>> ```
>>> File "/src/erfgoedbot/categorize_images.py", line 263, in
replace_default_cat_with_new_categories_in_image_text
>>> page_text_without_base_category, new_categories, addOnly=True)
>>> File
"/src/.tox/py27/lib/python2.7/site-packages/pywikibot/textlib.py", line 1459, in
replaceCategoryLinks
>>> new_cats = categoryFormat(new, insite=site)
>>> File
"/src/.tox/py27/lib/python2.7/site-packages/pywikibot/textlib.py", line 1552, in
categoryFormat
>>> category = pywikibot.Category(category)
>>> File
"/src/.tox/py27/lib/python2.7/site-packages/pywikibot/tools/__init__.py", line
1819, in wrapper
>>> return obj(*__args, **__kw)
>>> File
"/src/.tox/py27/lib/python2.7/site-packages/pywikibot/page/__init__.py", line
2879, in __init__
>>> Page.__init__(self, source, title, ns=14)
>>> File
"/src/.tox/py27/lib/python2.7/site-packages/pywikibot/tools/__init__.py", line
1819, in wrapper
>>> return obj(*__args, **__kw)
>>> File
"/src/.tox/py27/lib/python2.7/site-packages/pywikibot/page/__init__.py", line
2392, in __init__
>>> super(Page, self).__init__(source, title, ns)
>>> File
"/src/.tox/py27/lib/python2.7/site-packages/pywikibot/page/__init__.py", line
221, in __init__
>>> .format(type(source), source))
>>> Error: Invalid argument type '<type 'str'>' in Page
initializer: B
>>> ```
>>> --
>>> Jean-Frédéric
>>>
>>>
>>> _______________________________________________
>>> pywikibot mailing list
>>> pywikibot(a)lists.wikimedia.org
>>>
https://lists.wikimedia.org/mailman/listinfo/pywikibot
>> _______________________________________________
>> pywikibot mailing list
>> pywikibot(a)lists.wikimedia.org
>>
https://lists.wikimedia.org/mailman/listinfo/pywikibot