Skip to content

Commit

Permalink
Require the PEP 563 'annotations' future import
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Nov 22, 2024
1 parent 0e15ad7 commit b6366e1
Show file tree
Hide file tree
Showing 122 changed files with 193 additions and 17 deletions.
7 changes: 5 additions & 2 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ select = [
"TC001", # documentation doesn't need type-checking blocks
]
"doc/conf.py" = ["INP001", "W605"]
"doc/development/tutorials/examples/*" = ["INP001"]
"doc/development/tutorials/examples/*" = ["I002", "INP001"]
# allow print() in the tutorial
"doc/development/tutorials/examples/recipe.py" = [
"FURB118",
Expand Down Expand Up @@ -360,7 +360,7 @@ select = [

# these tests need old ``typing`` generic aliases
"tests/test_util/test_util_typing.py" = ["UP006", "UP007", "UP035"]
"tests/test_util/typing_test_data.py" = ["FA100", "PYI030", "UP006", "UP007", "UP035"]
"tests/test_util/typing_test_data.py" = ["FA100", "I002", "PYI030", "UP006", "UP007", "UP035"]

"utils/*" = [
"T201", # whitelist ``print`` for stdout messages
Expand All @@ -377,6 +377,9 @@ inline-quotes = "single"
forced-separate = [
"tests",
]
required-imports = [
"from __future__ import annotations",
]

[format]
preview = true
Expand Down
1 change: 1 addition & 0 deletions sphinx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Sphinx documentation toolchain."""
from __future__ import annotations

__version__ = '8.2.0'
__display_version__ = __version__ # used for command line version
Expand Down
1 change: 1 addition & 0 deletions sphinx/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Sphinx documentation toolchain."""
from __future__ import annotations

import sys

Expand Down
1 change: 1 addition & 0 deletions sphinx/builders/latex/nodes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Additional nodes for LaTeX writer."""
from __future__ import annotations

from docutils import nodes

Expand Down
7 changes: 6 additions & 1 deletion sphinx/environment/adapters/asset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
"""Assets adapter for sphinx.environment."""
from __future__ import annotations

from typing import TYPE_CHECKING

from sphinx.environment import BuildEnvironment
from sphinx.util._pathlib import _StrPath

if TYPE_CHECKING:
from sphinx.environment import BuildEnvironment


class ImageAdapter:
def __init__(self, env: BuildEnvironment) -> None:
Expand Down
1 change: 1 addition & 0 deletions sphinx/ext/intersphinx/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Command line interface for the intersphinx extension."""
from __future__ import annotations

import logging as _logging
import sys
Expand Down
1 change: 1 addition & 0 deletions sphinx/pygments_styles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sphinx theme specific highlighting styles."""
from __future__ import annotations

from pygments.style import Style
from pygments.styles.friendly import FriendlyStyle
Expand Down
11 changes: 9 additions & 2 deletions sphinx/testing/restructuredtext.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from docutils import nodes
from __future__ import annotations

from typing import TYPE_CHECKING

from docutils.core import publish_doctree

from sphinx.application import Sphinx
from sphinx.io import SphinxStandaloneReader
from sphinx.parsers import RSTParser
from sphinx.util.docutils import sphinx_domains

if TYPE_CHECKING:
from docutils import nodes

from sphinx.application import Sphinx


def parse(app: Sphinx, text: str, docname: str = 'index') -> nodes.document:
"""Parse a string as reStructuredText with Sphinx application."""
Expand Down
3 changes: 3 additions & 0 deletions sphinx/util/_lines.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


def parse_line_num_spec(spec: str, total: int) -> list[int]:
"""Parse a line number spec (such as "1,2,4-6") and return a list of
wanted line numbers.
Expand Down
1 change: 1 addition & 0 deletions sphinx/util/build_phase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Build phase of Sphinx application."""
from __future__ import annotations

from enum import IntEnum

Expand Down
1 change: 1 addition & 0 deletions sphinx/util/http_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Reference: https://www.rfc-editor.org/rfc/rfc7231#section-7.1.1.1
"""
from __future__ import annotations

import time
import warnings
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test all builders."""
from __future__ import annotations

import os
import shutil
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_changes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the ChangesBuilder class."""
from __future__ import annotations

import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_dirhtml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test dirhtml builder."""
from __future__ import annotations

import posixpath

Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_epub.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the HTML builder and check output against XPath."""
from __future__ import annotations

import os
import subprocess
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_gettext.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the build process with gettext builder with the test root."""
from __future__ import annotations

import gettext
import re
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_html_assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the HTML builder and check output against XPath."""
from __future__ import annotations

import re
from pathlib import Path
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_code.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_copyright.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import time

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_download.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import hashlib
import re

Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_highlight.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from unittest.mock import ANY, call, patch

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_image.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import re
from pathlib import Path

Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_html_maths.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from sphinx.errors import ConfigError
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_html_numfig.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the HTML builder and check output against XPath."""
from __future__ import annotations

import os
import re
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_html_tocdepth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the HTML builder and check output against XPath."""
from __future__ import annotations

import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_html_toctree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the HTML builder and check output against XPath."""
from __future__ import annotations

import re
from unittest.mock import patch
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_latex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the build process with LaTeX builder with the test root."""
from __future__ import annotations

import http.server
import os
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_manpage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the build process with manpage builder with the test root."""
from __future__ import annotations

import docutils
import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_texinfo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the build process with Texinfo builder with the test root."""
from __future__ import annotations

import re
import subprocess
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builders/test_build_warnings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import re
import sys
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_incremental_reading.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the Builder class."""
from __future__ import annotations

import sys

Expand Down
1 change: 1 addition & 0 deletions tests/test_config/test_copyright.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test copyright year adjustment"""
from __future__ import annotations

import time

Expand Down
1 change: 1 addition & 0 deletions tests/test_directives/test_directive_code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the code-block directive."""
from __future__ import annotations

import pytest
from docutils import nodes
Expand Down
1 change: 1 addition & 0 deletions tests/test_directives/test_directive_only.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the only directive with the test root."""
from __future__ import annotations

import re

Expand Down
2 changes: 2 additions & 0 deletions tests/test_directives/test_directive_option.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest


Expand Down
1 change: 1 addition & 0 deletions tests/test_directives/test_directive_other.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the other directives."""
from __future__ import annotations

from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions tests/test_directives/test_directive_patch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the patched directives."""
from __future__ import annotations

import pytest
from docutils import nodes
Expand Down
1 change: 1 addition & 0 deletions tests/test_directives/test_directives_no_typesetting.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the directives"""
from __future__ import annotations

import pytest
from docutils import nodes
Expand Down
6 changes: 5 additions & 1 deletion tests/test_domains/test_domain_c.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Tests the C Domain"""
from __future__ import annotations

import itertools
import xml.etree.ElementTree as ET
import zlib
from io import StringIO
from typing import TYPE_CHECKING

import pytest

Expand All @@ -29,6 +30,9 @@
from sphinx.util.cfamily import DefinitionError
from sphinx.writers.text import STDINDENT

if TYPE_CHECKING:
from io import StringIO


class Config:
c_id_attributes = ['id_attr', 'LIGHTGBM_C_EXPORT']
Expand Down
6 changes: 5 additions & 1 deletion tests/test_domains/test_domain_cpp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Tests the C++ Domain"""
from __future__ import annotations

import itertools
import re
import zlib
from io import StringIO
from typing import TYPE_CHECKING

import pytest

Expand All @@ -30,6 +31,9 @@
from sphinx.util.cfamily import DefinitionError, NoOldIdError
from sphinx.writers.text import STDINDENT

if TYPE_CHECKING:
from io import StringIO


def parse(name, string):
class Config:
Expand Down
1 change: 1 addition & 0 deletions tests/test_domains/test_domain_js.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the JavaScript Domain"""
from __future__ import annotations

from unittest.mock import Mock

Expand Down
1 change: 1 addition & 0 deletions tests/test_domains/test_domain_rst.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the reStructuredText domain."""
from __future__ import annotations

import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/test_domains/test_domain_std.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the std domain"""
from __future__ import annotations

from unittest import mock

Expand Down
1 change: 1 addition & 0 deletions tests/test_environment/test_environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the BuildEnvironment class."""
from __future__ import annotations

import shutil
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions tests/test_environment/test_environment_indexentries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the sphinx.environment.adapters.indexentries."""
from __future__ import annotations

import pytest

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for ``record_dependencies``."""
from __future__ import annotations

import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/test_environment/test_environment_toctree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the sphinx.environment.adapters.toctree."""
from __future__ import annotations

import pytest
from docutils import nodes
Expand Down
2 changes: 2 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from sphinx.errors import ExtensionError


Expand Down
1 change: 1 addition & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the EventManager class."""
from __future__ import annotations

import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/test_extensions/ext_napoleon_pep526_data_google.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test module for napoleon PEP 526 compatibility with google style"""
from __future__ import annotations

module_level_var: int = 99
"""This is an example module level variable"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_extensions/ext_napoleon_pep526_data_numpy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test module for napoleon PEP 526 compatibility with numpy style"""
from __future__ import annotations

module_level_var: int = 99
"""This is an example module level variable"""
Expand Down
Loading

0 comments on commit b6366e1

Please sign in to comment.