Sphinx 抛出一些缩进错误,我不知道如何修复它们

问题描述 投票:0回答:1

这些是我从 Sphinx 收到的错误:

  1. 意外的缩进: [{ “资源”:“/c:/Users/User/Documents/GitHub/MIMIC/mimic/model_simulate/base_model.py”, “所有者”:“生成的诊断集合名称#5”, “严重性”:8, "message": "意外的缩进。", “来源”:“狮身人面像”, “起始行号”:46, “开始列”:1, “结束行号”:47, “结束列”:1 }]
  2. 定义列表结束时没有空行;意外的取消缩进: [{ “资源”:“/c:/Users/User/Documents/GitHub/MIMIC/mimic/model_simulate/base_model.py”, “所有者”:“生成的诊断集合名称#5”, “严重性”:4, "message": "定义列表结束时没有空行;意外取消缩进。", “来源”:“狮身人面像”, “起始行号”:44, “开始列”:1, “结束行号”:45, “结束列”:1 }]
  3. 块引用结束时没有空行;意外的取消缩进: [{ “资源”:“/c:/Users/User/Documents/GitHub/MIMIC/mimic/model_simulate/base_model.py”, “所有者”:“生成的诊断集合名称#5”, “严重性”:4, "message": "块引用结束时没有空行;意外取消缩进。", “来源”:“狮身人面像”, “起始行号”:47, “开始列”:1, “结束行号”:48, “结束列”:1 }]

这是文档字符串:

    """
    Abstract base class for creating and managing simulation models.

    This class serves as a foundation for any type of model that requires
    managing data, parameters, and basic I/O operations. It defines a
    common interface for parameter handling, data simulation, and data
    persistence.

    Attributes:
        data (np.ndarray | None): Holds the output data generated by the model's simulation.
            This could be None if the model has not yet produced any data.
        model (object | None): A generic placeholder for the specific simulation model instance.
            This attribute should be overridden in subclasses with an actual
            model representation.
        parameters (dict | None): A dictionary containing the parameters that control the model's
            behavior. Parameters should be defined in subclasses or set through
            the provided methods.

    Abstract Methods:
        set_parameters(self): Should be implemented by subclasses to define how model parameters
            are set or updated.
        simulate(self): Should be implemented by subclasses to define the model's simulation process
            based on the set parameters.

    Methods:
        check_params(self, params, sim_type): Checks provided parameters against required ones for a
            given simulation type, applying default values if necessary.
        read_parameters(self, filepath): Reads model parameters from a specified JSON file and updates
            the model's parameters accordingly.
        save_parameters(self, filepath, parameters=None): Saves the model's current parameters to a
            JSON file. Optionally, a specific set of parameters can be provided to save instead.
        print_parameters(self, precision=2): Prints the current set of model parameters to the console,
            formatting numpy arrays with specified precision.
        save_data(self, filename, data=None): Saves the model's generated data to a CSV file. Optionally,
            specific data can be provided to save instead.
        load_data(self, filename): Loads data from a specified CSV file into the model's `data` attribute.
        _custom_array_to_string(self, array, precision=2): Converts a numpy array to a string representation
            with specified precision.
        update_attributes(self): Updates class attributes based on the current parameters dictionary.
    """

文档字符串从第 10 行开始。

救命!

python-sphinx restructuredtext docstring
1个回答
0
投票

如何调试:

  • 将有问题的文档字符串内容复制粘贴到文本编辑器中。
  • 使用
    rst2html
    保存并翻译。 (如果源包含 rST 扩展,请使用 Sphinx 进行翻译)

错误消息指向源文档中的相关行。

修复第 35 行的缩进:

     save_data(self, filename, data=None): Saves the model's generated data to a CSV file. Optionally,
         specific data can be provided to save instead.
     load_data(self, filename): Loads data from a specified CSV file into the model's `data` attribute.
-    _custom_array_to_string(self, array, precision=2): Converts a numpy array to a string representation
+        _custom_array_to_string(self, array, precision=2): Converts a numpy array to a string representation
         with specified precision.
     update_attributes(self): Updates class attributes based on the current parameters dictionary.

将最后一行设为定义列表项:

     load_data(self, filename): Loads data from a specified CSV file into the model's `data` attribute.
     _custom_array_to_string(self, array, precision=2): Converts a numpy array to a string representation
         with specified precision.
-    update_attributes(self): Updates class attributes based on the current parameters dictionary.
+    update_attributes(self):
+        Updates class attributes based on the current parameters dictionary.

您可能还想修复所有其他定义列表条目,并在定义术语后使用换行符并正确缩进描述(参见定义列表)。

© www.soinside.com 2019 - 2024. All rights reserved.