Skip to content

Allow docutils.readers.standalone.Reader.document to be a docutils.no… #14447

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

adamtheturtle
Copy link
Contributor

…des.document

The use of this in docutils is not trivial but in testing I changed document to a property and created a setter and found that https://github.com/docutils/docutils/blob/9f04802532e77542c8edf6b7f4bf78bab141cf6e/docutils/docutils/readers/__init__.py#L103 was setting this as a nodes.document.
Intuitively it likely is not always None, as well :)

I am making this change because Sphinx sets this to a nodes.document - see sphinx-doc/sphinx#13634.

…des.document

The use of this in docutils is not trivial but in testing I changed `document` to a property and created
a setter and found that https://github.com/docutils/docutils/blob/9f04802532e77542c8edf6b7f4bf78bab141cf6e/docutils/docutils/readers/__init__.py#L103
was setting this as a `nodes.document`.
Intuitively it likely is not always None, as well :)

I am making this change because Sphinx sets this to a `nodes.document`.

This comment has been minimized.

@adamtheturtle
Copy link
Contributor Author

The primer shows what I care about and I guess in Sphinx we can do an assert ... is not None type narrowing given this change.

@adamtheturtle
Copy link
Contributor Author

cc @donBarbos

Copy link
Contributor

@donBarbos donBarbos left a comment

Choose a reason for hiding this comment

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

Indeed, you're right. Thank you.
But to be honest, I don't like any of the approaches, because the problem is in Sphinx itself, it often redefines attributes :-)

I've never contributed there, but I hope more warnings will encourage them to be more careful with attributes

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/io.py:100:16: error: Incompatible return value type (got "None", expected "document")  [return-value]
+ sphinx/io.py:100:16: error: Incompatible return value type (got "document | None", expected "document")  [return-value]

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.

2 participants