-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
improve type annotations in 'docutils.nodes.Element' #11539
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
Conversation
ba14955 to
b90a547
Compare
1276d17 to
dcc419b
Compare
This comment has been minimized.
This comment has been minimized.
ec43ca6 to
83b6563
Compare
This comment has been minimized.
This comment has been minimized.
|
could really use your eyes on this one @picnixz! |
|
For this one I'll need my computer because I don't think a review from my phone would be precise enough. Thus, I'll do it next week. |
b75aafd to
246f3de
Compare
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
b17aa64 to
a40d252
Compare
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
| def replace(self, old: Node, new: Node | Sequence[Node]) -> None: ... | ||
| def replace_self(self, new: Node | Sequence[Node]) -> None: ... | ||
| def first_child_matching_class( | ||
| self, childclass: type[Node] | tuple[type[Node], ...], start: int = 0, end: int = sys.maxsize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if childclass also allow unions and union types
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
efce590 to
087e590
Compare
This comment has been minimized.
This comment has been minimized.
|
Could you fix the merge conflict? |
087e590 to
aaa1414
Compare
aaa1414 to
0a83560
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Jelle Zijlstra <[email protected]>
This comment has been minimized.
This comment has been minimized.
@JelleZijlstra this is an interesting one. It seems not all
|
srittau
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below for some notes. Also, why did you remove child_text_separator from some of the classes?
stubs/docutils/docutils/nodes.pyi
Outdated
| def index(self, item: Node, start: int = 0, stop: int = sys.maxsize) -> int: ... | ||
| def previous_sibling(self) -> Node | None: ... | ||
| def __getattr__(self, name: str, /) -> Incomplete: ... | ||
| def is_not_default(self, key: str) -> Literal[0, 1]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether it's better to just return bool here, as this is clearly how it's intended to be used. Using Literal[0, 1] will prevent the return value from being used as a bool, which works at runtime.
Co-authored-by: Sebastian Rittau <[email protected]>
Co-authored-by: Sebastian Rittau <[email protected]>
because this is inherited from the |
|
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: In member "preserve_original_messages" of class "toctree":
+ sphinx/addnodes.py:91:22: error: Need type annotation for "rawentries" [var-annotated]
- sphinx/util/nodes.py: note: In function "_copy_except__document":
- sphinx/util/nodes.py:658:5: error: "Element" has no attribute "tagname" [attr-defined]
- sphinx/util/nodes.py:660:5: error: "Element" has no attribute "attributes" [attr-defined]
+ sphinx/directives/__init__.py: note: In member "run" of class "ObjectDescription":
+ sphinx/directives/__init__.py:299:28: error: Need type annotation for "node_id" [var-annotated]
+ sphinx/domains/std/__init__.py: note: In member "add_target_and_index" of class "Cmdoption":
+ sphinx/domains/std/__init__.py:209:9: error: Need type annotation for "optname" [var-annotated]
+ sphinx/domains/std/__init__.py:231:9: error: Need type annotation for "option" [var-annotated]
+ sphinx/transforms/i18n.py: note: In member "update_title_mapping" of class "_NodeUpdater":
+ sphinx/transforms/i18n.py:140:25: error: Need type annotation for "names" [var-annotated]
+ sphinx/transforms/i18n.py: note: In member "apply" of class "AddTranslationClasses":
+ sphinx/transforms/i18n.py:590:59: error: Argument 1 to "append" of "list" has incompatible type "str"; expected Never [arg-type]
+ sphinx/transforms/i18n.py:593:59: error: Argument 1 to "append" of "list" has incompatible type "str"; expected Never [arg-type]
+ sphinx/writers/latex.py: note: In member "visit_inline" of class "LaTeXTranslator":
+ sphinx/writers/latex.py:2124:9: error: Need type annotation for "classes" (hint: "classes: List[<type>] = ...") [var-annotated]
+ sphinx/writers/latex.py: note: In member "visit_container" of class "LaTeXTranslator":
+ sphinx/writers/latex.py:2156:9: error: Need type annotation for "classes" (hint: "classes: List[<type>] = ...") [var-annotated]
+ sphinx/writers/latex.py: note: In member "depart_container" of class "LaTeXTranslator":
+ sphinx/writers/latex.py:2161:9: error: Need type annotation for "classes" (hint: "classes: List[<type>] = ...") [var-annotated]
- sphinx/environment/collectors/metadata.py:37: error: Unused "type: ignore" comment [unused-ignore]
+ sphinx/environment/collectors/metadata.py: note: In member "process_doc" of class "MetadataCollector":
+ sphinx/environment/collectors/metadata.py:32:56: error: Argument 1 to "first_child_not_matching_class" of "Element" has incompatible type "type[PreBibliographic]"; expected "Union[type[Node], tuple[type[Node], ...]]" [arg-type]
|
No description provided.