summaryrefslogtreecommitdiff
path: root/sphinx/config.py
diff options
context:
space:
mode:
authorAdam Turner <9087854+aa-turner@users.noreply.github.com>2023-01-01 20:43:59 +0000
committerAdam Turner <9087854+aa-turner@users.noreply.github.com>2023-01-01 20:48:39 +0000
commit14a9289d780240bbce78ad3640e8e1b1b12df43f (patch)
treefd753f5b0f8c7053923b78c8fef2b90b60f9c7fa /sphinx/config.py
parent26f79b0d2dd88b353ac65623897bdfbe8bc07cab (diff)
downloadsphinx-git-14a9289d780240bbce78ad3640e8e1b1b12df43f.tar.gz
Use PEP 604 types
Diffstat (limited to 'sphinx/config.py')
-rw-r--r--sphinx/config.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/sphinx/config.py b/sphinx/config.py
index f72f01e60..4cc04fc2e 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -7,8 +7,7 @@ import traceback
import types
from collections import OrderedDict
from os import getenv, path
-from typing import (TYPE_CHECKING, Any, Callable, Generator, Iterator, NamedTuple, Optional,
- Union)
+from typing import TYPE_CHECKING, Any, Callable, Generator, Iterator, NamedTuple, Optional
from sphinx.errors import ConfigError, ExtensionError
from sphinx.locale import _, __
@@ -32,7 +31,7 @@ copyright_year_re = re.compile(r'^((\d{4}-)?)(\d{4})(?=[ ,])')
class ConfigValue(NamedTuple):
name: str
value: Any
- rebuild: Union[bool, str]
+ rebuild: bool | str
def is_serializable(obj: Any) -> bool:
@@ -58,7 +57,7 @@ class ENUM:
def __init__(self, *candidates: str) -> None:
self.candidates = candidates
- def match(self, value: Union[str, list, tuple]) -> bool:
+ def match(self, value: str | list | tuple) -> bool:
if isinstance(value, (list, tuple)):
return all(item in self.candidates for item in value)
else:
@@ -153,7 +152,7 @@ class Config:
self.overrides = dict(overrides)
self.values = Config.config_values.copy()
self._raw_config = config
- self.setup: Optional[Callable] = config.get('setup', None)
+ self.setup: Callable | None = config.get('setup', None)
if 'extensions' in self.overrides:
if isinstance(self.overrides['extensions'], str):
@@ -164,7 +163,7 @@ class Config:
@classmethod
def read(
- cls, confdir: str, overrides: Optional[dict] = None, tags: Optional[Tags] = None
+ cls, confdir: str, overrides: dict | None = None, tags: Tags | None = None
) -> "Config":
"""Create a Config object from configuration file."""
filename = path.join(confdir, CONFIG_FILENAME)
@@ -300,13 +299,13 @@ class Config:
for name, value in self.values.items():
yield ConfigValue(name, getattr(self, name), value[1])
- def add(self, name: str, default: Any, rebuild: Union[bool, str], types: Any) -> None:
+ def add(self, name: str, default: Any, rebuild: bool | str, types: Any) -> None:
if name in self.values:
raise ExtensionError(__('Config value %r already present') % name)
else:
self.values[name] = (default, rebuild, types)
- def filter(self, rebuild: Union[str, list[str]]) -> Iterator[ConfigValue]:
+ def filter(self, rebuild: str | list[str]) -> Iterator[ConfigValue]:
if isinstance(rebuild, str):
rebuild = [rebuild]
return (value for value in self if value.rebuild in rebuild)
@@ -338,7 +337,7 @@ class Config:
self.__dict__.update(state)
-def eval_config_file(filename: str, tags: Optional[Tags]) -> dict[str, Any]:
+def eval_config_file(filename: str, tags: Tags | None) -> dict[str, Any]:
"""Evaluate a config file."""
namespace: dict[str, Any] = {}
namespace['__file__'] = filename