larksuite / larksuite/oapi-sdk-python

CardKit sequence example raises SyntaxError at module scope

Open Beginner friendly
#161 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
559
Forks
102
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open doc/channel/cardkit-streaming.md and find the recommended CardKit sequence pattern. Check the snippet with the documented Python compilation approach, then adjust the scope or state pattern so the example is syntactically valid when copied. Re-run the repository-wide documentation check and confirm the 71 explicit Python fences compile successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
94/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.