refactor: 将装饰器 gobridge 重命名为 expose,并添加 pyproject.toml

This commit is contained in:
2026-04-13 17:13:54 +08:00
parent 308faa95ff
commit 07e9239ac5
4 changed files with 38 additions and 26 deletions

View File

@@ -28,7 +28,7 @@ Python 端直接复制 `python/gobridge/` 目录到项目中,无需安装依
from gobridge import gobridge, run
from typing import Iterator
@gobridge
@expose
def add(a: int, b: int) -> int:
return a + b
@@ -61,15 +61,15 @@ result, err := gobridge.Invoke[[]User](ctx, pool, "enrich_users", users)
```python
# Python
@gobridge
@expose
def add(a: int, b: int) -> int:
return a + b
@gobridge
@expose
def get_user(uid: int) -> dict:
return {"id": uid, "name": f"user_{uid}", "score": uid * 1.5}
@gobridge
@expose
def enrich_users(users: list) -> list:
for u in users:
u["level"] = "gold" if u["score"] >= 10 else "silver"
@@ -95,12 +95,12 @@ for u := range userCh {
```python
# Python
@gobridge
@expose
def range_gen(start: int, stop: int) -> Iterator[int]:
for i in range(start, stop):
yield i
@gobridge
@expose
def gen_users(count: int) -> Iterator[dict]:
for i in range(1, count + 1):
yield {"id": i, "name": f"user_{i}", "score": float(i * 3)}
@@ -125,7 +125,7 @@ fmt.Println(total) // 15
```python
# Python
@gobridge
@expose
def sum_stream(numbers: Iterator[int]) -> int:
return sum(numbers)
```
@@ -151,7 +151,7 @@ for u := range outCh {
```python
# Python
@gobridge
@expose
def process_users(users: Iterator[dict]) -> Iterator[dict]:
for u in users:
yield {"id": u["id"], "name": u["name"].upper(), "score": u["score"] * 2}
@@ -170,7 +170,7 @@ result, err := gobridge.Invoke[int](ctx, pool, "slow_compute", 1000000)
```
```python
@gobridge
@expose
def slow_compute(n: int) -> int:
total = 0
for i in range(n):
@@ -360,7 +360,7 @@ gobridge = { git = "https://git.fsdpf.net/go/gobridge.git", subdirectory = "pyth
│ │ _dispatch() │ → 执行线程抛 InterruptedError│ │
│ │ │ │ │ │
│ │ ┌──────▼──────┐ │ │ │
│ │ │ @gobridge fn│ │ │ │
│ │ │ @expose fn│ │ │ │
│ │ │ │ │ │ │
│ │ │ 普通函数 │ │ │ │
│ │ │ return val ──────────────► result/error │ │