Page MenuHomePhabricator

config: B020 Found for loop that reassigns the iterable it is iterating with each iterable value
Closed, ResolvedPublic

Description

https://integration.wikimedia.org/ci/job/pywikibot-core-tox-docker/18459/console

23:02:00 [208] /src$ /src/.tox/flake8-py38/bin/flake8 --version
23:02:00 4.0.1 (flake8-bugbear: 22.3.20, flake8-colors: 0.1.9, flake8-comprehensions:
23:02:00 3.8.0, flake8-darglint: 1.8.1, flake8-docstrings: 1.6.0, pydocstyle: 6.1.1,
23:02:00 flake8-mock: 0.3, flake8-no-u-prefixed-strings: 0.2, flake8-print: 4.0.0,
23:02:00 flake8-string-format: 0.3.0, flake8-tuple: 0.4.1, flake8_coding: 1.3.2,
23:02:00 flake8_quotes: 3.3.1, mccabe: 0.6.1, naming: 0.12.1, pycodestyle: 2.8.0,
23:02:00 pyflakes: 2.4.0) CPython 3.8.1 on Linux
23:02:00 flake8-py38 run-test: commands[1] | flake8 --doctests
23:02:00 [210] /src$ /src/.tox/flake8-py38/bin/flake8 --doctests
23:02:18 ./pywikibot/config.py: line 434:13: B020 Found for loop that reassigns the iterable it is iterating with each iterable value.
23:02:18 ERROR: InvocationError for command /src/.tox/flake8-py38/bin/flake8 --doctests (exited with code 1)

B020 was added to flake8-bugbear in v22.3.20.

Event Timeline

Change 772317 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [fix] Ignore bugbear B20 issue in config.py

https://gerrit.wikimedia.org/r/772317

The context is wrong. There is not reassignment of the iterable because a property is used. Indeed there is a reassignment of a variable path but this is a wanted behavior:

path = Path(folder_path)
if not is_zipfile(path):
    for path in path.parents:  # find a new path to proceed later
        if is_zipfile(path):
            break
    else:
        raise NotADirectoryError('20', 'Not a directory', folder_path)

zip_file = ZipFile(path)
Xqt triaged this task as High priority.

Change 772317 merged by Xqt:

[pywikibot/core@master] [fix] Ignore bugbear B020 issue in config.py

https://gerrit.wikimedia.org/r/772317