CardKit sequence example raises SyntaxError at module scope

オープン 初心者向け
#161 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
94/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
documentation

調査の方向性

doc/channel/cardkit-streaming.md を開き、推奨されている CardKit のシーケンスパターンを見つけてください。文書化されている Python コンパイル方法を使ったスニペットを確認し、コピーしたときに例が構文的に有効になるよう、scope または state パターンを調整してください。リポジトリ全体のドキュメントチェックを再実行し、71 個の明示的な Python フェンスが正常にコンパイルされることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
559
フォーク
102
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

larksuite/oapi-sdk-python のほかの issue

larksuite/oapi-sdk-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。