diff --git a/distutils/command/build_ext.py b/distutils/command/build_ext.py index c0d61559..5f3b21ff 100644 --- a/distutils/command/build_ext.py +++ b/distutils/command/build_ext.py @@ -13,7 +13,7 @@ from collections.abc import Callable from distutils._log import log from site import USER_BASE -from typing import ClassVar +from typing import ClassVar, cast from .._modified import newer_group from ..ccompiler import CCompiler, new_compiler, show_compilers @@ -736,7 +736,7 @@ def get_ext_filename(self, ext_name: str) -> str: from ..sysconfig import get_config_var ext_path = ext_name.split('.') - ext_suffix = get_config_var('EXT_SUFFIX') + ext_suffix = cast('str | None', get_config_var('EXT_SUFFIX')) or '' return os.path.join(*ext_path) + ext_suffix def get_export_symbols(self, ext: Extension) -> list[str]: @@ -817,7 +817,7 @@ def get_libraries(self, ext: Extension) -> list[str]: link_libpython = True if link_libpython: - ldversion = get_config_var('LDVERSION') + ldversion = cast('str | None', get_config_var('LDVERSION')) or '' return ext.libraries + ['python' + ldversion] return ext.libraries diff --git a/distutils/compilers/C/base.py b/distutils/compilers/C/base.py index 902f8bc5..4c1943e2 100644 --- a/distutils/compilers/C/base.py +++ b/distutils/compilers/C/base.py @@ -16,6 +16,7 @@ ClassVar, Literal, TypeVar, + cast, overload, ) @@ -1082,7 +1083,11 @@ def shared_object_filename( assert output_dir is not None if strip_dir: basename = os.path.basename(basename) - return os.path.join(output_dir, basename + self.shared_lib_extension) + return os.path.join( + output_dir, + # cast: we only allow basename to PathLike if strip_dir=True, so we always coerce + cast("str", basename) + (self.shared_lib_extension or ''), + ) @overload def executable_filename( @@ -1107,7 +1112,11 @@ def executable_filename( assert output_dir is not None if strip_dir: basename = os.path.basename(basename) - return os.path.join(output_dir, basename + (self.exe_extension or '')) + return os.path.join( + output_dir, + # cast: we only allow basename to PathLike if strip_dir=True, so we always coerce + cast("str", basename) + (self.exe_extension or ''), + ) def library_filename( self, diff --git a/mypy.ini b/mypy.ini index 48ddecfd..85f31821 100644 --- a/mypy.ini +++ b/mypy.ini @@ -24,7 +24,6 @@ disable_error_code = return-value, type-var, # TODO: Resolve and re-enable these gradually - operator, arg-type, allow_redefinition = true