John Snow <js...@redhat.com> writes:

> On Fri, Mar 7, 2025 at 7:00 AM Markus Armbruster <arm...@redhat.com> wrote:
>
>> John Snow <js...@redhat.com> writes:
>>
>> > Now that the legacy code is factored out, fix up the typing on the
>> > remaining code in qapidoc.py. Add a type ignore to qapi_legacy.py to
>> > prevent the errors there from bleeding out into qapidoc.py.
>> >
>> > Signed-off-by: John Snow <js...@redhat.com>
>> > ---
>> >  docs/sphinx/qapidoc.py        | 40 ++++++++++++++++++++++-------------
>> >  docs/sphinx/qapidoc_legacy.py |  1 +
>> >  2 files changed, 26 insertions(+), 15 deletions(-)
>> >
>> > diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py
>> > index f4abf42e7bf..5246832b68c 100644
>> > --- a/docs/sphinx/qapidoc.py
>> > +++ b/docs/sphinx/qapidoc.py
>> > @@ -24,17 +24,18 @@
>> >  https://www.sphinx-doc.org/en/master/development/index.html
>> >  """
>> >
>> > +from __future__ import annotations
>> > +
>> >  import os
>> >  import sys
>> > -from typing import List
>> > +from typing import TYPE_CHECKING
>> >
>> >  from docutils import nodes
>> >  from docutils.parsers.rst import Directive, directives
>> >  from qapi.error import QAPIError
>> > -from qapi.gen import QAPISchemaVisitor
>> > -from qapi.schema import QAPISchema
>> > +from qapi.schema import QAPISchema, QAPISchemaVisitor
>> >
>> > -from qapidoc_legacy import QAPISchemaGenRSTVisitor
>> > +from qapidoc_legacy import QAPISchemaGenRSTVisitor  # type: ignore
>> >  from sphinx import addnodes
>> >  from sphinx.directives.code import CodeBlock
>> >  from sphinx.errors import ExtensionError
>> > @@ -42,6 +43,15 @@
>> >  from sphinx.util.nodes import nested_parse_with_titles
>> >
>> >
>> > +if TYPE_CHECKING:
>> > +    from typing import Any, List, Sequence
>> > +
>> > +    from docutils.statemachine import StringList
>> > +
>> > +    from sphinx.application import Sphinx
>> > +    from sphinx.util.typing import ExtensionMetadata
>>
>> Can you briefly explain why this needs to be conditional?
>>
>
> No requisite, but if they aren't used outside of type hints, they don't
> actually need to be imported at runtime (when we use from __future__ import
> annotations). Improves startup speed slightly and potentially makes the
> plugin less porcelain at runtime.

Should we do that for all typing-only imports everywhere?

[...]


Reply via email to