Python ValueError:TextCommand';之后不能使用编辑对象;的运行方法已返回

Python ValueError:TextCommand';之后不能使用编辑对象;的运行方法已返回,python,sublimetext3,sublime-text-plugin,Python,Sublimetext3,Sublime Text Plugin,我正在将现有的ST2插件移植到ST3。它基本上是一个Lorem Ipsum替代方案。 这是相关代码。我把它从更大的上下文中拉出来,只显示跟踪中的行 class FilleratiCommand(sublime_plugin.TextCommand): def run(self, edit, n=300, b=None): completes = [] def api_check(thread): # Completed. completes.a

我正在将现有的ST2插件移植到ST3。它基本上是一个Lorem Ipsum替代方案。

这是相关代码。我把它从更大的上下文中拉出来,只显示跟踪中的行

class FilleratiCommand(sublime_plugin.TextCommand):

def run(self, edit, n=300, b=None):
    completes = []
    def api_check(thread):
        # Completed.
        completes.append(lambda r, n: self.complete(edit, r, thread.result, n))

def complete(self, edit, region, result, n):
    if region.empty():
        self.view.insert(edit, region.begin(), content)
    else:
        self.view.replace(edit, region, content)
运行时,我在标题中得到错误。以下是跟踪:

Traceback (most recent call last):
  File "/Users/cardern/Library/Application Support/Sublime Text 3/Packages/Fillerati/fillerati.py", line 24, in <lambda>
    sublime.set_timeout(lambda: api_check(thread), 100)
  File "/Users/cardern/Library/Application Support/Sublime Text 3/Packages/Fillerati/fillerati.py", line 46, in api_check
    completes[i](region, cnt)
  File "/Users/cardern/Library/Application Support/Sublime Text 3/Packages/Fillerati/fillerati.py", line 34, in <lambda>
    lambda r, n: self.complete(edit, r, thread.result, n))
  File "/Users/cardern/Library/Application Support/Sublime Text 3/Packages/Fillerati/fillerati.py", line 76, in complete
    self.view.replace(edit, region, content)
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime.py", line 685, in replace
    raise ValueError("Edit objects may not be used after the TextCommand's run method has returned")
ValueError: Edit objects may not be used after the TextCommand's run method has returned
回溯(最近一次呼叫最后一次):
文件“/Users/cardern/Library/Application Support/Sublime Text 3/Packages/Fillerati/Fillerati.py”,第24行,在
设置超时(lambda:api\u检查(线程),100)
文件“/Users/cardern/Library/Application Support/Sublime Text 3/Packages/Fillerati/Fillerati.py”,第46行,在api检查中
完成[i](区域,cnt)
文件“/Users/cardern/Library/Application Support/Sublime Text 3/Packages/Fillerati/Fillerati.py”,第34行,在
lambda r,n:self.complete(编辑,r,thread.result,n))
文件“/Users/cardern/Library/Application Support/Sublime Text 3/Packages/Fillerati/Fillerati.py”,第76行,完整
self.view.replace(编辑、区域、内容)
文件“/Applications/Sublime Text.app/Contents/MacOS/Sublime.py”,第685行,替换为
raise VALUERROR(“在TextCommand的run方法返回后,不能使用编辑对象”)
ValueError:返回TextCommand的run方法后,可能无法使用编辑对象
在我看来,这似乎是由于违反了《移植指南》中受限制的begin_edit()和end_edit()部分:


有没有人对如何正确插入Lorem文本以遵循ST3的限制提出建议

请在问题中发布代码,或者更好的是a-,而不仅仅是指向外部资源的链接。