From c670eab917863295c80bd4e6487cc4c2d9efab5b Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:12:30 +0100 Subject: [PATCH] Fix mypy errors on Windows --- pyproject.toml | 2 ++ sphinx/locale/__init__.py | 15 +++++++++------ sphinx/registry.py | 2 +- sphinx/theming.py | 4 ++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5d6284294ab..556e1ce9d48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,6 +87,8 @@ lint = [ "sphinx-lint", "types-docutils", "types-requests", + "importlib_metadata", # for mypy (Python<=3.9) + "tomli", # for mypy (Python<=3.10) "pytest>=6.0", ] test = [ diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py index 72c1d80700c..f464b4cab99 100644 --- a/sphinx/locale/__init__.py +++ b/sphinx/locale/__init__.py @@ -3,6 +3,7 @@ from __future__ import annotations import locale +import sys from gettext import NullTranslations, translation from os import path from typing import TYPE_CHECKING @@ -156,13 +157,15 @@ def init_console( """ if locale_dir is None: locale_dir = _LOCALE_DIR - try: - # encoding is ignored - language, _ = locale.getlocale(locale.LC_MESSAGES) - except AttributeError: - # LC_MESSAGES is not always defined. Fallback to the default language - # in case it is not. + if sys.platform == 'win32': language = None + else: + try: + # encoding is ignored + language, _ = locale.getlocale(locale.LC_MESSAGES) + except AttributeError: + # Fallback to the default language in case LC_MESSAGES is not defined. + language = None return init([locale_dir], language, catalog, 'console') diff --git a/sphinx/registry.py b/sphinx/registry.py index 1c58ba71341..78878585bdb 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -11,7 +11,7 @@ if sys.version_info >= (3, 10): from importlib.metadata import entry_points else: - from importlib_metadata import entry_points # type: ignore[import-not-found] + from importlib_metadata import entry_points from sphinx.domains import Domain, Index, ObjType from sphinx.domains.std import GenericObject, Target diff --git a/sphinx/theming.py b/sphinx/theming.py index 777ba94b313..5f1ddab24cd 100644 --- a/sphinx/theming.py +++ b/sphinx/theming.py @@ -24,12 +24,12 @@ if sys.version_info >= (3, 11): import tomllib else: - import tomli as tomllib # type: ignore[import-not-found] + import tomli as tomllib if sys.version_info >= (3, 10): from importlib.metadata import entry_points else: - from importlib_metadata import entry_points # type: ignore[import-not-found] + from importlib_metadata import entry_points if TYPE_CHECKING: from typing import TypedDict