Skip to content

Commit b005b81

Browse files
authored
Define __repr__ for ENUM (#13251)
1 parent 31de02c commit b005b81

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

sphinx/config.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ class ENUM:
8383
"""
8484

8585
def __init__(self, *candidates: str | bool | None) -> None:
86-
self.candidates = candidates
86+
self._candidates = frozenset(candidates)
87+
88+
def __repr__(self) -> str:
89+
return f'ENUM({", ".join(sorted(map(repr, self._candidates)))})'
8790

8891
def match(self, value: str | list | tuple) -> bool:
89-
if isinstance(value, list | tuple):
90-
return all(item in self.candidates for item in value)
91-
else:
92-
return value in self.candidates
92+
if isinstance(value, frozenset | list | set | tuple):
93+
return all(item in self._candidates for item in value)
94+
return value in self._candidates
9395

9496

9597
_OptValidTypes: TypeAlias = tuple[()] | tuple[type, ...] | frozenset[type] | ENUM
@@ -803,7 +805,7 @@ def check_confval_types(app: Sphinx | None, config: Config) -> None:
803805
)
804806
logger.warning(
805807
msg.format(
806-
name=name, current=value, candidates=valid_types.candidates
808+
name=name, current=value, candidates=valid_types._candidates
807809
),
808810
once=True,
809811
)

0 commit comments

Comments
 (0)