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

未关闭 适合新手
#53 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
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 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DataDog/envier 的其他 Issue

查看 DataDog/envier 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。