【问题标题】:Sphinx: What is the cause for 'WARNING: duplicate object description'?狮身人面像:“警告:重复对象描述”的原因是什么?
【发布时间】:2021-03-31 15:45:00
【问题描述】:

我收到多个警告,例如:

警告:pyfar.signal.TimeData.times 的重复对象描述,pyfar.classes_audio 中的其他实例,其中之一使用 :noindex:

但不知道为什么?有人建议我可能在不同的 rst 文件中包含两次相同的对象。但我认为情况并非如此。

我尝试基于原始包 (https://github.com/pyfar/pyfar/tree/develop/docs) 创建一个最小的工作示例:

获取代码

git clone https://github.com/f-brinkmann/pyfar_sphinx_test.git pyfar_sphinx_test
cd pyfar_sphinx_test

制作虚拟环境

conda create --name sphinx_test python<3.9
conda activate sphinx_test
pip install -r requirements_dev.txt
pip install -e .

构建文档

cd docs
make clean
make html

产量

Running Sphinx v3.5.3
making output directory... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index
C:\Users\panik\Desktop\pyfar_sphinx_test\pyfar\signal.py:docstring of pyfar.signal.FrequencyData.fft_norm:1: WARNING: duplicate object description of pyfar.signal.FrequencyData.fft_norm, other instance in index, use :noindex: for one of them
C:\Users\panik\Desktop\pyfar_sphinx_test\pyfar\signal.py:docstring of pyfar.signal.FrequencyData.frequencies:1: WARNING: duplicate object description of pyfar.signal.FrequencyData.frequencies, other instance in index, use :noindex: for one of them
C:\Users\panik\Desktop\pyfar_sphinx_test\pyfar\signal.py:docstring of pyfar.signal.Signal.domain:1: WARNING: duplicate object description of pyfar.signal.Signal.domain, other instance in index, use :noindex: for one of them
C:\Users\panik\Desktop\pyfar_sphinx_test\pyfar\signal.py:docstring of pyfar.signal.Signal.fft_norm:1: WARNING: duplicate object description of pyfar.signal.Signal.fft_norm, other instance in index, use :noindex: for one of them
C:\Users\panik\Desktop\pyfar_sphinx_test\pyfar\signal.py:docstring of pyfar.signal.Signal.sampling_rate:1: WARNING: duplicate object description of pyfar.signal.Signal.sampling_rate, other instance in index, use :noindex: for one of them
C:\Users\panik\Desktop\pyfar_sphinx_test\pyfar\signal.py:docstring of pyfar.signal.TimeData.times:1: WARNING: duplicate object description of pyfar.signal.TimeData.times, other instance in index, use :noindex: for one of them
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index
generating indices... genindex py-modindex done
highlighting module code... [100%] pyfar.signal
writing additional pages... search done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 6 warnings.

感谢您的回复,法比安

【问题讨论】:

  • SO 上的大多数人可能对 pyfar 一无所知。请提供minimal reproducible example。此问题不包含您的其他已关闭问题的更多信息。
  • 对不起@mzjn。我生成了一个最小的示例和步骤来重现我的问题。感谢您的耐心,Fabian

标签: python python-sphinx autodoc sphinx-napoleon


【解决方案1】:

问题似乎是您在某些__init__ 方法的文档字符串中使用了Attributes 标头。如果将其更改为 Parameters(这是正确的标头),警告就会消失。

例子:

def __init__(self, data, frequencies, fft_norm=None, comment=None,
                 dtype=complex):
        """Init FrequencyData with data, and frequencies.
 
        Parameters
        ----------
        data : array, double
            Raw data in the frequency domain. The memory layout of Data is 'C'.
            E.g. data of shape (3, 2, 1024) has 3 x 2 channels with 1024
            frequency bins each.
        frequencies : array, double
            Frequencies of the data in Hz. The number of frequencies must match
            the size of the last dimension of data.
        fft_norm : 'none', 'unitary', 'amplitude', 'rms', 'power', 'psd'
            The kind of Discrete Fourier Transform (DFT) normalization. See
            pyfar.fft.normalization and _[#] for more information. The default
            is 'none', which is typically used for energy signals, such as
            impulse responses.
        comment : str
            A comment related to the data. The default is None.
        dtype : string, optional
            Raw data type of the signal. The default is float64

【讨论】:

  • 非常感谢@mzjn 抽出宝贵时间分享您的经验!这至少要花我一辈子才能找到。我错误地认为参数和属性是可以互换的
  • 以防它帮助其他人:我刚刚从 Sphinx 收到相同的警告消息,原因不同,并找到了解决方案。我在类文档字符串的“属性”部分下混合了类属性和实例属性。原来它只能是实例属性。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多