From 2ccbc3209ab8ead125a27dadaac26055b117fb73 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:26:05 +0000 Subject: [PATCH] Use type hints for directories --- sphinx/builders/__init__.py | 9 +++++---- sphinx/environment/__init__.py | 5 ++--- sphinx/writers/html5.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index f17331842..142041738 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -48,6 +48,7 @@ if TYPE_CHECKING: from sphinx.application import Sphinx from sphinx.config import Config from sphinx.events import EventManager + from sphinx.util._pathlib import _StrPath from sphinx.util.tags import Tags @@ -94,10 +95,10 @@ class Builder: supported_data_uri_images: bool = False def __init__(self, app: Sphinx, env: BuildEnvironment) -> None: - self.srcdir = app.srcdir - self.confdir = app.confdir - self.outdir = app.outdir - self.doctreedir = app.doctreedir + self.srcdir: _StrPath = app.srcdir + self.confdir: _StrPath = app.confdir + self.outdir: _StrPath = app.outdir + self.doctreedir: _StrPath = app.doctreedir ensuredir(self.doctreedir) self.app: Sphinx = app diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index e63e6c383..397b3667e 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -32,7 +32,6 @@ from sphinx.util.osutil import _last_modified_time, canon_path, os_path if TYPE_CHECKING: from collections.abc import Callable, Iterable, Iterator - from pathlib import Path from typing import Any, Literal from docutils import nodes @@ -102,8 +101,8 @@ class BuildEnvironment: def __init__(self, app: Sphinx) -> None: self.app: Sphinx = app - self.doctreedir: Path = app.doctreedir - self.srcdir: Path = app.srcdir + self.doctreedir: _StrPath = app.doctreedir + self.srcdir: _StrPath = app.srcdir self.config: Config = None # type: ignore[assignment] self.config_status: int = CONFIG_UNSET self.config_status_extra: str = '' diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index b6e342ac1..0ca97c5f3 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -752,7 +752,7 @@ class HTML5Translator(SphinxTranslator, BaseTranslator): # type: ignore[misc] # but it tries the final file name, which does not necessarily exist # yet at the time the HTML file is written. if not ('width' in node and 'height' in node): - path = os.path.join(self.builder.srcdir, olduri) # type: ignore[has-type] + path = os.path.join(self.builder.srcdir, olduri) size = get_image_size(path) if size is None: logger.warning(