使用@中缀运算符进行矩阵乘法时,Sphinx 不会呈现语法高亮显示

Sphinx doesn't render syntax highlighting when using the @ infix operator for matrix multiplication

Python 3.5按照PEP 465.

实现矩阵乘法的@中缀运算符

设 A 和 B 为 2 个 numpy 数组:

A = numpy.array([[1],[2]])
B = numpy.array([[1,2]])

然后,紧凑形式:

C = A @ B 

相当于:

C = numpy.dot(A,B)

我的问题是,当我使用 sphinx (v1.3.6) 时,稍后描述的 literalinclude 不会将脚本视为 Python 并且不会呈现语法突出显示:

.. literalinclude:: toto.py
    :linenos:
    :language: python

Pygments 有一个针对 Python 3 的特殊词法分析器。参见 http://pygments.org/docs/lexers/#pygments.lexers.python.Python3Lexer

如果您使用 python3py3 作为语言,它应该可以工作:

.. literalinclude:: toto.py
   :linenos:
   :language: python3