Skip to content

Commit

Permalink
Remove unneeded runtime typing imports (#13233)
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner authored Jan 12, 2025
1 parent d29c2c1 commit 72ce436
Show file tree
Hide file tree
Showing 102 changed files with 265 additions and 149 deletions.
4 changes: 2 additions & 2 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ select = [
"T10",
# flake8-print ('T20')
"T20",
# flake8-type-checking ('TCH')
"TCH",
# flake8-type-checking ('TC')
"TC",
# flake8-todos ('TD')
# "TD001", # Invalid TODO tag: `{tag}`
# "TD002", # Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...`
Expand Down
3 changes: 3 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,12 @@
('py:class', 'Element'), # sphinx.domains.Domain
('py:class', 'Documenter'), # sphinx.application.Sphinx.add_autodocumenter
('py:class', 'IndexEntry'), # sphinx.domains.IndexEntry
('py:class', 'Inliner'), # sphinx.util.docutils.SphinxRole.inliner
('py:class', 'Lexer'), # sphinx.application.Sphinx.add_lexer
('py:class', 'Node'), # sphinx.domains.Domain
('py:class', 'NullTranslations'), # gettext.NullTranslations
('py:class', 'ObjDescT'), # sphinx.directives.ObjectDescription
('py:class', 'OptionSpec'), # sphinx.directives.ObjectDescription.option_spec
('py:class', 'Path'), # sphinx.application.Sphinx.connect
('py:class', 'RoleFunction'), # sphinx.domains.Domain
('py:class', 'RSTState'), # sphinx.utils.parsing.nested_parse_to_nodes
Expand Down
4 changes: 3 additions & 1 deletion doc/development/tutorials/examples/autodoc_intenum.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import annotations

from enum import IntEnum
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from sphinx.ext.autodoc import ClassDocumenter, bool_option

if TYPE_CHECKING:
from typing import Any

from docutils.statemachine import StringList

from sphinx.application import Sphinx
Expand Down
3 changes: 2 additions & 1 deletion sphinx/addnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from docutils import nodes

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Any

from docutils.nodes import Element

Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
import time
from contextlib import nullcontext
from typing import TYPE_CHECKING, Any, Literal, final
from typing import TYPE_CHECKING, final

from docutils import nodes
from docutils.utils import DependencyList
Expand Down Expand Up @@ -49,6 +49,7 @@
if TYPE_CHECKING:
from collections.abc import Iterable, Sequence, Set
from pathlib import Path
from typing import Any, Literal

from docutils.nodes import Node

Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/_epub_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os.path
import re
import time
from typing import TYPE_CHECKING, Any, NamedTuple
from typing import TYPE_CHECKING, NamedTuple
from urllib.parse import quote
from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile

Expand All @@ -25,6 +25,7 @@

if TYPE_CHECKING:
from pathlib import Path
from typing import Any

from docutils.nodes import Element, Node

Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/epub3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os.path
import re
import time
from typing import TYPE_CHECKING, Any, NamedTuple
from typing import TYPE_CHECKING, NamedTuple

from sphinx import package_dir
from sphinx.builders import _epub_base
Expand All @@ -22,6 +22,7 @@

if TYPE_CHECKING:
from collections.abc import Set
from typing import Any

from sphinx.application import Sphinx
from sphinx.util.typing import ExtensionMetadata
Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections import defaultdict
from os import getenv, path, walk
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal
from typing import TYPE_CHECKING
from uuid import uuid4

from docutils import nodes
Expand All @@ -30,6 +30,7 @@
if TYPE_CHECKING:
import os
from collections.abc import Iterable, Iterator, Sequence
from typing import Any, Literal

from docutils.nodes import Element

Expand Down
4 changes: 2 additions & 2 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import sys
import warnings
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING
from urllib.parse import quote

import docutils.readers.doctree
Expand Down Expand Up @@ -65,7 +65,7 @@

if TYPE_CHECKING:
from collections.abc import Iterator, Set
from typing import TypeAlias
from typing import Any, TypeAlias

from docutils.nodes import Node
from docutils.readers import Reader
Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/html/_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import warnings
import zlib
from functools import cache
from typing import TYPE_CHECKING, Any, NoReturn
from typing import TYPE_CHECKING

from sphinx.deprecation import RemovedInSphinx90Warning
from sphinx.errors import ThemeError

if TYPE_CHECKING:
from pathlib import Path
from typing import Any, NoReturn


class _CascadingStyleSheet:
Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/latex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import os.path
import warnings
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from docutils.frontend import OptionParser

Expand Down Expand Up @@ -39,6 +39,7 @@

if TYPE_CHECKING:
from collections.abc import Iterable, Set
from typing import Any

from docutils.nodes import Node

Expand Down
5 changes: 4 additions & 1 deletion sphinx/builders/latex/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from __future__ import annotations

from typing import Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any

PDFLATEX_DEFAULT_FONTPKG = r"""
\usepackage{tgtermes}
Expand Down
4 changes: 3 additions & 1 deletion sphinx/builders/latex/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, cast
from typing import TYPE_CHECKING, cast

from docutils import nodes
from docutils.transforms.references import Substitutions
Expand All @@ -21,6 +21,8 @@
from sphinx.util.nodes import NodeMatcher

if TYPE_CHECKING:
from typing import Any

from docutils.nodes import Element, Node

from sphinx.application import Sphinx
Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/manpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os.path
import warnings
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from docutils.frontend import OptionParser
from docutils.io import FileOutput
Expand All @@ -21,6 +21,7 @@

if TYPE_CHECKING:
from collections.abc import Set
from typing import Any

from sphinx.application import Sphinx
from sphinx.config import Config
Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/singlehtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from docutils import nodes

Expand All @@ -18,6 +18,7 @@

if TYPE_CHECKING:
from collections.abc import Set
from typing import Any

from docutils.nodes import Node

Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/texinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import os.path
import warnings
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from docutils import nodes
from docutils.frontend import OptionParser
Expand All @@ -26,6 +26,7 @@

if TYPE_CHECKING:
from collections.abc import Iterable, Set
from typing import Any

from docutils.nodes import Node

Expand Down
3 changes: 2 additions & 1 deletion sphinx/cmd/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import multiprocessing
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Any, TextIO
from typing import TYPE_CHECKING

import sphinx._cli.util.errors
import sphinx.locale
Expand All @@ -23,6 +23,7 @@

if TYPE_CHECKING:
from collections.abc import Collection, Sequence
from typing import Any, TextIO

from sphinx.extension import Extension

Expand Down
3 changes: 2 additions & 1 deletion sphinx/cmd/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os.path
import sys
import time
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

# try to import readline, unix specific enhancement
try:
Expand Down Expand Up @@ -38,6 +38,7 @@

if TYPE_CHECKING:
from collections.abc import Callable, Sequence
from typing import Any

EXTENSIONS = {
'autodoc': __('automatically insert docstrings from modules'),
Expand Down
8 changes: 5 additions & 3 deletions sphinx/directives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
from __future__ import annotations

import re
from typing import TYPE_CHECKING, ClassVar, Generic, TypeVar, cast
from typing import TYPE_CHECKING, Generic, TypeVar, cast

from docutils import nodes
from docutils.parsers.rst import directives, roles

from sphinx import addnodes
from sphinx.addnodes import desc_signature # NoQA: TC001
from sphinx.util import docutils
from sphinx.util.docfields import DocFieldTransformer, Field, TypedField
from sphinx.util.docutils import SphinxDirective
from sphinx.util.typing import ExtensionMetadata, OptionSpec # NoQA: TC001

if TYPE_CHECKING:
from typing import ClassVar

from docutils.nodes import Node

from sphinx.addnodes import desc_signature
from sphinx.application import Sphinx
from sphinx.util.typing import ExtensionMetadata, OptionSpec


# RE to strip backslash escapes
Expand Down
3 changes: 2 additions & 1 deletion sphinx/directives/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import textwrap
from difflib import unified_diff
from typing import TYPE_CHECKING, Any, ClassVar
from typing import TYPE_CHECKING

from docutils import nodes
from docutils.parsers.rst import directives
Expand All @@ -18,6 +18,7 @@

if TYPE_CHECKING:
import os
from typing import Any, ClassVar

from docutils.nodes import Element, Node

Expand Down
3 changes: 2 additions & 1 deletion sphinx/directives/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from os.path import abspath, relpath
from pathlib import Path
from typing import TYPE_CHECKING, Any, ClassVar, cast
from typing import TYPE_CHECKING, cast

from docutils import nodes
from docutils.parsers.rst import directives
Expand All @@ -22,6 +22,7 @@

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Any, ClassVar

from docutils.nodes import Element, Node

Expand Down
4 changes: 3 additions & 1 deletion sphinx/directives/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
from pathlib import Path
from typing import TYPE_CHECKING, ClassVar, cast
from typing import TYPE_CHECKING, cast

from docutils import nodes
from docutils.nodes import Node, make_id
Expand All @@ -19,6 +19,8 @@
from sphinx.util.osutil import SEP, relpath

if TYPE_CHECKING:
from typing import ClassVar

from sphinx.application import Sphinx
from sphinx.util.typing import ExtensionMetadata, OptionSpec

Expand Down
3 changes: 2 additions & 1 deletion sphinx/domains/c/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, ClassVar
from typing import TYPE_CHECKING

from docutils import nodes
from docutils.parsers.rst import directives
Expand Down Expand Up @@ -34,6 +34,7 @@

if TYPE_CHECKING:
from collections.abc import Iterator, Set
from typing import Any, ClassVar

from docutils.nodes import Element, Node, TextElement, system_message

Expand Down
Loading

0 comments on commit 72ce436

Please sign in to comment.