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.
Affected version
lark-oapi1.7.30b9e6e48b74bb4b34462fc67b7e738b27e73e697doc/channel/cardkit-streaming.md, recommended sequence patternProblem
The recommended CardKit sequence snippet declares
seqat module scope and then usesnonlocal seqinsidepatch():nonlocalcan only reference a binding in an enclosing function scope, not a module-level binding, so copying or compiling the example raises:Reproduction
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
seqand the nestedpatch()helper inside an enclosing async function, keepingnonlocal seqmeaningful, 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.