Skip to content

Commit c7d7f29

Browse files
committed
Remove sphinx.locale.setlocale
1 parent 7d928b3 commit c7d7f29

File tree

7 files changed

+13
-33
lines changed

7 files changed

+13
-33
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Incompatible changes
1717
now-obsolete binary distribution format
1818
* #11089: Remove deprecated code in ``sphinx.builders.linkcheck``.
1919
Patch by Daniel Eades
20+
* Remove internal-only ``sphinx.locale.setlocale``
2021

2122
Deprecated
2223
----------

sphinx/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def _init_i18n(self) -> None:
272272
the configuration.
273273
"""
274274
if self.config.language == 'en':
275-
self.translator, has_translation = locale.init([], None)
275+
self.translator, _ = locale.init([], None)
276276
else:
277277
logger.info(bold(__('loading translations [%s]... ') % self.config.language),
278278
nonl=True)

sphinx/cmd/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from docutils.utils import SystemMessage
1717

1818
import sphinx.locale
19-
from sphinx import __display_version__, package_dir
19+
from sphinx import __display_version__
2020
from sphinx.application import Sphinx
2121
from sphinx.errors import SphinxError
2222
from sphinx.locale import __
@@ -310,8 +310,8 @@ def _bug_report_info() -> int:
310310

311311

312312
def main(argv: list[str] = sys.argv[1:]) -> int:
313-
sphinx.locale.setlocale(locale.LC_ALL, '')
314-
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
313+
locale.setlocale(locale.LC_ALL, '')
314+
sphinx.locale.init_console()
315315

316316
if argv[:1] == ['--bug-report']:
317317
return _bug_report_info()

sphinx/cmd/quickstart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,8 @@ def get_parser() -> argparse.ArgumentParser:
540540

541541

542542
def main(argv: list[str] = sys.argv[1:]) -> int:
543-
sphinx.locale.setlocale(locale.LC_ALL, '')
544-
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
543+
locale.setlocale(locale.LC_ALL, '')
544+
sphinx.locale.init_console()
545545

546546
if not color_terminal():
547547
nocolor()

sphinx/ext/apidoc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ def get_parser() -> argparse.ArgumentParser:
392392

393393
def main(argv: list[str] = sys.argv[1:]) -> int:
394394
"""Parse and check the command line arguments."""
395-
sphinx.locale.setlocale(locale.LC_ALL, '')
396-
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
395+
locale.setlocale(locale.LC_ALL, '')
396+
sphinx.locale.init_console()
397397

398398
parser = get_parser()
399399
args = parser.parse_args(argv)

sphinx/ext/autosummary/generate.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,10 @@ def get_parser() -> argparse.ArgumentParser:
636636

637637

638638
def main(argv: list[str] = sys.argv[1:]) -> None:
639-
sphinx.locale.setlocale(locale.LC_ALL, '')
640-
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
641-
translator, _ = sphinx.locale.init([], None)
639+
locale.setlocale(locale.LC_ALL, '')
640+
sphinx.locale.init_console()
642641

643-
app = DummyApplication(translator)
642+
app = DummyApplication(sphinx.locale.get_translator())
644643
logging.setup(app, sys.stdout, sys.stderr) # type: ignore
645644
setup_documenters(app)
646645
args = get_parser().parse_args(argv)

sphinx/locale/__init__.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import locale
44
from gettext import NullTranslations, translation
55
from os import path
6-
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
6+
from typing import Any, Callable, Dict, List, Optional, Tuple
77

88

99
class _TranslationProxy:
@@ -138,26 +138,6 @@ def init(
138138
return translator, has_translation
139139

140140

141-
def setlocale(category: int, value: Union[str, Iterable[str], None] = None) -> None:
142-
"""Update locale settings.
143-
144-
This does not throw any exception even if update fails.
145-
This is workaround for Python's bug.
146-
147-
For more details:
148-
149-
* https://github.com/sphinx-doc/sphinx/issues/5724
150-
* https://bugs.python.org/issue18378#msg215215
151-
152-
.. note:: Only for internal use. Please don't call this method from extensions.
153-
This will be removed in Sphinx 6.0.
154-
"""
155-
try:
156-
locale.setlocale(category, value)
157-
except locale.Error:
158-
pass
159-
160-
161141
_LOCALE_DIR = path.abspath(path.dirname(__file__))
162142

163143

0 commit comments

Comments
 (0)