This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fix flake8 warning F841: local variable ... is assigned to but never used
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, dstufft, eric.araujo, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2017-11-28 14:03 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4608 merged vstinner, 2017-11-28 14:05
PR 4610 closed python-dev, 2017-11-28 14:31
PR 4618 merged vstinner, 2017-11-28 20:58
PR 4619 merged vstinner, 2017-11-28 21:04
Messages (10)
msg307120 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-28 14:03
Using flake8, I found some bugs in the standard libraries and tools.

I already fixed another flake8 error:
---
commit 28e61650b23119b68cd7943ccc01b8b9af1b4103
Author: Victor Stinner <victor.stinner@gmail.com>
Date:   Tue Nov 28 00:34:08 2017 +0100

    bpo-31245: asyncio: Fix typo, isistance => isinstance (#4594)
---

Attached patch fix 3 bugs found by the flake8 F841 warning.

Note: Python 2.7 is not impacted by the turtledemo bug, but it's impacted by the two other bugs.
msg307123 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-28 14:30
New changeset 696b501cd11dc429a0f661adeb598bfaf89e4112 by Victor Stinner in branch 'master':
bpo-32155: Bugfixes found by flake8 F841 warnings (#4608)
https://github.com/python/cpython/commit/696b501cd11dc429a0f661adeb598bfaf89e4112
msg307124 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-28 14:40
If you have replaced self.DEFAULT_REALM with realm why not replace self.DEFAULT_REPOSITORY with repository?

I don't know what is correct. Added distutils experts for review.
msg307125 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-28 15:04
> If you have replaced self.DEFAULT_REALM with realm why not replace self.DEFAULT_REPOSITORY with repository?

Oh, I didn't notice that there is also a repository variable which is not used in all code paths.

> I don't know what is correct. Added distutils experts for review.

Now I'm not sure that my realm change is correct.
msg307128 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-11-28 15:23
I don't think distutils changes are correct.

    ('realm', self.DEFAULT_REALM)

'realm' is the config name and 'self.DEFAULT_REALM' is its default value. In the 'for key, default in ...:' loop,

1. It checks if it's already set in the config file
2. Sets its value to 'current' if it does
3. If it doesn't, uses self.DEFAULT_REALM

distutils sets default values for undefined options via 'finalize_options' methods and there is the following command in 'PyPIRCCommand.finalize_options()' method:

    if self.realm is None:
        self.realm = self.DEFAULT_REALM

So unless there is a user set value for the 'realm' option (see the 'upload' and 'register' commands), 'self.realm' equals to 'self.DEFAULT_REALM'.

I'd remove the following code instead:

    realm = self.realm or self.DEFAULT_REALM
msg307144 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2017-11-28 16:33
The best course of action would be to revert the distutils changes.

There are a handful of tickets related to register/upload commands, which are funky commands with their own config file not 100% in line with other distutils commands.  Changes in that code need tests.
msg307168 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-28 21:00
I proposed PR 4618 to revert the distutils.config changes.
msg307177 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-28 22:04
New changeset 6979fcdc91114b1ccb16345e26734d6df4cccbc3 by Victor Stinner in branch '3.6':
bpo-32155: Bugfixes found by flake8 F841 warnings (#4619)
https://github.com/python/cpython/commit/6979fcdc91114b1ccb16345e26734d6df4cccbc3
msg307179 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-28 22:19
New changeset 71bd588646b282c9eebc390b31184a5bdb54e712 by Victor Stinner in branch 'master':
bpo-32155: Revert distutils.config change (#4618)
https://github.com/python/cpython/commit/71bd588646b282c9eebc390b31184a5bdb54e712
msg307180 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-28 22:23
The main bugs have been fixed in Python 3.6 and 3.7 (master).

Python 2.7 only has the bug in Tools/scripts/treesync.py, but I don't think that it's worth it to fix this old script in the stable 2.7 branch. I just removed this script from the master branch (bpo-32159).
History
Date User Action Args
2022-04-11 14:58:54adminsetgithub: 76336
2017-11-28 22:23:18vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg307180

stage: patch review -> resolved
2017-11-28 22:19:28vstinnersetmessages: + msg307179
2017-11-28 22:04:14vstinnersetmessages: + msg307177
2017-11-28 21:04:24vstinnersetpull_requests: + pull_request4533
2017-11-28 21:00:34vstinnersetmessages: + msg307168
2017-11-28 20:58:34vstinnersetpull_requests: + pull_request4532
2017-11-28 16:33:11eric.araujosetmessages: + msg307144
2017-11-28 15:23:29berker.peksagsetnosy: + berker.peksag
messages: + msg307128
2017-11-28 15:04:34vstinnersetmessages: + msg307125
2017-11-28 14:40:58serhiy.storchakasetnosy: + eric.araujo, serhiy.storchaka, dstufft
messages: + msg307124
2017-11-28 14:31:42python-devsetpull_requests: + pull_request4526
2017-11-28 14:30:34vstinnersetmessages: + msg307123
2017-11-28 14:05:23vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request4524
2017-11-28 14:03:17vstinnercreate