Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime changes for typeshed parameter annotations merge #4505

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/4505.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed the order of type checks in ``setuptools.command.easy_install.CommandSpec.from_param`` to support any `collections.abc.Iterable` of `str` param -- by :user:`Avasam`
3 changes: 1 addition & 2 deletions setuptools/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Iterator
from pathlib import Path

from distutils.command.build_ext import build_ext as _du_build_ext
from distutils.ccompiler import new_compiler
from distutils.sysconfig import customize_compiler, get_config_var
from distutils import log
Expand All @@ -24,7 +23,7 @@
# also. Ref #1229.
__import__('Cython.Compiler.Main')
except ImportError:
_build_ext = _du_build_ext
from distutils.command.build_ext import build_ext as _build_ext

# make sure _config_vars is initialized
get_config_var("LDSHARED")
Expand Down
14 changes: 10 additions & 4 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from __future__ import annotations

from collections.abc import Iterable
from glob import glob
from distutils.util import get_platform
from distutils.util import convert_path, subst_vars
Expand All @@ -26,6 +27,7 @@
from distutils.command import install
import sys
import os
from typing import TYPE_CHECKING
import zipimport
import shutil
import tempfile
Expand Down Expand Up @@ -78,6 +80,8 @@
from .._path import ensure_directory
from jaraco.text import yield_lines

if TYPE_CHECKING:
from typing_extensions import Self

# Turn on PEP440Warnings
warnings.filterwarnings("default", category=pkg_resources.PEP440Warning)
Expand Down Expand Up @@ -2055,19 +2059,21 @@ def _sys_executable(cls):
return os.environ.get('__PYVENV_LAUNCHER__', _default)

@classmethod
def from_param(cls, param):
def from_param(cls, param: Self | str | Iterable[str] | None) -> Self:
"""
Construct a CommandSpec from a parameter to build_scripts, which may
be None.
"""
if isinstance(param, cls):
return param
if isinstance(param, list):
if isinstance(param, str):
return cls.from_string(param)
if isinstance(param, Iterable):
return cls(param)
if param is None:
return cls.from_environment()
# otherwise, assume it's a string.
return cls.from_string(param)
# AttributeError to keep backwards compatibility, this should really be a TypeError though
raise AttributeError(f"Argument has an unsupported type {type(param)}")

@classmethod
def from_environment(cls):
Expand Down
5 changes: 3 additions & 2 deletions setuptools/command/editable_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,9 @@ def _create_file(self, relative_output: str, src_file: str, link=None):
def _create_links(self, outputs, output_mapping):
self.auxiliary_dir.mkdir(parents=True, exist_ok=True)
link_type = "sym" if _can_symlink_files(self.auxiliary_dir) else "hard"
mappings = {self._normalize_output(k): v for k, v in output_mapping.items()}
mappings.pop(None, None) # remove files that are not relative to build_lib
normalised = ((self._normalize_output(k), v) for k, v in output_mapping.items())
# remove files that are not relative to build_lib
mappings = {k: v for k, v in normalised if k is not None}

for output in outputs:
relative = self._normalize_output(output)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def assert_string_list(dist, attr, value):
try:
# verify that value is a list or tuple to exclude unordered
# or single-use iterables
assert isinstance(value, (list, tuple))
assert isinstance(value, sequence)
# verify that elements of value are strings
assert ''.join(value) != value
except (TypeError, ValueError, AttributeError, AssertionError) as e:
Expand Down
5 changes: 3 additions & 2 deletions setuptools/extension.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import re
import functools
import distutils.core
Expand Down Expand Up @@ -126,10 +127,10 @@ class Extension(_Extension):
specified on Windows. (since v63)
"""

def __init__(self, name, sources, *args, **kw):
def __init__(self, name: str, sources, *args, py_limited_api: bool = False, **kw):
# The *args is needed for compatibility as calls may use positional
# arguments. py_limited_api may be set only via keyword.
self.py_limited_api = kw.pop("py_limited_api", False)
self.py_limited_api = py_limited_api
super().__init__(name, sources, *args, **kw)

def _convert_pyx_sources_to_lang(self):
Expand Down
Loading