getSyntaxHint.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:ITAP-django 作者: krivers 项目源码 文件源码
def getMinimalChanges(changes, code, cutoff=None):
    # Only do the power set if the # of changes is reasonable
    if len(changes) < 8:
        changesPowerSet = powerSet(changes)
    elif len(changes) < 50:
        changesPowerSet = fastPowerSet(changes)
    else: # too large, we can't even do the fast power set because it will overwhelm memory
        changesPowerSet = [changes]
    sortList = list(map(lambda x : (x, sum(len(item.text) + len(item.newText) for item in x)), changesPowerSet))
    if cutoff != None:
        sortList = list(filter(lambda x : x[1] < cutoff, sortList))
    sortList.sort(key=lambda x : x[1])
    usedChange = combineSameLocationChanges(changes)
    usedCode = applyChanges(code, usedChange)
    for (change, l) in sortList:
        change = combineSameLocationChanges(change)
        tmpSource = applyChanges(code, change)
        try:
            ast.parse(tmpSource)
            usedChange = change
            usedCode = tmpSource
            break
        except:
            pass
    return (usedChange, usedCode)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号