-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
add type annotations to docutils.writers #12420
Conversation
This comment has been minimized.
This comment has been minimized.
0c44974
to
447a252
Compare
there's definitely there's definitely some issues with these stubs. can i get your insight? |
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.
For the mypy errors:
- Missing generics are normal, since we didn't specify one.
- Errors on the reader should not be error but it's because the typings are incorrect (there shouldn't be a bound for this type variable).
+ sphinx/builders/latex/__init__.py:281:28: error: Argument "components" to "OptionParser" has incompatible type "tuple[LaTeXWriter]"; expected "Iterable[type[Parser]]" [arg-type]
: the error is in the stub, it should not beIterable[type[Parser]]
butIterable[Component]
(I don't know why it's typed like that and I don't know when it was typed like that).- Concerning the fact that
None
has no attributewalkabout
, this is because the variables are set at runtime when callingwrite()
but this is impossible to indicate as a typing intent I think... unless you useAny
(but it defeats the purpose ..., though this is what's being done for `docutils.parsers.
I'll review other errors after you changed the Reader
class and remove ClassVar
s.
447a252
to
633c048
Compare
This comment has been minimized.
This comment has been minimized.
The only relevant error is now:
and
|
This comment has been minimized.
This comment has been minimized.
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.
Surprisingly, we have no additional issue. So, the remaining issues in Sphinx are real issues IMO:
Cannot override class variable (previously declared on base class "SettingsSpec") with instance variable
We write
settings_spec: tuple[str, Any, tuple[tuple[str, list[str], dict[str, str]], ...]]
but this should be a class var (we can even omit it after this PR is merged). As for the second error, we do self.document.walkabout(visitor)
so we should have some assert
just before the call to help mypy (or just type-ignore it). Finally, for
- sphinx/builders/text.py:74:27: error: Argument 1 to "write" of "Writer" has incompatible type "Node"; expected "document" [arg-type]
It's because we have an incorrect signature:
def write_doc(self, docname: str, doctree: Node) -> None: ...
It should be doctree: nodes.document
instead. Now, we just need to add the generic types now in Sphinx but AFAIK, we only use strings and not bytes.
@AA-Turner do you want to have a look here?
Co-authored-by: James Addison <55152140+jayaddison@users.noreply.github.com>
Diff from mypy_primer, showing the effect of this PR on open source code: sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/io.py:146: error: Unused "type: ignore" comment [unused-ignore]
+ sphinx/io.py:146:25: error: Missing type parameters for generic type "UnfilteredWriter" [type-arg]
+ sphinx/io.py:146:25: note: Error code "type-arg" not covered by "type: ignore" comment
+ sphinx/writers/latex.py:68: error: Unused "type: ignore" comment [unused-ignore]
+ sphinx/writers/latex.py:68:19: error: Missing type parameters for generic type "Writer" [type-arg]
+ sphinx/writers/latex.py:68:19: note: Error code "type-arg" not covered by "type: ignore" comment
+ sphinx/writers/latex.py: note: In class "LaTeXWriter":
+ sphinx/writers/latex.py:77:5: error: Cannot override class variable (previously declared on base class "SettingsSpec") with instance variable [misc]
+ sphinx/writers/latex.py: note: In member "translate" of class "LaTeXWriter":
+ sphinx/writers/latex.py:87:9: error: Item "None" of "document | None" has no attribute "walkabout" [union-attr]
+ sphinx/writers/text.py:359: error: Unused "type: ignore" comment [unused-ignore]
+ sphinx/writers/text.py:359:18: error: Missing type parameters for generic type "Writer" [type-arg]
+ sphinx/writers/text.py:359:18: note: Error code "type-arg" not covered by "type: ignore" comment
+ sphinx/writers/text.py: note: In class "TextWriter":
+ sphinx/writers/text.py:362:5: error: Cannot override class variable (previously declared on base class "SettingsSpec") with instance variable [misc]
+ sphinx/writers/text.py: note: In member "translate" of class "TextWriter":
+ sphinx/writers/text.py:372:9: error: Item "None" of "document | None" has no attribute "walkabout" [union-attr]
+ sphinx/writers/texinfo.py:107: error: Unused "type: ignore" comment [unused-ignore]
+ sphinx/writers/texinfo.py:107:21: error: Missing type parameters for generic type "Writer" [type-arg]
+ sphinx/writers/texinfo.py:107:21: note: Error code "type-arg" not covered by "type: ignore" comment
+ sphinx/writers/texinfo.py: note: In class "TexinfoWriter":
+ sphinx/writers/texinfo.py:112:5: error: Cannot override class variable (previously declared on base class "SettingsSpec") with instance variable [misc]
+ sphinx/writers/texinfo.py:120:5: error: Cannot override class variable (previously declared on base class "SettingsSpec") with instance variable [misc]
+ sphinx/writers/texinfo.py: note: In member "translate" of class "TexinfoWriter":
+ sphinx/writers/texinfo.py:133:9: error: Item "None" of "document | None" has no attribute "walkabout" [union-attr]
|
No description provided.