"Local variable (defined in enclosing scope) referenced before assignment" wording is misleading

オープン
#390 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
tooling

調査の方向性

まず、F823 診断をフォーマットするコードを見つけ、この issue の例および #315 の関連する例とその文言を比較します。メッセージが、内側の名前が外側のスコープの名前をシャドーイングしていることを明確に説明し、外側の変数が代入前に参照されたと言わないようになれば完了です。

索引モデルが issue の本文から書いたものです。

説明

def f():
    x = None
    def g():
        # Programmer forgot to add `nonlocal` here.
        if x is None:
            x = "hello"

foo.py:5:12: F823 local variable 'x' (defined in enclosing scope on line 2) referenced before assignment

But it's not the variable defined on line 2 which is being referenced before assignment, it's the one defined on line 6. The programmer thinks they're using the one on line 2, and the message only reinforces their mistake.

Suggest rephrase to something like (shadowing name from line 2 in enclosing scope).

(There's a similar example in #315 where the enclosing scope was global.)

主要言語
Python
スター
1.5k
フォーク
207
平均マージ
4分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

PyCQA/pyflakes のほかの issue

PyCQA/pyflakes の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。