typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Expand docutils.parsters.rst.states

Open adamtheturtle opened this issue 1 year ago • 7 comments

I used stubgen and broke out a few classes.

adamtheturtle avatar Jun 27 '24 08:06 adamtheturtle

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

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/domains/__init__.py:23: note: In module imported here:
+ sphinx/util/docutils.py: note: In member "get_source_info" of class "SphinxDirective":
+ sphinx/util/docutils.py:419:16: error: Incompatible return value type (got "Union[tuple[str, int], tuple[None, None]]", expected "tuple[str, int]")  [return-value]
+ sphinx/ext/autosummary/__init__.py: note: In function "get_table":
+ sphinx/ext/autosummary/__init__.py:411:57: error: Incompatible types in string interpolation (expression has type "Optional[int]", placeholder has type "Union[int, float, SupportsInt]")  [str-format]
+ sphinx/directives/other.py: note: In member "run" of class "Include":
+ sphinx/directives/other.py:418:13: error: Cannot assign to a method  [method-assign]
+ sphinx/directives/other.py:418:47: error: Incompatible types in assignment (expression has type "Callable[[list[str], str], None]", variable has type "Callable[[Union[list[str], StringList], str], None]")  [assignment]
+ sphinx/directives/code.py: note: In member "run" of class "CodeBlock":
+ sphinx/directives/code.py:140:74: error: Argument "location" to "dedent_lines" has incompatible type "Union[tuple[str, int], tuple[None, None]]"; expected "Optional[tuple[str, int]]"  [arg-type]
+ sphinx/directives/code.py: note: In member "run" of class "LiteralInclude":
+ sphinx/directives/code.py:436:48: error: Argument "location" to "read" of "LiteralIncludeReader" has incompatible type "Union[tuple[str, int], tuple[None, None]]"; expected "Optional[tuple[str, int]]"  [arg-type]
+ sphinx/ext/inheritance_diagram.py: note: In member "run" of class "InheritanceDiagram":
+ sphinx/ext/inheritance_diagram.py:389:57: error: Argument 5 has incompatible type "RSTState"; expected "Inliner"  [arg-type]

bokeh (https://github.com/bokeh/bokeh)
- src/bokeh/sphinxext/bokeh_palette_group.py:53: note: In module imported here:
+ src/bokeh/sphinxext/bokeh_palette_group.py:53: note: ... from here:

github-actions[bot] avatar Jun 27 '24 09:06 github-actions[bot]

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

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/ext/autodoc/directive.py: note: In member "run" of class "AutodocDirective":
+ sphinx/ext/autodoc/directive.py:118:30: error: "Reporter" has no attribute "get_source_and_line"  [attr-defined]
+ sphinx/ext/inheritance_diagram.py:381: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/ext/inheritance_diagram.py: note: In member "run" of class "InheritanceDiagram":
+ sphinx/ext/inheritance_diagram.py:389:57: error: Argument 5 has incompatible type "RSTState"; expected "Inliner"  [arg-type]

github-actions[bot] avatar Jun 27 '24 10:06 github-actions[bot]

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

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/ext/autodoc/directive.py: note: In member "run" of class "AutodocDirective":
+ sphinx/ext/autodoc/directive.py:118:30: error: "Reporter" has no attribute "get_source_and_line"  [attr-defined]
+ sphinx/ext/inheritance_diagram.py:381: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/ext/inheritance_diagram.py: note: In member "run" of class "InheritanceDiagram":
+ sphinx/ext/inheritance_diagram.py:389:57: error: Argument 5 has incompatible type "RSTState[Any]"; expected "Inliner"  [arg-type]

github-actions[bot] avatar Jun 27 '24 10:06 github-actions[bot]

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

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/directives/__init__.py:9: note: In module imported here:
+ sphinx/ext/autodoc/directive.py: note: In member "run" of class "AutodocDirective":
+ sphinx/ext/autodoc/directive.py:118:30: error: "Reporter" has no attribute "get_source_and_line"  [attr-defined]
+ sphinx/ext/inheritance_diagram.py:381: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/ext/inheritance_diagram.py: note: In member "run" of class "InheritanceDiagram":
+ sphinx/ext/inheritance_diagram.py:389:57: error: Argument 5 has incompatible type "RSTState[Generic?[_Context?]]"; expected "Inliner"  [arg-type]

github-actions[bot] avatar Jun 27 '24 10:06 github-actions[bot]

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

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/util/nodes.py: note: In function "set_source_info":
+ sphinx/util/nodes.py:580:32: error: Missing type parameters for generic type "Directive"  [type-arg]
+ sphinx/parsers.py:50:17: error: Missing type parameters for generic type "Parser"  [type-arg]
+ sphinx/domains/std/__init__.py: note: In class "StandardDomain":
+ sphinx/domains/std/__init__.py:527:32: error: Missing type parameters for generic type "Directive"  [type-arg]
+ sphinx/ext/autodoc/directive.py: note: In function "parse_generated_content":
+ sphinx/ext/autodoc/directive.py:87:30: error: Argument 1 to "switch_source_input" has incompatible type "RSTState[Any]"; expected "State[Any]"  [arg-type]
+ sphinx/ext/autodoc/directive.py: note: In member "run" of class "AutodocDirective":
+ sphinx/ext/autodoc/directive.py:118:30: error: "Reporter" has no attribute "get_source_and_line"  [attr-defined]
+ sphinx/ext/autosummary/__init__.py: note: In function "get_table":
+ sphinx/ext/autosummary/__init__.py:412:42: error: Argument 1 to "switch_source_input" has incompatible type "RSTState[Any]"; expected "State[Any]"  [arg-type]
+ sphinx/directives/other.py:378:15: error: Missing type parameters for generic type "Include"  [type-arg]
+ sphinx/ext/inheritance_diagram.py:381: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/ext/inheritance_diagram.py: note: In member "run" of class "InheritanceDiagram":
+ sphinx/ext/inheritance_diagram.py:389:57: error: Argument 5 has incompatible type "RSTState[Any]"; expected "Inliner"  [arg-type]

github-actions[bot] avatar Jun 27 '24 10:06 github-actions[bot]

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

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/util/nodes.py: note: In function "set_source_info":
+ sphinx/util/nodes.py:580:32: error: Missing type parameters for generic type "Directive"  [type-arg]
+ sphinx/parsers.py:50:17: error: Missing type parameters for generic type "Parser"  [type-arg]
+ sphinx/domains/std/__init__.py: note: In class "StandardDomain":
+ sphinx/domains/std/__init__.py:527:32: error: Missing type parameters for generic type "Directive"  [type-arg]
+ sphinx/ext/autodoc/directive.py: note: In member "run" of class "AutodocDirective":
+ sphinx/ext/autodoc/directive.py:118:30: error: "Reporter" has no attribute "get_source_and_line"  [attr-defined]
+ sphinx/directives/other.py:378:15: error: Missing type parameters for generic type "Include"  [type-arg]
+ sphinx/ext/inheritance_diagram.py:381: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/ext/inheritance_diagram.py: note: In member "run" of class "InheritanceDiagram":
+ sphinx/ext/inheritance_diagram.py:389:57: error: Argument 5 has incompatible type "RSTState[Any]"; expected "Inliner"  [arg-type]

github-actions[bot] avatar Jun 27 '24 11:06 github-actions[bot]

Looking at the primer output:

+ sphinx/ext/autodoc/directive.py: note: In member "run" of class "AutodocDirective":
+ sphinx/ext/autodoc/directive.py:118:30: error: "Reporter" has no attribute "get_source_and_line"  [attr-defined]

The code is https://github.com/sphinx-doc/sphinx/blob/f85f50e52614c627adbcf43629ca028829454081/sphinx/ext/autodoc/directive.py#L117, and it appears that the authors expect an AttributeError in some cases:

        try:
            source, lineno = reporter.get_source_and_line(
                self.lineno)
        except AttributeError:
            source, lineno = (None, None)

I'm not sure what to do about:

+ sphinx/ext/inheritance_diagram.py: note: In member "run" of class "InheritanceDiagram":
+ sphinx/ext/inheritance_diagram.py:389:57: error: Argument 5 has incompatible type "RSTState"; expected "Inliner"  [arg-type]

Also, this will require users (Sphinx, in the output) to give generic types type parameters.

adamtheturtle avatar Jun 27 '24 11:06 adamtheturtle

Pinging you here as thanks for taking a look at my first foray into TypeVars 😉

adamtheturtle avatar Jul 02 '24 17:07 adamtheturtle

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

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/util/parsing.py: note: In function "nested_parse_to_nodes":
+ sphinx/util/parsing.py:18:12: error: Missing type parameters for generic type "RSTState"  [type-arg]
+ sphinx/util/parsing.py: note: In function "_fresh_title_style_context":
+ sphinx/util/parsing.py:70:39: error: Missing type parameters for generic type "RSTState"  [type-arg]
+ sphinx/util/nodes.py: note: In function "nested_parse_with_titles":
+ sphinx/util/nodes.py:328:37: error: Missing type parameters for generic type "RSTState"  [type-arg]
+ sphinx/ext/autodoc/directive.py: note: In member "run" of class "AutodocDirective":
+ sphinx/ext/autodoc/directive.py:115:30: error: "Reporter" has no attribute "get_source_and_line"  [attr-defined]
+ sphinx/ext/inheritance_diagram.py:381: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/ext/inheritance_diagram.py: note: In member "run" of class "InheritanceDiagram":
+ sphinx/ext/inheritance_diagram.py:389:57: error: Argument 5 has incompatible type "RSTState[Any]"; expected "Inliner"  [arg-type]

github-actions[bot] avatar Jul 03 '24 11:07 github-actions[bot]

Thank you @srittau . I have made the change I believe you wanted.

adamtheturtle avatar Jul 03 '24 11:07 adamtheturtle