CardKit sequence example raises SyntaxError at module scope

Đang mở Phù hợp với người mới
#161 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
94/100
Loại issue
Tài liệu
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
documentation

Hướng nghiên cứu

Mở doc/channel/cardkit-streaming.md và tìm mẫu chuỗi CardKit được khuyến nghị. Kiểm tra đoạn snippet sử dụng phương pháp biên dịch Python được ghi chép, sau đó điều chỉnh mẫu scope hoặc state để ví dụ có cú pháp hợp lệ khi được sao chép. Chạy lại kiểm tra tài liệu trên toàn repository và xác nhận rằng 71 fence Python tường minh được biên dịch thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Affected version

  • lark-oapi 1.7.3
  • Default branch commit: 0b9e6e48b74bb4b34462fc67b7e738b27e73e697
  • File: doc/channel/cardkit-streaming.md, recommended sequence pattern

Problem

The recommended CardKit sequence snippet declares seq at module scope and then uses nonlocal seq inside patch():

seq = 0

async def patch(text):
    nonlocal seq
    seq += 1
    await channel.update_card_element_content(card_id, "main", text, sequence=seq)

nonlocal can only reference a binding in an enclosing function scope, not a module-level binding, so copying or compiling the example raises:

SyntaxError: no binding for nonlocal 'seq' found

Reproduction

source = '''
seq = 0
async def patch(text):
    nonlocal seq
    seq += 1
'''
compile(source, "cardkit-example.py", "exec")

The repository-wide documentation check compiled 71 explicit Python code fences with ast.PyCF_ALLOW_TOP_LEVEL_AWAIT; this was the only fence that failed.

Expected behavior

The recommended pattern should be syntactically valid when copied into an application.

Suggested fix

Place both seq and the nested patch() helper inside an enclosing async function, keeping nonlocal seq meaningful, or use another state pattern that compiles at module scope. The lower-level complete example later in the same page already uses a valid direct increment pattern.

I searched open and closed issues, all pull request states, and repository history for nonlocal seq, CardKit streaming, and the document path. I found no existing report or competing fix.

Ngôn ngữ chính
Python
Star
559
Fork
102
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của larksuite/oapi-sdk-python

Tất cả issue của larksuite/oapi-sdk-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.