From 6450313237bc269394ed389fed065f12607884a4 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 24 Jan 2024 22:29:30 -0500 Subject: [PATCH] Trivial fixes --- setuptools/command/easy_install.py | 11 ++++++++++- setuptools/command/upload_docs.py | 2 +- setuptools/config/pyprojecttoml.py | 8 ++++++-- setuptools/msvc.py | 4 +++- setuptools/sandbox.py | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index f73d857f084..4b484c85bca 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -11,6 +11,7 @@ """ from glob import glob +from typing import TYPE_CHECKING, Optional, Union from distutils.util import get_platform from distutils.util import convert_path, subst_vars from distutils.errors import ( @@ -78,6 +79,8 @@ from .._path import ensure_directory from ..extern.jaraco.text import yield_lines +if TYPE_CHECKING: + _FileDescriptorOrPath = Union[int, str, bytes, os.PathLike[str], os.PathLike[bytes]] # Turn on PEP440Warnings warnings.filterwarnings("default", category=pkg_resources.PEP440Warning) @@ -2016,7 +2019,13 @@ def is_python_script(script_text, filename): from os import chmod as _chmod except ImportError: # Jython compatibility - def _chmod(*args): + def _chmod( + path: "_FileDescriptorOrPath", + mode: int, + *, + dir_fd: Optional[int] = None, + follow_symlinks: bool = True, + ) -> None: pass diff --git a/setuptools/command/upload_docs.py b/setuptools/command/upload_docs.py index 32c9abd796f..5de0721bd49 100644 --- a/setuptools/command/upload_docs.py +++ b/setuptools/command/upload_docs.py @@ -50,7 +50,7 @@ def has_sphinx(self): and metadata.entry_points(group='distutils.commands', name='build_sphinx') ) - sub_commands = [('build_sphinx', has_sphinx)] + sub_commands = [('build_sphinx', has_sphinx)] # type: ignore[list-item] # distutils stubs issue w/ Python 3.12 def initialize_options(self): upload.initialize_options(self) diff --git a/setuptools/config/pyprojecttoml.py b/setuptools/config/pyprojecttoml.py index 321e106e406..825f2d62c74 100644 --- a/setuptools/config/pyprojecttoml.py +++ b/setuptools/config/pyprojecttoml.py @@ -296,7 +296,10 @@ def _obtain(self, dist: "Distribution", field: str, package_dir: Mapping[str, st def _obtain_version(self, dist: "Distribution", package_dir: Mapping[str, str]): # Since plugins can set version, let's silently skip if it cannot be obtained if "version" in self.dynamic and "version" in self.dynamic_cfg: - return _expand.version(self._obtain(dist, "version", package_dir)) + return _expand.version( + # We already do an early check for the presence of "version" + self._obtain(dist, "version", package_dir) # pyright: ignore[reportArgumentType] + ) return None def _obtain_readme(self, dist: "Distribution") -> Optional[Dict[str, str]]: @@ -306,9 +309,10 @@ def _obtain_readme(self, dist: "Distribution") -> Optional[Dict[str, str]]: dynamic_cfg = self.dynamic_cfg if "readme" in dynamic_cfg: return { + # We already do an early check for the presence of "readme" "text": self._obtain(dist, "readme", {}), "content-type": dynamic_cfg["readme"].get("content-type", "text/x-rst"), - } + } # pyright: ignore[reportReturnType] self._ensure_previously_set(dist, "readme") return None diff --git a/setuptools/msvc.py b/setuptools/msvc.py index aa69db58109..33177503e90 100644 --- a/setuptools/msvc.py +++ b/setuptools/msvc.py @@ -19,10 +19,12 @@ import platform import itertools import subprocess +from typing import TYPE_CHECKING import distutils.errors from setuptools.extern.more_itertools import unique_everseen -if platform.system() == 'Windows': +# https://github.com/python/mypy/issues/8166 +if not TYPE_CHECKING and platform.system() == 'Windows': import winreg from os import environ else: diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index 757074166a1..502f248062d 100644 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -19,7 +19,7 @@ else: _os = sys.modules[os.name] try: - _file = file + _file = file # type: ignore[name-defined] # Check for global variable except NameError: _file = None _open = open