Docstring says t.Tuple is supported, but typing.Tuple raises AttributeError

オープン 初心者向け
#53 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
88/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
documentation

調査の方向性

Env の docstring がある envier/env.py の 232-233 行目から始めてください。そこでは t.Tuple が list や set と並んで記載されています。EnvVariable._cast(78-87 行目)と _check_type(28-32 行目)を読み、裸の typing.Tuple エイリアスに __args__ がないことを確認してください。最も簡単な修正は docstring を tuple に変えることです。別案として、typing.Tuple/List/Set を元の型に正規化します。既存の collection テストを実行し、正規化する場合は typing.Tuple のケースを追加してください。

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

説明

The Env docstring says t.Tuple is supported as a collection type, but declaring a variable with typing.Tuple raises AttributeError when the value is read. The builtin tuple works.

Environment: envier 0.6.1, Python 3.12

Reproduction

import json
import typing
from envier import Env

try:
    class C(Env):
        x = Env.var(typing.Tuple, "x")
    print(json.dumps(C({"X": "a,b"}).x))
except Exception as e:
    print(json.dumps(type(e).__name__))

Actual output

"AttributeError"

Expected output

["a", "b"]

From the Env class docstring:

There is also basic support for collections. An item of type list, t.Tuple or set will be parsed using , as item separator.

https://github.com/DataDog/envier/blob/a8ee033fd2581be09c0d61eb6b8343f12c8f08e9/envier/env.py#L232-L233

Likely cause: EnvVariable._cast only handles _type in (list, tuple, set), so typing.Tuple falls through to _check_type, which reads _type.__args__; the bare typing.Tuple alias has no __args__:
https://github.com/DataDog/envier/blob/a8ee033fd2581be09c0d61eb6b8343f12c8f08e9/envier/env.py#L28-L32
https://github.com/DataDog/envier/blob/a8ee033fd2581be09c0d61eb6b8343f12c8f08e9/envier/env.py#L78-L87

Since the same sentence lists the builtins list and set and the tests use builtin tuple, the simplest fix may be to change t.Tuple to tuple in the docstring; alternatively typing.Tuple (and typing.List/typing.Set) could be normalized to their origin types.

Found while testing the library with an automated exploration tool; the reproduction above was re-run on 0.6.1 before filing.

主要言語
Python
スター
9
フォーク
2
平均マージ
7時間 22分
マージ済み PR(30日)
1

環境構築

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

はじめの一歩

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

DataDog/envier のほかの issue

DataDog/envier の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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