Skip to content

Commit 17edcc9

Browse files
committed
cleanup
1 parent ed93af8 commit 17edcc9

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

sphinx/util/typing.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import typing
88
from collections.abc import Sequence
99
from contextvars import Context, ContextVar, Token
10-
from functools import partial as _partial
1110
from struct import Struct
1211
from typing import TYPE_CHECKING, Any, Callable, ForwardRef, TypedDict, TypeVar, Union
1312

@@ -431,7 +430,7 @@ def _stringify_literal_arg(arg: Any, mode: str) -> str:
431430
return repr(arg)
432431

433432

434-
# validations functions (keep them as separate functions to handle enumerations
433+
# validation functions (keep them as separate functions to handle enumerations
435434
# values instead of plain strings in the future and to be able to add better
436435
# type annotations using literal values)
437436
def _validate_mode(mode: str, allowed_modes: AbstractSet[str]) -> str:
@@ -442,15 +441,24 @@ def _validate_mode(mode: str, allowed_modes: AbstractSet[str]) -> str:
442441
return mode
443442

444443

445-
_RESTIFY_ALLOWED_MODES: Final[AbstractSet[str]] = {'fully-qualified-except-typing', 'smart'}
446-
_validate_restify_mode = _partial(_validate_mode, allowed_modes=_RESTIFY_ALLOWED_MODES)
444+
def _validate_restify_mode(mode: Any) -> str:
445+
# add more allowed modes here (e.g., enumeration values)
446+
allowed_modes: AbstractSet[str] = {
447+
'fully-qualified-except-typing',
448+
'smart',
449+
}
450+
return _validate_mode(mode, allowed_modes)
451+
452+
453+
def _validate_stringify_mode(mode: Any) -> str:
454+
# add more allowed modes here (e.g., enumeration values)
455+
allowed_modes: AbstractSet[str] = {
456+
'fully-qualified-except-typing',
457+
'fully-qualified',
458+
'smart',
459+
}
460+
return _validate_mode(mode, allowed_modes)
447461

448-
_STRINGIFY_ALLOWED_MODES: Final[AbstractSet[str]] = {
449-
'fully-qualified-except-typing',
450-
'fully-qualified',
451-
'smart',
452-
}
453-
_validate_stringify_mode = _partial(_validate_mode, allowed_modes=_STRINGIFY_ALLOWED_MODES)
454462

455463
# deprecated name -> (object to return, canonical path or empty string, removal version)
456464
_DEPRECATED_OBJECTS: dict[str, tuple[Any, str, tuple[int, int]]] = {

0 commit comments

Comments
 (0)