Skip to content

Commit

Permalink
Improve typing for _ConfigRebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jan 13, 2024
1 parent bcb1825 commit 85400a0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sphinx/builders/_epub_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def init(self) -> None:
self.refnodes: list[dict[str, Any]] = []

def create_build_info(self) -> BuildInfo:
return BuildInfo(self.config, self.tags, ['html', 'epub'])
return BuildInfo(self.config, self.tags, frozenset({'html', 'epub'}))

def get_theme_config(self) -> tuple[str, dict]:
return self.config.epub_theme, self.config.epub_theme_options
Expand Down
7 changes: 4 additions & 3 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@
from sphinx.writers.html5 import HTML5Translator

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Sequence
from collections.abc import Iterable, Iterator, Set

from docutils.nodes import Node

from sphinx.application import Sphinx
from sphinx.config import _ConfigRebuild
from sphinx.environment import BuildEnvironment
from sphinx.util.tags import Tags

Expand Down Expand Up @@ -130,7 +131,7 @@ def __init__(
self,
config: Config | None = None,
tags: Tags | None = None,
config_categories: Sequence[str] = (),
config_categories: Set[_ConfigRebuild] = frozenset(),
) -> None:
self.config_hash = ''
self.tags_hash = ''
Expand Down Expand Up @@ -239,7 +240,7 @@ def init(self) -> None:
self.use_index = self.get_builder_config('use_index', 'html')

def create_build_info(self) -> BuildInfo:
return BuildInfo(self.config, self.tags, ['html'])
return BuildInfo(self.config, self.tags, frozenset({'html'}))

def _get_translations_js(self) -> str:
candidates = [path.join(dir, self.config.language,
Expand Down
12 changes: 9 additions & 3 deletions sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

if TYPE_CHECKING:
import os
from collections.abc import Collection, Iterator, Sequence
from collections.abc import Collection, Iterator, Sequence, Set

from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment
Expand All @@ -33,7 +33,13 @@

logger = logging.getLogger(__name__)

_ConfigRebuild = Literal['', 'env', 'epub', 'gettext', 'html']
_ConfigRebuild = Literal[
'', 'env', 'epub', 'gettext', 'html',
# sphinxcontrib-applehelp
'applehelp',
# sphinxcontrib-devhelp
'devhelp',
]

CONFIG_FILENAME = 'conf.py'
UNSERIALIZABLE_TYPES = (type, types.ModuleType, types.FunctionType)
Expand Down Expand Up @@ -423,7 +429,7 @@ def add(self, name: str, default: Any, rebuild: _ConfigRebuild,
valid_types = _validate_valid_types(types)
self._options[name] = _Opt(default, rebuild, valid_types)

def filter(self, rebuild: str | Sequence[str]) -> Iterator[ConfigValue]:
def filter(self, rebuild: Set[_ConfigRebuild]) -> Iterator[ConfigValue]:
if isinstance(rebuild, str):
return (value for value in self if value.rebuild == rebuild)
return (value for value in self if value.rebuild in rebuild)
Expand Down
2 changes: 1 addition & 1 deletion sphinx/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def _update_config(self, config: Config) -> None:
else:
# check if a config value was changed that affects how
# doctrees are read
for item in config.filter('env'):
for item in config.filter(frozenset({'env'})):
if self.config[item.name] != item.value:
self.config_status = CONFIG_CHANGED
self.config_status_extra = f' ({item.name!r})'
Expand Down

0 comments on commit 85400a0

Please sign in to comment.