Decorated Function Should Be Considered Used

オープン
#488 コメント 20 件 リアクション 6 件 担当者 0 名 GitHub で見る

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

評価

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

調査の方向性

この issue ではリポジトリのファイルやテストが指定されていません。まず decorator を使った例と、それと同等の直接呼び出しの例を再現し、次に既存の unused-name および F811 の解析を追跡してください。decorator で修飾された定義が使用済みとして扱われ、真の再定義警告を抑制しない状態になれば完了です。

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

説明

Functions with a decorator are considered unused, leading to situations like https://github.com/PyCQA/pyflakes/issues/320 and https://github.com/sympy/sympy/issues/17795.

If I run flake8 on the:

def my_overload(func):
    print(func)
    pass

@my_overload
def utf8(value: bytes) -> bytes:
    pass

@my_overload
def utf8(value: str) -> bytes:
    pass

def utf8(value):
    pass  # actual implementation

I get:

test.py:8:1: F811 redefinition of unused 'utf8' from line 4
test.py:12:1: F811 redefinition of unused 'utf8' from line 8

But the semantically-equivalent:

def utf8(value: bytes) -> bytes:
    pass
my_overload(utf8)

def utf8(value: str) -> bytes:
    pass
my_overload(utf8)

def utf8(value):
    pass  # actual implementation

Does not have any errors. As in my example above, annotations to functions have arbitrary side-effects and should be considered a use of the function

Alternatives:
I can either add an additional prepend overload to my own decorator

def my_decorator(func):
    return func

@overload
@my_decorator
def utf8(value: None) -> None:
    pass

Or I can add two noqa per overloaded function declaration:

@my_overload  # noqa
def utf8(value: str) -> bytes:  # noqa
    pass

These both work for now but it would be nice if I didn't have to do them.

主要言語
Python
スター
1.5k
フォーク
205
平均マージ
1日 2時間
マージ済み PR(30日)
5

環境構築

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

はじめの一歩

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

PyCQA/pyflakes のほかの issue

PyCQA/pyflakes の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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