mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 18:08:31 +07:00
Extract a PlainConfigSchema alias
This commit is contained in:
@@ -64,6 +64,10 @@ class ValidationError(Exception):
|
||||
"""Raised during the validation process of the config on errors."""
|
||||
|
||||
|
||||
PlainConfigSchemaItem = Tuple[str, BaseConfigOption]
|
||||
PlainConfigSchema = Sequence[PlainConfigSchemaItem]
|
||||
|
||||
|
||||
class Config(UserDict):
|
||||
"""
|
||||
MkDocs Configuration dict
|
||||
@@ -72,9 +76,7 @@ class Config(UserDict):
|
||||
for running validation on the structure and contents.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, schema: Sequence[Tuple[str, BaseConfigOption]], config_file_path: Optional[str] = None
|
||||
):
|
||||
def __init__(self, schema: PlainConfigSchema, config_file_path: Optional[str] = None):
|
||||
"""
|
||||
The schema is a Python dict which maps the config name to a validator.
|
||||
"""
|
||||
@@ -192,7 +194,7 @@ class Config(UserDict):
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def get_schema(cls: type) -> Sequence[Tuple[str, BaseConfigOption]]:
|
||||
def get_schema(cls: type) -> PlainConfigSchema:
|
||||
"""
|
||||
Extract ConfigOptions defined in a class (used just as a container) and put them into a schema tuple.
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from urllib.parse import urlsplit, urlunsplit
|
||||
import markdown
|
||||
|
||||
from mkdocs import plugins, theme, utils
|
||||
from mkdocs.config.base import BaseConfigOption, Config, ValidationError
|
||||
from mkdocs.config.base import BaseConfigOption, Config, PlainConfigSchemaItem, ValidationError
|
||||
from mkdocs.exceptions import ConfigurationError
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class SubConfig(BaseConfigOption):
|
||||
enable validation with `validate=True`.
|
||||
"""
|
||||
|
||||
def __init__(self, *config_options, validate=False):
|
||||
def __init__(self, *config_options: PlainConfigSchemaItem, validate=False):
|
||||
super().__init__()
|
||||
self.default = {}
|
||||
self.config_options = config_options
|
||||
@@ -137,7 +137,7 @@ class ConfigItems(ListOfItems):
|
||||
options.
|
||||
"""
|
||||
|
||||
def __init__(self, *config_options, required=False, validate=False):
|
||||
def __init__(self, *config_options: PlainConfigSchemaItem, required=False, validate=False):
|
||||
super().__init__(SubConfig(*config_options, validate=validate))
|
||||
self.required = required
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ Implements the plugin API for MkDocs.
|
||||
|
||||
import logging
|
||||
from collections import OrderedDict
|
||||
from typing import Any, Callable, Dict, Optional, Sequence, Tuple, TypeVar, overload
|
||||
from typing import Any, Callable, Dict, Optional, Tuple, TypeVar, overload
|
||||
|
||||
import importlib_metadata
|
||||
import jinja2.environment
|
||||
|
||||
from mkdocs.config.base import BaseConfigOption, Config
|
||||
from mkdocs.config.base import Config, PlainConfigSchema
|
||||
from mkdocs.livereload import LiveReloadServer
|
||||
from mkdocs.structure.files import Files
|
||||
from mkdocs.structure.nav import Navigation
|
||||
@@ -43,7 +43,7 @@ class BasePlugin:
|
||||
All plugins should subclass this class.
|
||||
"""
|
||||
|
||||
config_scheme: Sequence[Tuple[str, BaseConfigOption]] = ()
|
||||
config_scheme: PlainConfigSchema = ()
|
||||
config: Config = {} # type: ignore[assignment]
|
||||
|
||||
def load_config(
|
||||
|
||||
Reference in New Issue
Block a user