pylint W0621 unused variable warning due to use of locals()

Bug #1650816 reported by Stu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack DBaaS (Trove)
New
Wishlist
Unassigned

Bug Description

Would the team be open to a patch to remove the use of locals(), which causes a pylint W0621 warning, as an example, this:

    def list_access(self, instance, username, hostname=None):
        """Show all databases the given user has access to."""
        instance_id = base.getid(instance)
        user = common.quote_user_host(username, hostname)
        url = "/instances/%(instance_id)s/users/%(user)s/databases"
        local_vars = locals()
        resp, body = self.api.client.get(url % local_vars)
        common.check_for_exceptions(resp, body, url)
        if not body:
            raise Exception("Call to %s did not return to a body" % url)
        return [databases.Database(self, db) for db in body['databases']]

...could become:

    def list_access(self, instance, username, hostname=None):
        """Show all databases the given user has access to."""
        instance_id = base.getid(instance)
        user = common.quote_user_host(username, hostname)
        url = "/instances/{i}/users/{u}/databases".format(i=instance_id, u=user)
        resp, body = self.api.client.get(url)
        common.check_for_exceptions(resp, body, url)
        if not body:
            raise Exception("Call to {u} did not return to a body".format(u=url))
        return [databases.Database(self, db) for db in body['databases']]

Perhaps there is some good reason for the current approach, which I've been unable to grasp.

I'd be grateful for feedback, happy to work on a patch if it is thought useful.

Revision history for this message
Amrith Kumar (amrith) wrote :

Sure, please submit a patch. But please also consider the following before you do.

trove runs pylint on the code base as part of every commit; see tools/trove-pylint. But, we currently do not look for warnings; pylint is run with -E.

If you'd like to fix this bug, then you will notice that there are 5081 warnings which we currently ignore (because of -E) and the warning W0621 occurs 19 times.

Speaking only for myself, the patch you submit is most welcome if it includes some tooling (such as a change to the pylint tool that we do run) to prevent the same error from creeping back into the code base, and a good reason why this particular warning (which occurs 19 times) is worthy of special treatment over the 5081 warnings that we ignore along with the many errors which we also ignore.

As to why the code is this way, I didn't look.

Amrith Kumar (amrith)
Changed in trove:
importance: Undecided → Wishlist
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.