Skip to content

[docutils] Add remaining node classes and functions #11255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 31, 2024

Conversation

flying-sheep
Copy link
Contributor

@flying-sheep flying-sheep commented Jan 7, 2024

I checked that everything is included using this little script:

import ast
from types import FunctionType

import rich.console
from docutils import nodes

DEPRECATED = {"ensure_str", "unescape", "reprunicode"}


def main() -> None:
    con = rich.console.Console()

    with open("stubs/docutils/docutils/nodes.pyi") as f:
        stubs = ast.parse(f.read(), f.name)
    names_stubs = dict.fromkeys(stmt.name for stmt in stubs.body if isinstance(stmt, (ast.ClassDef, ast.FunctionDef))).keys()
    names_real = dict.fromkeys(
        name
        for name, global_ in vars(nodes).items()
        if not name in DEPRECATED
        if isinstance(global_, (type, FunctionType))
        if not global_.__name__.startswith("_")
        if global_.__module__ == "docutils.nodes"
    ).keys()
    for name in names_real:
        is_missing = name not in names_stubs
        if is_missing:
            con.print(name, style="red")
        else:
            con.print(name, style="bold")

    if superfluous := [name for name in names_stubs if not name.startswith("_") if name not in names_real]:
        con.print(f"Superfluous items: {superfluous}", style="bold red")


if __name__ == "__main__":
    main()

@flying-sheep flying-sheep changed the title Add remaining docutils node classes [docutils] Add remaining node classes Jan 7, 2024
@flying-sheep flying-sheep changed the title [docutils] Add remaining node classes [docutils] Add remaining node classes and functions Jan 7, 2024
Comment on lines +83 to +85
# Left out
# - def ensure_str (deprecated)
# - def unescape (canonical import from docutils.utils)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-explanatory

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a history of leaving out deprecated symbols for third-party stubs, I'd say it's fine.
But if you want, you could use the typing_extensions.deprecated decorator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in these two cases, it’s not necessary. One is for Python 2 only and therefore completely unnecessary, the other should just be imported from somewhere else, which is a single line change.

# - def ensure_str (deprecated)
# - def unescape (canonical import from docutils.utils)

class Text(Node, str):
Copy link
Contributor Author

@flying-sheep flying-sheep Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this up so the module layout matches the source file.

This makes it easier to compare stubs and module code

Comment on lines -140 to -154
def copy(self) -> Self: ...
def deepcopy(self) -> Self: ...
def pformat(self, indent: str = " ", level: int = 0) -> str: ...
def astext(self) -> str: ...
Copy link
Contributor Author

@flying-sheep flying-sheep Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As document inherits these from Element, duplicating these is not necessary.

This comment has been minimized.

This comment has been minimized.

@flying-sheep
Copy link
Contributor Author

flying-sheep commented Jan 7, 2024

No idea what the “Test / Run mypy on the test cases” failure is about:

AssertionError: Cannot find module for resource.struct_rusage

doesn’t look like anything I’ve touched.

This comment has been minimized.

@AlexWaygood
Copy link
Member

No idea what the “Test / Run mypy on the test cases” failure is about:

AssertionError: Cannot find module for resource.struct_rusage

doesn’t look like anything I’ve touched.

It's a known, unrelated issue:

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A few – mostly nits – below.

Co-authored-by: Sebastian Rittau <[email protected]>

This comment has been minimized.

srittau
srittau previously approved these changes Jan 14, 2024

This comment has been minimized.

@srittau srittau dismissed their stale review January 14, 2024 14:34

Looking at the primer output.

@srittau
Copy link
Collaborator

srittau commented Jan 14, 2024

I don't like the mypy primer output. One of the problems is that we annotate Node.parent using Node | None. But Sphinx often does the equivalent of x = foo.parent and then assumes that x is not None. I believe this is usually a valid assumption as – I guess – only the root node of a document has a None parent. For example https://github.com/sphinx-doc/sphinx/blob/587e01177deeaf10b4fbe3f567b99ec083238b7e/sphinx/util/nodes.py#L132-L134:

    elif isinstance(node, nodes.classifier) and not node.source:
        # docutils-0.15 fills in rawsource attribute, but not in source.
        node.source = node.parent.source

In this case, it's valid to assume that node has a parent.

I see two possible solutions:

  • The easy solution is to use the "Any trick" (documented in CONTRIBUTING.md) and annotate Node.parent as Node | Any instead of Node | None. This can lead to false negatives, but is preferable to the big number of false positives we get now.
  • Add a parent: Node field to most sub-classes of Element (and possibly some Node sub-classes as well).

@flying-sheep
Copy link
Contributor Author

In a fully parsed document, that assumption holds, but it’s always possible to create nodes whereever you want and use them. And these don’t have parents.

I don’t like the “Any trick”. I do type checking to accurately handle all cases in my code. Corner cases like this are exactly what I want typing to be correct for: so I get notified that they exist and I can handle them before they become a problem.

@flying-sheep
Copy link
Contributor Author

flying-sheep commented Jan 26, 2024

I invested quite some time into this. Sad to see all the conflicts being introduced.

@adamtheturtle FYI this is a complete PR that adds all node classes, and you’re making this harder

Unless anything is incorrect, can this please be merged and nitpicks and design choices deferred to later?

This comment has been minimized.

@Avasam
Copy link
Collaborator

Avasam commented Jan 26, 2024

I don’t like the “Any trick”. I do type checking to accurately handle all cases in my code. Corner cases like this are exactly what I want typing to be correct for: so I get notified that they exist and I can handle them before they become a problem.

Unless anything is incorrect, can this please be merged and nitpicks and design choices deferred to later?

I understand your feeling on this, and I agree, but, if you first introduce less disruptive changes (ie, by using the Any trick for example), then other maintainers are likely be more inclined to merge as-is (my understanding is that the primer output is the only thing blocking @srittau 's approval)
Then the change to "potentially None" can be the only thing that gets debated over in its own PR.

@flying-sheep
Copy link
Contributor Author

Sounds good, I can do that. I wanted to discuss this, but I agree that merging this is higher priority than getting that specific facet right.

This comment has been minimized.

@Avasam
Copy link
Collaborator

Avasam commented Jan 27, 2024

Trying to cleanup the "messages only changes" in the last primer output ([-+](.+?: error:).+?\n([-+]\1.+?\n)+) gives me the following:

- sphinx/addnodes.py: note: At top level:
- sphinx/addnodes.py:172: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/util/nodes.py: note: In function "apply_source_workaround":
+ sphinx/util/nodes.py:130:21: error: Unsupported operand types for - ("None" and "int")  [operator]
+ sphinx/util/nodes.py:130:21: note: Left operand is of type "Union[int, None, Any]"
+ sphinx/util/nodes.py: note: At top level:
+ sphinx/util/docutils.py: note: In function "register_role":
+ sphinx/util/docutils.py:104:37: error: Argument 2 to "register_local_role" has incompatible type "Callable[[str, str, str, int, Inliner, dict[str, Any], Sequence[str]], tuple[list[Node], list[system_message]]]"; expected "Callable[[str, str, str, int, Inliner, dict[str, Any], list[str]], tuple[list[reference], list[reference]]]"  [arg-type]
- sphinx/util/docutils.py:124: error: Unused "type: ignore" comment  [unused-ignore]
- sphinx/util/docutils.py: note: In member "dispatch_visit" of class "SphinxTranslator":
- sphinx/util/docutils.py:588:13: error: "dispatch_visit" undefined in superclass  [misc]
- sphinx/util/docutils.py: note: In member "dispatch_departure" of class "SphinxTranslator":
- sphinx/util/docutils.py:605:13: error: "dispatch_departure" undefined in superclass  [misc]
- sphinx/util/docutils.py: note: In function "new_document":
- sphinx/util/docutils.py:636:44: error: Argument 2 to "document" has incompatible type "Reporter"; expected "Node"  [arg-type]
- sphinx/writers/html5.py: note: In member "depart_term" of class "HTML5Translator":
+ sphinx/roles.py: note: In function "setup":
+ sphinx/roles.py:445:45: error: Argument 2 to "register_local_role" has incompatible type "Callable[[str, str, str, int, Inliner, dict[str, Any], Sequence[str]], tuple[list[Node], list[system_message]]]"; expected "Callable[[str, str, str, int, Inliner, dict[str, Any], list[str]], tuple[list[reference], list[reference]]]"  [arg-type]
- sphinx/environment/adapters/toctree.py:169: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/environment/adapters/toctree.py:422:20: error: Item "Node" of "Union[Node, Any]" has no attribute "get"  [union-attr]
+ sphinx/environment/adapters/toctree.py:426:21: error: Unsupported target for indexed assignment ("Node")  [index]
+ sphinx/transforms/i18n.py: note: In member "update_title_mapping" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:185:17: error: Incompatible types in assignment (expression has type "Node", variable has type "target")  [assignment]
+ sphinx/transforms/i18n.py: note: In member "update_autofootnote_references" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:202:14: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "footnote_reference"  [list-item]
+ sphinx/transforms/i18n.py:204:14: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "footnote_reference"  [list-item]
+ sphinx/transforms/i18n.py:215:17: error: Item "Node" of "Union[Node, Any]" has no attribute "remove"  [union-attr]
+ sphinx/transforms/i18n.py: note: In member "update_refnamed_references" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:243:45: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "reference"  [list-item]
+ sphinx/transforms/i18n.py:244:45: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "reference"  [list-item]
+ sphinx/transforms/i18n.py: note: In member "update_refnamed_footnote_references" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:267:59: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "footnote_reference"  [list-item]
+ sphinx/transforms/i18n.py:269:59: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "footnote_reference"  [list-item]
+ sphinx/transforms/i18n.py: note: In member "update_citation_references" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:285:59: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "citation_reference"  [list-item]
+ sphinx/transforms/i18n.py:286:59: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "citation_reference"  [list-item]
+ sphinx/transforms/i18n.py:414:59: error: Argument 4 to "publish_msgstr" has incompatible type "Optional[int]"; expected "int"  [arg-type]
+ sphinx/transforms/i18n.py:417:66: error: Argument 5 to "make_glossary_term" has incompatible type "Optional[int]"; expected "int"  [arg-type]
+ sphinx/transforms/i18n.py:480:36: error: Argument 4 to "publish_msgstr" has incompatible type "Optional[int]"; expected "int"  [arg-type]
+ sphinx/transforms/i18n.py:446: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/transforms/i18n.py: note: In member "apply" of class "RemoveTranslatableInline":
+ sphinx/transforms/i18n.py:614:13: error: Item "Node" of "Union[Node, Any]" has no attribute "remove"  [union-attr]
+ sphinx/transforms/i18n.py:615:13: error: Unsupported left operand type for + ("Node")  [operator]
+ sphinx/transforms/i18n.py:615:13: note: Left operand is of type "Union[Node, Any]"
+ sphinx/search/__init__.py: note: In member "dispatch_visit" of class "WordCollector":
+ sphinx/search/__init__.py:234:19: error: Value of type "Union[Node, Any]" is not indexable  [index]
+ sphinx/search/__init__.py:237:62: error: Argument 1 to "_is_meta_keywords" has incompatible type "Element"; expected "meta"  [arg-type]
+ sphinx/search/__init__.py: note: At top level:
+ sphinx/search/__init__.py: note: In function "_visit_nodes":
+ sphinx/search/__init__.py:506:23: error: Value of type "Union[Node, Any]" is not indexable  [index]
+ sphinx/builders/_epub_base.py: note: In member "get_refnodes" of class "EpubBuilder":
+ sphinx/builders/_epub_base.py:196:23: error: Item "Node" of "Union[Node, Any]" has no attribute "attributes"  [union-attr]
+ sphinx/builders/_epub_base.py: note: In function "add_visible_links":
+ sphinx/builders/_epub_base.py:329:24: error: Incompatible return value type (got "tuple[Union[Node, Any], Any]", expected "tuple[Element, int]")  [return-value]
+ sphinx/builders/_epub_base.py:329:35: error: Item "Node" of "Union[Node, Any]" has no attribute "index"  [union-attr]
+ sphinx/builders/_epub_base.py:332:28: error: Incompatible return value type (got "tuple[Union[Node, Any], Any]", expected "tuple[Element, int]")  [return-value]
+ sphinx/builders/_epub_base.py:332:41: error: Item "Node" of "Union[Node, Any]" has no attribute "index"  [union-attr]
+ sphinx/builders/_epub_base.py: note: In member "add_visible_links" of class "EpubBuilder":
+ sphinx/builders/_epub_base.py:348:23: error: Item "Node" of "Union[Node, Any]" has no attribute "index"  [union-attr]
+ sphinx/builders/_epub_base.py:353:21: error: Item "Node" of "Union[Node, Any]" has no attribute "insert"  [union-attr]
+ sphinx/builders/_epub_base.py:358:21: error: Item "Node" of "Union[Node, Any]" has no attribute "insert"  [union-attr]
- sphinx/writers/latex.py: note: In member "visit_entry" of class "LaTeXTranslator":
- sphinx/writers/latex.py:1163:23: error: Item "None" of "Optional[Node]" has no attribute "parent"  [union-attr]
+ sphinx/writers/latex.py:1240:41: error: Argument 1 to "get_nested_level" has incompatible type "Union[Node, Any]"; expected "Element"  [arg-type]
+ sphinx/domains/citation.py: note: In member "note_citation" of class "CitationDomain":
+ sphinx/domains/citation.py:72:33: error: Incompatible types in assignment (expression has type "tuple[Any, Any, Optional[int]]", target has type "tuple[str, str, int]")  [assignment]
- sphinx/ext/autosectionlabel.py: note: In function "get_node_depth":
- sphinx/ext/autosectionlabel.py:27:20: error: Incompatible types in assignment (expression has type "Optional[Node]", variable has type "Node")  [assignment]
+ sphinx/writers/texinfo.py: note: In member "collect_node_names" of class "TexinfoTranslator":
+ sphinx/writers/texinfo.py:284:45: error: Value of type variable "_N" of "next_node" of "Node" cannot be "Titular"  [type-var]
- sphinx/builders/latex/transforms.py: note: In member "get_docname_for_node" of class "ShowUrlsTransform":
- sphinx/builders/latex/transforms.py:114:24: error: Incompatible types in assignment (expression has type "Optional[Node]", variable has type "Node")  [assignment]
- sphinx/builders/latex/transforms.py: note: At top level:

I think that something really interesting we can see with that primer output, is a lot of assumptions in sphinx code that a value will be a specific subclass of a Node when that can't statically be defined.

Especially for parent attribute. A good example is https://github.com/sphinx-doc/sphinx/blob/master/sphinx/environment/adapters/toctree.py#L422 where subnode is checked to be a reference, but subnode.parent.parent is assumed to be an Element

Or type declarations (: nodes.NodeSubclass & # type: nodes.NodeSubclass comments) that could be removed and work with a basic Node type (most of sphinx/transforms/i18n.py)

@Avasam
Copy link
Collaborator

Avasam commented Jan 27, 2024

Under the exact same reasoning of using "the Any trick", you could be cheeky and type parent as Self | Any, with a setter to deal with variance when assigning a parent.

@property
def parent(self) -> Self | Any: ...
@parent.setter
def parent(self, value: Node) -> None: ...

Still more accurate/safer than just Any whilst avoiding disruptively forcing isinstance calls everywhere from this PR.

Whilst also reinforcing the argument of changing it back to parent: Node | None later to force validating the type anyway.

Quick test: Avasam#38 (comment)

Not sure what other maintainers think of it however. It feels real hacky. The new positives in the output are probably fine.

@flying-sheep
Copy link
Contributor Author

flying-sheep commented Jan 29, 2024

The assumptions are probably there because a lot of subtrees are generated by Sphinx and therefore have a known structure. In that case, apart from some infeasible stack of generics, I don’t think the typing can be improved other than by some “trick”. Another facet is that some nodes do only appear in a certain configuration, e.g. a definition_list_item can only have a definition_list as a parent unless the user creates an invalid tree (there’s no runtime checks, so that’s possible, but the spec says it’s wrong). I could encode some of those assumptions by overriding the parent type for some classes I guess.

Most parents are Elements, so maybe Element | document | Any might be an improvement? But Self is very wrong, a node’s parent is more often of a different type than of the same as the node itself. Unless I misunderstood something, parent: Self | ... would be a bad choice.

@Avasam
Copy link
Collaborator

Avasam commented Jan 29, 2024

apart from some infeasible stack of generics, I don’t think the typing can be improved other than by some “trick”.

And even then seems out of scope for this PR

I could encode some of those assumptions by overriding the parent type for some classes

That might be nice, as it would improve the known type and help prevent the user from creating invalid trees. But I haven't found where that's specified for every Node subclass and might be a rabbit hole of its own.

But Self is very wrong, [...] parent: Self | ... would be a bad choice.

Agreed, my test above was more as a curiosity. Element would likely be enough.

Most parents are Elements, so maybe Element | document | Any might be an improvement?

Not sure why document (it only has transformer as an additional attribute right?). But this is what I'm personally leaning towards. It would address is not indexable and has no attribute new positives.

The only non-Element Node I can find at a glance is Text, which is a terminal node anyway.


Everything else seems like improvements to be done in sphinx itself (more runtime checks of expected types, or casting if they know their own structure)


I'm a bit confused by List item 0 has incompatible type "Generator[Node, None, None]"; expected messages. It's almost as if mypy isn't unpacking the generator type there. But that doesn't sound like an issue of your PR.

@flying-sheep
Copy link
Contributor Author

Not sure why document (it only has transformer as an additional attribute right?).

You’re right, I thought document wasn’t an Element, in which case it’d be necessary. But it is, so Element is enough.

Let’s see how this pans out!

This comment has been minimized.

Copy link
Collaborator

@Avasam Avasam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tentatively approving. The mypy_primer output now looks great.
With the exception of List item 0 has incompatible type "Generator[Node, None, None]"; new positives which are nonsensical to me looking at the source code.

@Avasam Avasam requested a review from srittau January 29, 2024 17:00
Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My previous points were addressed and the primer output looks good. Thanks, @flying-sheep and @Avasam for ironing out the remaining issues!

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

sphinx (https://github.com/sphinx-doc/sphinx)
- sphinx/addnodes.py: note: At top level:
- sphinx/addnodes.py:172: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/util/nodes.py: note: In function "apply_source_workaround":
+ sphinx/util/nodes.py:130:21: error: Unsupported operand types for - ("None" and "int")  [operator]
+ sphinx/util/nodes.py:130:21: note: Left operand is of type "Union[int, None, Any]"
+ sphinx/util/nodes.py: note: At top level:
- sphinx/util/nodes.py: note: In function "traverse_parent":
- sphinx/util/nodes.py:295:16: error: Incompatible types in assignment (expression has type "Optional[Node]", variable has type "Element")  [assignment]
- sphinx/util/nodes.py: note: In function "get_prev_node":
- sphinx/util/nodes.py:299:11: error: Item "Node" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/util/nodes.py:299:11: error: Item "None" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/util/nodes.py:301:16: error: Value of type "Optional[Node]" is not indexable  [index]
- sphinx/util/nodes.py: note: In function "clean_astext":
- sphinx/util/nodes.py:345:9: error: Item "Node" of "Optional[Node]" has no attribute "remove"  [union-attr]
- sphinx/util/nodes.py:345:9: error: Item "None" of "Optional[Node]" has no attribute "remove"  [union-attr]
- sphinx/util/nodes.py: note: In function "inline_all_toctrees":
- sphinx/util/nodes.py:435:9: error: Item "Node" of "Optional[Node]" has no attribute "replace"  [union-attr]
- sphinx/util/nodes.py:435:9: error: Item "None" of "Optional[Node]" has no attribute "replace"  [union-attr]
- sphinx/util/nodes.py: note: In function "is_smartquotable":
- sphinx/util/nodes.py:596:34: error: Argument 1 to "traverse_parent" has incompatible type "Optional[Node]"; expected "Element"  [arg-type]
+ sphinx/util/docutils.py: note: In function "register_role":
+ sphinx/util/docutils.py:104:37: error: Argument 2 to "register_local_role" has incompatible type "Callable[[str, str, str, int, Inliner, dict[str, Any], Sequence[str]], tuple[list[Node], list[system_message]]]"; expected "Callable[[str, str, str, int, Inliner, dict[str, Any], list[str]], tuple[list[reference], list[reference]]]"  [arg-type]
- sphinx/util/docutils.py:267:22: error: Incompatible types in assignment (expression has type "Callable[[str, Module, int, Reporter], tuple[Callable[[str, str, str, int, Inliner, dict[str, Any], Sequence[str]], tuple[list[Node], list[system_message]]], list[system_message]]]", variable has type "Callable[[str, _LanguageModule, int, Reporter], tuple[Optional[Callable[[str, str, str, int, Inliner, dict[str, Any], list[str]], tuple[list[Any], list[Any]]]], list[SystemMessage]]]")  [assignment]
+ sphinx/util/docutils.py:267:22: error: Incompatible types in assignment (expression has type "Callable[[str, Module, int, Reporter], tuple[Callable[[str, str, str, int, Inliner, dict[str, Any], Sequence[str]], tuple[list[Node], list[system_message]]], list[system_message]]]", variable has type "Callable[[str, _LanguageModule, int, Reporter], tuple[Optional[Callable[[str, str, str, int, Inliner, dict[str, Any], list[str]], tuple[list[reference], list[reference]]]], list[SystemMessage]]]")  [assignment]
- sphinx/util/docutils.py:124: error: Unused "type: ignore" comment  [unused-ignore]
- sphinx/util/docutils.py: note: In member "dispatch_visit" of class "SphinxTranslator":
- sphinx/util/docutils.py:588:13: error: "dispatch_visit" undefined in superclass  [misc]
- sphinx/util/docutils.py: note: In member "dispatch_departure" of class "SphinxTranslator":
- sphinx/util/docutils.py:605:13: error: "dispatch_departure" undefined in superclass  [misc]
- sphinx/util/docutils.py: note: In function "new_document":
- sphinx/util/docutils.py:636:44: error: Argument 2 to "document" has incompatible type "Reporter"; expected "Node"  [arg-type]
- sphinx/writers/html5.py: note: In member "depart_desc_signature_line" of class "HTML5Translator":
- sphinx/writers/html5.py:109:36: error: Argument 1 to "add_permalink_ref" of "HTML5Translator" has incompatible type "Optional[Node]"; expected "Element"  [arg-type]
- sphinx/writers/html5.py: note: At top level:
- sphinx/writers/html5.py: note: In member "depart_term" of class "HTML5Translator":
- sphinx/writers/html5.py:460:27: error: Item "None" of "Optional[Node]" has no attribute "parent"  [union-attr]
- sphinx/writers/html5.py:460:27: error: Item "None" of "Union[Node, None, Any]" has no attribute "parent"  [union-attr]
- sphinx/writers/html5.py: note: In member "visit_title" of class "HTML5Translator":
- sphinx/writers/html5.py:475:28: error: Argument 1 to "add_fignumber" of "HTML5Translator" has incompatible type "Optional[Node]"; expected "Element"  [arg-type]
- sphinx/writers/html5.py: note: In member "depart_title" of class "HTML5Translator":
- sphinx/writers/html5.py:482:17: error: Item "Node" of "Optional[Node]" has no attribute "hasattr"  [union-attr]
- sphinx/writers/html5.py:482:17: error: Item "None" of "Optional[Node]" has no attribute "hasattr"  [union-attr]
- sphinx/writers/html5.py:482:48: error: Value of type "Optional[Node]" is not indexable  [index]
- sphinx/writers/html5.py:485:40: error: Argument 1 to "add_permalink_ref" of "HTML5Translator" has incompatible type "Optional[Node]"; expected "Element"  [arg-type]
- sphinx/writers/html5.py:488:34: error: Value of type "Optional[Node]" is not indexable  [index]
- sphinx/writers/html5.py: note: In member "visit_caption" of class "HTML5Translator":
- sphinx/writers/html5.py:529:28: error: Argument 1 to "add_fignumber" of "HTML5Translator" has incompatible type "Optional[Node]"; expected "Element"  [arg-type]
- sphinx/writers/html5.py: note: In member "depart_caption" of class "HTML5Translator":
- sphinx/writers/html5.py:540:14: error: Item "Node" of "Optional[Node]" has no attribute "get"  [union-attr]
- sphinx/writers/html5.py:540:14: error: Item "None" of "Optional[Node]" has no attribute "get"  [union-attr]
- sphinx/writers/html5.py:541:36: error: Item "None" of "Optional[Node]" has no attribute "parent"  [union-attr]
- sphinx/writers/html5.py:541:36: error: Argument 1 to "add_permalink_ref" of "HTML5Translator" has incompatible type "Union[Node, None, Any]"; expected "Element"  [arg-type]
- sphinx/transforms/__init__.py: note: In function "_reorder_index_target_nodes":
- sphinx/transforms/__init__.py:475:21: error: Item "Node" of "Union[Any, Node, None]" has no attribute "index"  [union-attr]
- sphinx/transforms/__init__.py:475:21: error: Item "None" of "Union[Any, Node, None]" has no attribute "index"  [union-attr]
- sphinx/transforms/__init__.py:476:20: error: Item "Node" of "Union[Any, Node, None]" has no attribute "index"  [union-attr]
- sphinx/transforms/__init__.py:476:20: error: Item "None" of "Union[Any, Node, None]" has no attribute "index"  [union-attr]
- sphinx/transforms/__init__.py:478:13: error: Unsupported target for indexed assignment ("Union[Any, Node, None]")  [index]
+ sphinx/roles.py: note: In function "setup":
+ sphinx/roles.py:445:45: error: Argument 2 to "register_local_role" has incompatible type "Callable[[str, str, str, int, Inliner, dict[str, Any], Sequence[str]], tuple[list[Node], list[system_message]]]"; expected "Callable[[str, str, str, int, Inliner, dict[str, Any], list[str]], tuple[list[reference], list[reference]]]"  [arg-type]
- sphinx/environment/adapters/toctree.py:169: error: Unused "type: ignore" comment  [unused-ignore]
- sphinx/environment/adapters/toctree.py: note: In function "_entries_from_toctree":
- sphinx/environment/adapters/toctree.py:253:23: error: Item "Node" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/environment/adapters/toctree.py:253:23: error: Item "None" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/environment/adapters/toctree.py:255:17: error: Item "Node" of "Optional[Node]" has no attribute "insert"  [union-attr]
- sphinx/environment/adapters/toctree.py:255:17: error: Item "None" of "Optional[Node]" has no attribute "insert"  [union-attr]
- sphinx/environment/adapters/toctree.py:256:13: error: Item "Node" of "Optional[Node]" has no attribute "remove"  [union-attr]
- sphinx/environment/adapters/toctree.py:256:13: error: Item "None" of "Optional[Node]" has no attribute "remove"  [union-attr]
- sphinx/environment/adapters/toctree.py: note: In function "_toctree_add_classes":
- sphinx/environment/adapters/toctree.py:420:38: error: Incompatible types in assignment (expression has type "Optional[Node]", variable has type "Element")  [assignment]
- sphinx/environment/__init__.py:647:17: error: Item "Node" of "Optional[Node]" has no attribute "replace"  [union-attr]
- sphinx/environment/__init__.py:647:17: error: Item "None" of "Optional[Node]" has no attribute "replace"  [union-attr]
- sphinx/domains/python/_object.py: note: In member "_toc_entry_name" of class "PyObject":
- sphinx/domains/python/_object.py:414:19: error: Item "Node" of "Optional[Node]" has no attribute "get"  [union-attr]
- sphinx/domains/python/_object.py:414:19: error: Item "None" of "Optional[Node]" has no attribute "get"  [union-attr]
+ sphinx/transforms/i18n.py: note: In member "update_title_mapping" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:185:17: error: Incompatible types in assignment (expression has type "Node", variable has type "target")  [assignment]
+ sphinx/transforms/i18n.py: note: In member "update_autofootnote_references" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:202:14: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "footnote_reference"  [list-item]
+ sphinx/transforms/i18n.py:204:14: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "footnote_reference"  [list-item]
+ sphinx/transforms/i18n.py: note: In member "update_refnamed_references" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:243:45: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "reference"  [list-item]
+ sphinx/transforms/i18n.py:244:45: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "reference"  [list-item]
+ sphinx/transforms/i18n.py: note: In member "update_refnamed_footnote_references" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:267:59: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "footnote_reference"  [list-item]
+ sphinx/transforms/i18n.py:269:59: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "footnote_reference"  [list-item]
+ sphinx/transforms/i18n.py: note: In member "update_citation_references" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:285:59: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "citation_reference"  [list-item]
+ sphinx/transforms/i18n.py:286:59: error: List item 0 has incompatible type "Generator[Node, None, None]"; expected "citation_reference"  [list-item]
+ sphinx/transforms/i18n.py:414:59: error: Argument 4 to "publish_msgstr" has incompatible type "Optional[int]"; expected "int"  [arg-type]
+ sphinx/transforms/i18n.py:417:66: error: Argument 5 to "make_glossary_term" has incompatible type "Optional[int]"; expected "int"  [arg-type]
+ sphinx/transforms/i18n.py:480:36: error: Argument 4 to "publish_msgstr" has incompatible type "Optional[int]"; expected "int"  [arg-type]
+ sphinx/transforms/i18n.py:446: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/search/__init__.py: note: In member "dispatch_visit" of class "WordCollector":
+ sphinx/search/__init__.py:237:62: error: Argument 1 to "_is_meta_keywords" has incompatible type "Element"; expected "meta"  [arg-type]
+ sphinx/search/__init__.py: note: At top level:
- sphinx/writers/latex.py: note: In member "visit_title" of class "LaTeXTranslator":
- sphinx/writers/latex.py:642:64: error: Argument 1 to "hypertarget_to" of "LaTeXTranslator" has incompatible type "Optional[Node]"; expected "Element"  [arg-type]
- sphinx/writers/latex.py: note: In function "_visit_signature_line":
- sphinx/writers/latex.py:710:24: error: Value of type "Optional[Node]" is not indexable  [index]
- sphinx/writers/latex.py:710:33: error: Item "Node" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/writers/latex.py:710:33: error: Item "None" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/writers/latex.py: note: In member "visit_desc_signature" of class "LaTeXTranslator":
- sphinx/writers/latex.py:760:12: error: Value of type "Optional[Node]" is not indexable  [index]
- sphinx/writers/latex.py: note: In member "visit_entry" of class "LaTeXTranslator":
- sphinx/writers/latex.py:1163:23: error: Item "None" of "Optional[Node]" has no attribute "parent"  [union-attr]
- sphinx/writers/latex.py: note: In function "visit_enumerated_list":
- sphinx/writers/latex.py:1242:41: error: Argument 1 to "get_nested_level" has incompatible type "Optional[Node]"; expected "Element"  [arg-type]
- sphinx/writers/latex.py: note: In member "visit_paragraph" of class "LaTeXTranslator":
- sphinx/writers/latex.py:1331:17: error: Item "Node" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/writers/latex.py:1331:17: error: Item "None" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/writers/latex.py: note: In member "visit_image" of class "LaTeXTranslator":
- sphinx/writers/latex.py:1401:40: error: Argument 1 to "is_inline" of "LaTeXTranslator" has incompatible type "Optional[Node]"; expected "Element"  [arg-type]
- sphinx/writers/latex.py: note: In member "visit_caption" of class "LaTeXTranslator":
- sphinx/writers/latex.py:1532:29: error: Item "Node" of "Optional[Node]" has no attribute "tagname"  [union-attr]
- sphinx/writers/latex.py:1532:29: error: Item "None" of "Optional[Node]" has no attribute "tagname"  [union-attr]
- sphinx/writers/latex.py: note: In function "visit_target":
- sphinx/writers/latex.py:1606:21: error: Item "Node" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/writers/latex.py:1606:21: error: Item "None" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/writers/latex.py:1607:41: error: Value of type "Optional[Node]" is not indexable  [index]
- sphinx/ext/todo.py: note: In member "process" of class "TodoListProcessor":
- sphinx/ext/todo.py:138:17: error: Item "Node" of "Optional[Node]" has no attribute "remove"  [union-attr]
- sphinx/ext/todo.py:138:17: error: Item "None" of "Optional[Node]" has no attribute "remove"  [union-attr]
- sphinx/domains/rst.py: note: In member "_toc_entry_name" of class "ReSTMarkup":
- sphinx/domains/rst.py:79:19: error: Item "Node" of "Optional[Node]" has no attribute "get"  [union-attr]
- sphinx/domains/rst.py:79:19: error: Item "None" of "Optional[Node]" has no attribute "get"  [union-attr]
- sphinx/domains/javascript.py: note: In member "_toc_entry_name" of class "JSObject":
- sphinx/domains/javascript.py:234:19: error: Item "Node" of "Optional[Node]" has no attribute "get"  [union-attr]
- sphinx/domains/javascript.py:234:19: error: Item "None" of "Optional[Node]" has no attribute "get"  [union-attr]
- sphinx/domains/index.py: note: In member "process_doc" of class "IndexDomain":
+ sphinx/domains/citation.py: note: In member "note_citation" of class "CitationDomain":
+ sphinx/domains/citation.py:72:33: error: Incompatible types in assignment (expression has type "tuple[Any, Any, Optional[int]]", target has type "tuple[str, str, int]")  [assignment]
- sphinx/domains/index.py:56:17: error: Item "Node" of "Optional[Node]" has no attribute "remove"  [union-attr]
- sphinx/domains/index.py:56:17: error: Item "None" of "Optional[Node]" has no attribute "remove"  [union-attr]
- sphinx/domains/cpp/_ast.py: note: In member "describe_signature" of class "ASTParametersQualifiers":
- sphinx/domains/cpp/_ast.py:1621:29: error: Incompatible types in assignment (expression has type "Node", variable has type "Element")  [assignment]
- sphinx/domains/c/_ast.py: note: In member "describe_signature" of class "ASTParameters":
- sphinx/domains/c/_ast.py:639:29: error: Incompatible types in assignment (expression has type "Node", variable has type "Element")  [assignment]
- sphinx/domains/cpp/__init__.py: note: In member "_toc_entry_name" of class "CPPObject":
- sphinx/domains/cpp/__init__.py:310:19: error: "Node" has no attribute "get"  [attr-defined]
- sphinx/writers/manpage.py:60:23: error: Item "Node" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/writers/manpage.py:60:23: error: Item "None" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/writers/manpage.py:64:25: error: Item "Node" of "Optional[Node]" has no attribute "insert"  [union-attr]
- sphinx/writers/manpage.py:64:25: error: Item "None" of "Optional[Node]" has no attribute "insert"  [union-attr]
- sphinx/writers/manpage.py:67:25: error: Item "Node" of "Optional[Node]" has no attribute "insert"  [union-attr]
- sphinx/writers/manpage.py:67:25: error: Item "None" of "Optional[Node]" has no attribute "insert"  [union-attr]
- sphinx/writers/manpage.py:70:21: error: Item "Node" of "Optional[Node]" has no attribute "remove"  [union-attr]
- sphinx/writers/manpage.py:70:21: error: Item "None" of "Optional[Node]" has no attribute "remove"  [union-attr]
- sphinx/ext/autosectionlabel.py: note: In function "get_node_depth":
- sphinx/ext/autosectionlabel.py:27:20: error: Incompatible types in assignment (expression has type "Optional[Node]", variable has type "Node")  [assignment]
- sphinx/ext/autodoc/typehints.py: note: In function "merge_typehints":
- sphinx/ext/autodoc/typehints.py:52:51: error: Value of type "Optional[Node]" is not indexable  [index]
- sphinx/environment/collectors/toctree.py: note: In function "process_doc":
- sphinx/environment/collectors/toctree.py:123:36: error: Item "Node" of "Optional[Node]" has no attribute "get"  [union-attr]
- sphinx/environment/collectors/toctree.py:123:36: error: Item "None" of "Optional[Node]" has no attribute "get"  [union-attr]
- sphinx/writers/texinfo.py: note: In member "visit_target" of class "TexinfoTranslator":
- sphinx/writers/texinfo.py:664:20: error: Item "Node" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/writers/texinfo.py:664:20: error: Item "None" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/writers/texinfo.py:667:24: error: Value of type "Optional[Node]" is not indexable  [index]
- sphinx/writers/texinfo.py:671:24: error: Item "None" of "Optional[Node]" has no attribute "parent"  [union-attr]
- sphinx/writers/texinfo.py:671:24: error: Value of type "Union[Node, None, Any]" is not indexable  [index]
- sphinx/writers/texinfo.py:671:43: error: Item "Node" of "Union[Node, None, Any]" has no attribute "index"  [union-attr]
- sphinx/writers/texinfo.py:671:43: error: Item "None" of "Union[Node, None, Any]" has no attribute "index"  [union-attr]
- sphinx/writers/texinfo.py: note: In member "visit_desc_signature" of class "TexinfoTranslator":
+ sphinx/writers/texinfo.py: note: In member "collect_node_names" of class "TexinfoTranslator":
+ sphinx/writers/texinfo.py:284:45: error: Value of type variable "_N" of "next_node" of "Node" cannot be "Titular"  [type-var]
- sphinx/writers/texinfo.py:1402:19: error: Value of type "Optional[Node]" is not indexable  [index]
- sphinx/writers/texinfo.py:1408:50: error: Value of type "Optional[Node]" is not indexable  [index]
- sphinx/builders/latex/transforms.py: note: In member "get_docname_for_node" of class "ShowUrlsTransform":
- sphinx/builders/latex/transforms.py:114:24: error: Incompatible types in assignment (expression has type "Optional[Node]", variable has type "Node")  [assignment]
- sphinx/builders/latex/transforms.py: note: At top level:
- sphinx/builders/latex/transforms.py: note: In member "unrestrict" of class "LaTeXFootnoteVisitor":
- sphinx/builders/latex/transforms.py:394:19: error: Item "Node" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/builders/latex/transforms.py:394:19: error: Item "None" of "Optional[Node]" has no attribute "index"  [union-attr]
- sphinx/builders/latex/transforms.py:397:17: error: Item "Node" of "Optional[Node]" has no attribute "insert"  [union-attr]
- sphinx/builders/latex/transforms.py:397:17: error: Item "None" of "Optional[Node]" has no attribute "insert"  [union-attr]

bokeh (https://github.com/bokeh/bokeh)
- src/bokeh/sphinxext/bokeh_roles.py:65: note: In module imported here:

@JelleZijlstra JelleZijlstra merged commit 8018337 into python:main Jan 31, 2024
@flying-sheep flying-sheep deleted the add-node-classes branch January 31, 2024 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants