python / python/mypy

Add support for attr.converters.default_if_none

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

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

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

説明

I have the following:

@attr.s(auto_attribs=True)
class Foo:
    bars: List[Bar] = attr.ib(
        default=attr.Factory(list),
        converter=default_if_none(default=attr.Factory(list)),
    )

I'm running mypy via pre-commit and getting:

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

I have the following in my .pre-commit-config.yaml:

- repo: https://github.com/pre-commit/mirrors-mypy
  rev: v0.650
  hooks:
  - id: mypy
    additional_dependencies:
      - attrs>=18.2.0

(Without the additional_dependencies part I also get error: Module 'attr.converters' has no attribute 'default_if_none')

Could the issue be that there's special handling for optional here but not for default_if_none?

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

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

はじめの一歩

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

調査の方向性

issue で関連付けられている、オプショナルなコンバーターに対する既存の特別処理を mypy/plugins/attrs.py から確認し、次に pre-commit の設定を通して mypy で報告された snippet を再現します。attr.converters.default_if_none がどのように検証されるかを追跡し、期待される型付けの挙動を判断します; 報告されたエラーなしでコンバーターが受け入れられれば完了です。

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

評価

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

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

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