Using typing.NoDefault instead of Ellipsis [3.13]
未关闭
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 5.1k
- 派生
- 2.1k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 82
描述
ParamSpec, TypeVar, TypeVarTuple have a __default__ attribute, which is evaluated to NoDefault, when no default is provided in constructor :
from typing import ParamSpec, TypeVar, TypeVarTuple, Any
print(f'{TypeVar("Plop").__default__ = }')
...
# ❯ python3.13 /tmp/tmpe9xlgjg8.py
TypeVar("Plop").__default__ = typing.NoDefault
TypeVarTuple("Plop").__default__ = typing.NoDefault
ParamSpec("Plop").__default__ = typing.NoDefault
TypeVar("Plop", default=Any).__default__ = typing.Any
TypeVarTuple("Plop", default=Any).__default__ = typing.Any
ParamSpec("Plop", default=Any).__default__ = typing.Any
But this behaviour is not implemented in stubs, Ellipsis is used instead of typing.NoDefault which is already in stubs. I guess it could be fixed without breaking risks.
diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi
index f04b2d858..a84a517cc 100644
--- a/stdlib/typing.pyi
+++ b/stdlib/typing.pyi
@@ -161,7 +161,7 @@ class TypeVar:
contravariant: bool = False,
covariant: bool = False,
infer_variance: bool = False,
- default: Any = ...,
+ default: Any = NoDefault,
) -> None: ...
elif sys.version_info >= (3, 12):
def __init__(
@@ -231,7 +231,7 @@ if sys.version_info >= (3, 11):
def __default__(self) -> Any: ...
def has_default(self) -> bool: ...
if sys.version_info >= (3, 13):
- def __init__(self, name: str, *, default: Any = ...) -> None: ...
+ def __init__(self, name: str, *, default: Any = NoDefault) -> None: ...
else:
def __init__(self, name: str) -> None: ...
@@ -279,7 +279,7 @@ if sys.version_info >= (3, 10):
contravariant: bool = False,
covariant: bool = False,
infer_variance: bool = False,
- default: Any = ...,
+ default: Any = NoDefault,
) -> None: ...
elif sys.version_info >= (3, 12):
def __init__(
Ps :
print(f'{TypeVar("Plop").__default__ is TypeVarTuple("Plop").__default__ is ParamSpec("Plop").__default__ = }')
❯ python3.13 /tmp/tmpe9xlgjg8.py
TypeVar("Plop").__default__ is TypeVarTuple("Plop").__default__ is ParamSpec("Plop").__default__ = True
TypeVar("Plop").__default__ is Ellipsis = False
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
检查 stdlib/typing.pyi 中的 TypeVar、TypeVarTuple 和 ParamSpec 定义,重点关注它们的默认参数以及现有的 NoDefault 存根。更新 Python 3.13 的签名,使省略的默认值对应于 typing.NoDefault,并确认该存根不再将它们表示为 Ellipsis。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 38/100