Repository navigation
Add stub file for dashscope #168
Description
Problem
When using Pylance / Pyright for type checking, import dashscope triggers:
Stub file not found for "dashscope"
The type checker cannot resolve any type information from dashscope.
Environment
- dashscope: 1.26.4 (latest)
- Python: 3.12
- Platform: Linux
- Type checker: Pylance (VS Code) / Pyright
Cause
The dashscope package is missing standard type stub files:
dashscope/
├── __init__.py # present
├── py.typed # missing (PEP 561 typed-package marker)
├── *.pyi # none exist
- No
py.typedmarker → PEP 561 does not recognize this as a typed package. - No
.pyistub files → the type checker falls back to inferring everything asAny.
Current workaround
Users either add # type: ignore after every import dashscope, or disable reportMissingTypeStubs globally. Both reduce type coverage and are a hassle to maintain.
Request
- Add a
py.typedmarker file to the package root (an empty file per PEP 561). - Provide
.pyistub files for the public API — at minimum coveringdashscopeanddashscope.commonmodule signatures.
If maintaining full stubs is not feasible in the short term, even a minimal __init__.pyi that exports the most commonly used classes/functions (e.g., Generation.result, Embedding, type aliases for response callbacks) would significantly improve the developer experience.
Reference
问题
在使用 Pylance / Pyright 进行类型检查时,import dashscope 报:
找不到 "dashscope" 的 Stub 文件
类型检查器无法解析 dashscope 的类型信息。
环境
- dashscope: 1.26.4 (latest)
- Python: 3.12
- 平台: Linux
- 类型检查器: Pylance (VS Code) / Pyright
原因
dashscope 包缺少类型 stub 文件:
dashscope/
├── __init__.py # 有
├── py.typed # 缺失(PEP 561 marker)
├── *.pyi # 全部缺失
- 没有
py.typedmarker 文件,PEP 561 无法识别为 typed package。 - 没有任何
.pyistub 文件,类型检查器只能靠 fromAny推断。
当前临时方案
在每个 import dashscope 处手动加 # type: ignore,或对全项目配置 reportMissingTypeStubs = false。但这些治标不治本,也降低了类型检查的覆盖率。
请求
- 在包根目录添加
py.typed文件(空文件即可,PEP 561 标准)。 - 为公开 API 添加
.pyistub 文件,至少覆盖dashscope、dashscope.common等主要模块的接口签名。
如果暂无精力维护完整 stubs,至少加上 py.typed + __init__.pyi 导出自动补全常用的类/函数签名(如 Generation.result、Embedding 等),能极大改善用户体验。
Activity
feat: add PEP 561 type stubs for better IDE support
lzsweb commentedon Jul 30, 2026
感谢 @howardhey 的详细反馈和清晰的 PEP 561 实现建议!🙏
我们已在 PR #170 中完成了以下修复:
dashscope/py.typed标记文件(PEP 561)dashscope/__init__.pyi,覆盖所有公开 API 的完整类型签名MANIFEST.in确保类型文件包含在 sdist/wheel 分发包中预计将在本周发布的下一个版本中包含此修复。