Skip to content

Commit

Permalink
Fix various Ruff errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jan 31, 2023
1 parent 7395b05 commit 4c4745a
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 18 deletions.
3 changes: 2 additions & 1 deletion sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import re
import sys
from inspect import Parameter, Signature
from types import ModuleType
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -45,6 +44,8 @@
from sphinx.util.typing import OptionSpec, get_type_hints, restify, stringify_annotation

if TYPE_CHECKING:
from types import ModuleType

from sphinx.ext.autodoc.directive import DocumenterBridge

logger = logging.getLogger(__name__)
Expand Down
6 changes: 4 additions & 2 deletions sphinx/ext/autosummary/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
import pydoc
import re
import sys
from gettext import NullTranslations
from os import path
from typing import Any, NamedTuple, Sequence
from typing import TYPE_CHECKING, Any, NamedTuple, Sequence

from jinja2 import TemplateNotFound
from jinja2.sandbox import SandboxedEnvironment
Expand All @@ -50,6 +49,9 @@
from sphinx.util.osutil import ensuredir
from sphinx.util.template import SphinxTemplateLoader

if TYPE_CHECKING:
from gettext import NullTranslations

logger = logging.getLogger(__name__)


Expand Down
6 changes: 4 additions & 2 deletions sphinx/ext/intersphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import sys
import time
from os import path
from types import ModuleType
from typing import IO, Any, cast
from typing import IO, TYPE_CHECKING, Any, cast
from urllib.parse import urlsplit, urlunsplit

from docutils import nodes
Expand All @@ -48,6 +47,9 @@
from sphinx.util.inventory import InventoryFile
from sphinx.util.typing import Inventory, InventoryItem, RoleFunction

if TYPE_CHECKING:
from types import ModuleType

logger = logging.getLogger(__name__)


Expand Down
6 changes: 4 additions & 2 deletions sphinx/pycode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import tokenize
from collections import OrderedDict
from importlib import import_module
from inspect import Signature
from os import path
from typing import Any
from typing import TYPE_CHECKING, Any
from zipfile import ZipFile

from sphinx.errors import PycodeError
from sphinx.pycode.parser import Parser

if TYPE_CHECKING:
from inspect import Signature


class ModuleAnalyzer:
annotations: dict[tuple[str, str], str]
Expand Down
6 changes: 4 additions & 2 deletions sphinx/testing/path.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import builtins
import os
import shutil
import sys
from typing import IO, Any, Callable
from typing import IO, TYPE_CHECKING, Any, Callable

if TYPE_CHECKING:
import builtins

FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding()

Expand Down
6 changes: 4 additions & 2 deletions sphinx/testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import re
import sys
import warnings
from io import StringIO
from typing import IO, Any, Generator
from typing import IO, TYPE_CHECKING, Any, Generator
from xml.etree import ElementTree

from docutils import nodes
Expand All @@ -19,6 +18,9 @@
from sphinx.testing.path import path
from sphinx.util.osutil import relpath

if TYPE_CHECKING:
from io import StringIO

__all__ = [
'Struct', 'SphinxTestApp', 'SphinxTestAppWrapperForSkipBuilding',
]
Expand Down
2 changes: 1 addition & 1 deletion sphinx/util/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from sphinx.util.console import bold, colorize, term_width_line # type: ignore

if False:
from types import TracebackType
from types import TracebackType # NoQA: TCH003

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion sphinx/util/docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from contextlib import contextmanager
from copy import copy
from os import path
from types import ModuleType
from typing import IO, TYPE_CHECKING, Any, Callable, Generator, cast

import docutils
Expand All @@ -30,6 +29,8 @@
report_re = re.compile('^(.+?:(?:\\d+)?): \\((DEBUG|INFO|WARNING|ERROR|SEVERE)/(\\d+)?\\) ')

if TYPE_CHECKING:
from types import ModuleType

from docutils.frontend import Values

from sphinx.builders import Builder
Expand Down
8 changes: 4 additions & 4 deletions tests/test_build_dirhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def test_dirhtml(app, status, warning):
invdata = InventoryFile.load(f, 'path/to', posixpath.join)

assert 'index' in invdata.get('std:doc')
assert ('Python', '', 'path/to/', '-') == invdata['std:doc']['index']
assert invdata['std:doc']['index'] == ('Python', '', 'path/to/', '-')

assert 'foo/index' in invdata.get('std:doc')
assert ('Python', '', 'path/to/foo/', '-') == invdata['std:doc']['foo/index']
assert invdata['std:doc']['foo/index'] == ('Python', '', 'path/to/foo/', '-')

assert 'index' in invdata.get('std:label')
assert ('Python', '', 'path/to/#index', '-') == invdata['std:label']['index']
assert invdata['std:label']['index'] == ('Python', '', 'path/to/#index', '-')

assert 'foo' in invdata.get('std:label')
assert ('Python', '', 'path/to/foo/#foo', 'foo/index') == invdata['std:label']['foo']
assert invdata['std:label']['foo'] == ('Python', '', 'path/to/foo/#foo', 'foo/index')
2 changes: 1 addition & 1 deletion tests/typing_test_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from inspect import Signature
from numbers import Integral
from numbers import Integral # NoQA: TCH003
from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union


Expand Down

0 comments on commit 4c4745a

Please sign in to comment.