def update(self, property_name, source_code_str):
"""Update the given property with the given source code.
This does not write the results to file immediately, rather, this updates an internal buffer with the
updated source code. To write to file use :meth:`write_to_file`.
Args:
property_name (str): the property (attribute or function) to update
source_code_str (str): the updated source code for the property
"""
try:
start, end = self._fine_property_definition(property_name)
source_lines = self._source.split('\n')
new_source = '\n'.join(source_lines[:start])
new_source += '\n' + indent(dedent(source_code_str.strip()), '\t') + '\n'
new_source += '\n'.join(source_lines[end:])
except ValueError:
new_source = self._source + '\n' + indent(dedent(source_code_str.strip()), '\t') + '\n'
self._source = new_source.rstrip('\n').replace('\t', ' ')
评论列表
文章目录