Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python stub file for type annotation hint on developing. #6

Merged
merged 1 commit into from
May 6, 2024

Conversation

Abeautifulsnow
Copy link

@Abeautifulsnow Abeautifulsnow commented May 6, 2024

最近也是恰好需要用到python的nacos sdk,官方的v2维护不够活跃,恰好发现了这个宝藏库🤩,十分感谢作者的贡献。但是在使用过程中,比较盲盒。遂 #5 开启了这个issue,希望添加 type hints 辅助。

目前我已经参照 python-typing-hints 的建议在项目根目录增加了一个 nacos_sdk_rust_binding_py.pyi 文件,自测可以随着 maturin develop

📦 Including license file "F:\learning\rust\git\nacos-sdk-rust-binding-py\LICENSE"
🔗 Found pyo3 bindings
🐍 Found CPython 3.12 at F:\learning\rust\git\nacos-sdk-rust-binding-py\.venv\Scripts\python.exe
📡 Using build options features from pyproject.toml
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Ignoring pdoc: markers 'extra == "docs"' don't match your environment
Ignoring behave: markers 'extra == "test"' don't match your environment
   Compiling nacos-sdk-rust-binding-py v0.3.6 (F:\learning\rust\git\nacos-sdk-rust-binding-py)
    Finished dev [unoptimized + debuginfo] target(s) in 4.07s
📖 Found type stub file at nacos_sdk_rust_binding_py.pyi   # <--- 自动发现pyi文件
📦 Built wheel for CPython 3.12 to C:\Users\rose\AppData\Local\Temp\.tmpwH57hk\nacos_sdk_rust_binding_py-0.3.6-cp312-none-win_amd64.whl
✏️  Setting installed package as editable
🛠 Installed  nacos-sdk-rust-binding-py-0.3.6

在本地环境安装的时候会看到比原本多了一个 __init__.pyi 文件,下面是执行了 maturin develop 后的安装包目录结构:

F:\learning\rust\git\nacos-sdk-rust-binding-py\.venv\Lib\site-packages\nacos_sdk_rust_binding_py
.
├── py.typed (0 B)
├── __init__.pyi (7.5KiB)
├── __init__.py (188 B)
├── nacos_sdk_rust_binding_py.cp312-win_amd64.pyd (16.7MiB)
└── __pycache__
    └── __init__.cpython-312.pyc (390 B)

Summary: Total folders: 1 Total files: 5 Total size: 16.7MiB

然后这是在IDE使用的时候,提示的内容:
image

image

此文件仅用于类型的声明,当使用mypy的时候可以为 Python 代码提供静态类型检查,以及优化开发体验。

希望 @CherishCai 可以再次验证,并希望能使得该功能让项目体验更加完美。🙏

@CherishCai CherishCai added the documentation Improvements or additions to documentation label May 6, 2024
Copy link
Member

@CherishCai CherishCai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CherishCai
Copy link
Member

感谢贡献 🎉

@CherishCai CherishCai merged commit 356668f into opc-source:master May 6, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants