Proposed changes to pyflakes's traversal code.
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
調査の方向性
まず Checker.handleNode と Checker.getNodeHandler を通るトラバーサルパスを読み、次に issue で提案されている handleFields と visitor の変更を確認します。既存のトラバーサルの動作を、参照されているプロトタイプ PR と比較し、特に順序と _unknown_handler のカバレッジを確認します。完了の条件は、リファクタリングによってトラバーサルの動作が維持され、列挙されたメカニズムが削除され、変更された動作に対するテストがあることです。
索引モデルが issue の本文から書いたものです。
説明
I have spent many happy hours studying pyflakes and its tree traversal methods. This issue proposes several possible simplifications. It's fine with me if you aren't interested.
Overview
All the simplifications follow from these changes:
- Eliminate the
omitand_fieldsOrderkwargs and the_FieldsOrderclass. - Add/change visitors to specify required traversal order.
- Rename the visitors so that the visitor's names are the same as the corresponding Ast nodes.
With these changes, Checker.getNodeHandler becomes:
handler = getattr(self, node.__class__.__name__, self.visit)
handler(node)
There is no need for the _nodeHandlers cache because the new code creates no strings.
Only Checker.handleNode calls getNodeHandler so the code above may as well appear in-line.
Other changes
- Eliminate
iter_child_nodes. - Add a
handleFieldsmethod:
def handleFields(self, node, fields):
"""Visit only the *given* children of node in the given order."""
for field in fields:
child = getattr(node, field, None)
if isinstance(child, list):
for item in child:
if isinstance(item, ast.AST):
self.handleNode(item, node)
elif isinstance(child, ast.AST):
self.handleNode(child, node)
def visit(self, node):
self.visitFields(node._fields) # Or duplicate the code above to eliminate the call.
- Add or change visitors to specify the required traversal order. Examples:
def arguments(self, node):
# Visit all fields except 'defaults' and 'kw_defaults'.
fields = ('posonlyargs', 'args', 'var arg', 'kwonlyargs', 'kwarg')
self.handleFields(node, fields)
def DictComp(self, node):
with self.in_scope(GeneratorScope):
# Order matters.
self.handleFields(node, ('generators', 'key', 'value'))
- Eliminate
Checker._unknown_handler. A new unit test would cover its absence.
Summary
These changes are merely suggestions. You can find the prototype code in the five PRs at ekr-fork-pyflakes.
I'll happily make any changes you like in a real PR.
Eliminating kwargs invariably simplifies and generalizes code. For example, it would be straightforward to subclass the new traversal code. The new visitors increase the traversal's speed and make explicit the required traversal order of the visitor's children.
Edward
- 主要言語
- Python
- スター
- 1.5k
- フォーク
- 205
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 5
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PyCQA/pyflakes のほかの issue
-
F542 is not a crimeオープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 52/100
-
Use of await in a function that is not async should be shown as a syntax error by flake8再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
F821 with Annotated import alias再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
-
needs-triage tooling
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
neilsh/stunt-reel#317 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
TandoorRecipes/recipes#4926 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
PyTomography/PyTomography#431 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
igormcsouza/tether#278 ·
メンテナーはふだん 1 日以内に返信