modelx v0.14.0 (2021年5月2日)#
本次发布修复了以下错误并引入了以下增强功能。
功能增强#
增强的Cells.doc属性与新增的set_doc()方法 (GH44)#
在此版本之前,Cells.doc
属性是只读的,并且
它与单元格公式的文档字符串相关联,因此
lambda单元格的这个属性始终为None。
在此版本中,Cells.doc
属性现在可作为设置器使用。
如果一个Cells具有无lambda公式,那么设置器会替换
该公式的文档字符串:
>>> @mx.defcells
... def foo(x):
... """This is foo"""
... return x
>>> foo.doc
'This is foo'
>>> foo.doc = "foo's doc is updated"
>>> foo.formula
def foo(x):
"""foo's doc is updated"""
return x
>>> foo.doc
"foo's doc is updated"
当通过Cells.doc属性设置Cells的文档字符串时,输入字符串不会自动缩进:
>>> doc = """This is foo
...
... Unindented docstring
... """
>>> foo.doc = doc
>>> foo.formula
def foo(x):
"""This is foo
Unindented docstring
"""
return x
新引入的Cells.set_doc方法
具有bool类型的参数insert_indents,
如果该参数值为True,则doc的第二行及后续行
会自动缩进:
>>> foo.set_doc(doc, insert_indents=True)
>>> foo.formula
def foo(x):
"""This is foo
Unindented docstring
"""
return x
如果一个单元格的公式由lambda函数定义,文档会与函数分开保存在单元格中:
>>> space.new_cells(name="bar", formula=lambda x: x)
<Cells Model1.Space1.bar(x)>
>>> space.bar.doc = "I am bar"
>>> space.bar.doc
'I am bar'
另请参阅
modelx版本保存在_system.json#
当通过Model.write、write_model()、Model.zip或zip_model()将模型写入文件时,除了序列化器版本外,还会在_system.json中输出modelx的版本。
Bug修复#
Model.doc被错误地当作引用处理。修复了在重新绑定一个被多个Cell直接和间接引用的Reference时出现的错误(GH43)。
修复了当模型保存时引发的错误,如果该模型之前已通过
zip_model()或Model.zip保存过,并且该模型包含由new_module()创建的模块 (GH45)。在通过
new_space()创建新Space时,cur_model()会被设置为该Space所属的Model。