python / python/mypy

Add support for classmethod converters in attrs plugin

オープン
#7,912 コメント 4 件 リアクション 8 件 担当者 0 名 GitHub で見る

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

feature priority-1-normal topic-attrs
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

import attr

@attr.s
class Bar:
    b = attr.ib()

    @classmethod
    def make(cls, one: int) -> 'Bar':
        return cls(one)


@attr.s
class Foo:
    a = attr.ib(converter=Bar.make)

error: Unsupported converter, only named functions and types are currently supported

Attrs is perfectly happy with make

>>> Foo(1)
Foo(a=Bar(b=1))

Granted the converter limitations are a known issue, I couldn't find this use-case covered anywhere.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

まず、issue の classmethod converter の例で報告されたエラーを再現し、その後 attrs plugin の converter 処理を追跡します。classmethod converter(Bar.make など)が unsupported-converter エラーなしで受け入れられ、例が引き続き正しく型チェックされれば完了です。

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

評価

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

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

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