You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sphinx.builders.html.StandaloneHTMLBuilder uses a property for default_translator_class, but in the base class it's a conventional variable. This means that code using app.registry.get_translator_class for any builder that subclasses StandaloneHTMLBuilder is given a property object rather than the actual nodes.NodeVisitor class.
How to Reproduce
The example conf.py below illustrates what I'm doing:
The default_translator_class attribute, and app.registry.get_translator_class, should always returns a nodes.NodeVisitor class, per the type annotations on both.
I suspect the # type: ignore is there because mypy was warning about exactly this issue. If I remove the comment I get an (albeit cryptic) error:
sphinx/builders/html/__init__.py: note: In class "StandaloneHTMLBuilder":
sphinx/builders/html/__init__.py:336:5: error: Signature of "default_translator_class" incompatible with supertype "Builder"
mypy has determined the signature to be def (self: sphinx.builders.html.StandaloneHTMLBuilder) -> Type[docutils.nodes.NodeVisitor].
The text was updated successfully, but these errors were encountered:
This is incorrect code. app.registry.get_translator_class() takes an instance of builder. But you passed a builder class, not an instance. I think the code that you want is this:
Describe the bug
sphinx.builders.html.StandaloneHTMLBuilder
uses a property fordefault_translator_class
, but in the base class it's a conventional variable. This means that code usingapp.registry.get_translator_class
for any builder that subclassesStandaloneHTMLBuilder
is given aproperty
object rather than the actualnodes.NodeVisitor
class.How to Reproduce
The example
conf.py
below illustrates what I'm doing:Running
sphinx-build -M html . ./build -T
:Expected behavior
The
default_translator_class
attribute, andapp.registry.get_translator_class
, should always returns anodes.NodeVisitor
class, per the type annotations on both.Your project
N/A
Screenshots
No response
OS
Ubuntu 20.04
Python version
3.8.10
Sphinx version
2.0.0 - 4.1.1
Sphinx extensions
None
Extra tools
None
Additional context
The offending code is here:
sphinx/sphinx/builders/html/__init__.py
Lines 335 to 340 in 07598f0
I suspect the
# type: ignore
is there because mypy was warning about exactly this issue. If I remove the comment I get an (albeit cryptic) error:mypy has determined the signature to be
def (self: sphinx.builders.html.StandaloneHTMLBuilder) -> Type[docutils.nodes.NodeVisitor]
.The text was updated successfully, but these errors were encountered: