From 05eb3c6054fbf8777abf07f711fb82da9b35be4e Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 3 Jan 2021 23:23:01 +0900 Subject: [PATCH] refactor: Index class becomes subclasses of abc.ABC The `Index` class becomes subclasses of `abc.ABC` to indicate methods that must be overrided in the concrete classes. --- CHANGES | 2 ++ sphinx/domains/__init__.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 35cea7ce4..641779ddc 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,8 @@ Dependencies Incompatible changes -------------------- +* domain: The ``Index`` class becomes subclasses of ``abc.ABC`` to indicate + methods that must be overrided in the concrete classes * #4826: py domain: The structure of python objects is changed. A boolean value is added to indicate that the python object is canonical one * #7425: MathJax: The MathJax was changed from 2 to 3. Users using a custom diff --git a/sphinx/domains/__init__.py b/sphinx/domains/__init__.py index 3439ea93c..d241b1523 100644 --- a/sphinx/domains/__init__.py +++ b/sphinx/domains/__init__.py @@ -10,6 +10,7 @@ """ import copy +from abc import ABC, abstractmethod from typing import (TYPE_CHECKING, Any, Callable, Dict, Iterable, List, NamedTuple, Tuple, Type, Union, cast) @@ -64,7 +65,7 @@ class IndexEntry(NamedTuple): descr: str -class Index: +class Index(ABC): """ An Index is the description for a domain-specific index. To add an index to a domain, subclass Index, overriding the three name attributes: @@ -97,6 +98,7 @@ class Index: % self.__class__.__name__) self.domain = domain + @abstractmethod def generate(self, docnames: Iterable[str] = None ) -> Tuple[List[Tuple[str, List[IndexEntry]]], bool]: """Get entries for the index.