Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

attr.Factory provided with the attribute beeing initialized

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

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

評価

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

調査の方向性

Start by reading the attr.Factory, converters.default_if_none, Attribute, and metadata documentation linked or named in the issue. Determine whether a factory can receive attribute context without mutating frozen Attribute instances. Done should be a supported way to derive an environment key from an attribute name or metadata, with the requested behavior documented and tested.

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

説明

Feature

Hi there,

I'm looking for a way to read default value for an attribute from os.environ

The natural way i see for this is to use a attr.Factory in combination with attr.converters.default_if_none. This factory would call os.environ with some env-key built with attribute's name or metadata.

But i dont see how this factory could be provided with the attribute's name or meta-data.

The other way i tried to was to build a custom decorator

def env_binding(prefix):
    def modify_ib_default(attribute):
        env_key = (prefix + '_' + attribute.name).upper()
        attribute.default = os.environ.get(env_key, attribute.default)
        return attribute

    def wrap(cls):
        new_cls = attr.s(cls)
        new_cls.__attrs_attrs__ = tuple(map(modify_ib_default, new_cls.__attrs_attrs__))
        return new_cls
    return wrap

but since Attribute instances are read-only (setattr --> raise FrozenInstanceError), this method is not valid...

Note: I know the nice python attr-based module config-environ but I need a different behavior.

主要言語
Python
スター
5.8k
フォーク
480
平均マージ
2時間 15分
マージ済み PR(30日)
2

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

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

はじめの一歩

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

python-attrs/attrs のほかの issue

python-attrs/attrs の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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