PyCQA / PyCQA/pyflakes

Treat global dunder names as always used

Open
#387 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
190
Avg merge
8m
Merged PRs (30d)
13

Description

When using a package versioning helper such as setuptools_scm, it is quite natural to write, in a package's toplevel __init__.py, something like

from ._version import version as __version__

(assuming one uses setuptools_scm's write_to option rather than pkg_resources, as the latter can be quite slow).

Currently, pyflakes complains that __version__ is an unused name. Obviously, one can placate pyflakes by writing (over two lines) from . import _version; __version__ = _version.version, but that seems a bit silly: I would instead suggest that pyflakes consider all global-level dunders as automatically used (in the sense "they have a special or metadata role anyways"), even if they appear not so.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the warning with the package-level init.py example and inspect how pyflakes marks global names as used. Done means the version import no longer reports an unused-name warning while ordinary unused globals still do, with coverage in the relevant existing tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.