Skip to content

Commit 9c71fd8

Browse files
Avasamabravalheri
andcommitted
Runtime changes for typeshed merge
Co-authored-by: Anderson Bravalheri <[email protected]>
1 parent 0c6f80f commit 9c71fd8

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

newsfragments/4505.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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`

setuptools/command/build_ext.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from typing import Iterator
99
from pathlib import Path
1010

11-
from distutils.command.build_ext import build_ext as _du_build_ext
1211
from distutils.ccompiler import new_compiler
1312
from distutils.sysconfig import customize_compiler, get_config_var
1413
from distutils import log
@@ -24,7 +23,7 @@
2423
# also. Ref #1229.
2524
__import__('Cython.Compiler.Main')
2625
except ImportError:
27-
_build_ext = _du_build_ext
26+
from distutils.command.build_ext import build_ext as _build_ext
2827

2928
# make sure _config_vars is initialized
3029
get_config_var("LDSHARED")

setuptools/command/easy_install.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from __future__ import annotations
1414

15+
from collections.abc import Iterable
1516
from glob import glob
1617
from distutils.util import get_platform
1718
from distutils.util import convert_path, subst_vars
@@ -26,6 +27,7 @@
2627
from distutils.command import install
2728
import sys
2829
import os
30+
from typing import TYPE_CHECKING
2931
import zipimport
3032
import shutil
3133
import tempfile
@@ -78,6 +80,8 @@
7880
from .._path import ensure_directory
7981
from jaraco.text import yield_lines
8082

83+
if TYPE_CHECKING:
84+
from typing_extensions import Self
8185

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

20572061
@classmethod
2058-
def from_param(cls, param):
2062+
def from_param(cls, param: Self | str | Iterable[str] | None) -> Self:
20592063
"""
20602064
Construct a CommandSpec from a parameter to build_scripts, which may
20612065
be None.
20622066
"""
20632067
if isinstance(param, cls):
20642068
return param
2065-
if isinstance(param, list):
2069+
if isinstance(param, str):
2070+
return cls.from_string(param)
2071+
if isinstance(param, Iterable):
20662072
return cls(param)
20672073
if param is None:
20682074
return cls.from_environment()
2069-
# otherwise, assume it's a string.
2070-
return cls.from_string(param)
2075+
# AttributeError to keep backwards compatibility, this should really be a TypeError though
2076+
raise AttributeError(f"Argument has an unsupported type {type(param)}")
20712077

20722078
@classmethod
20732079
def from_environment(cls):

setuptools/command/editable_wheel.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,14 @@ def _create_file(self, relative_output: str, src_file: str, link=None):
466466
def _create_links(self, outputs, output_mapping):
467467
self.auxiliary_dir.mkdir(parents=True, exist_ok=True)
468468
link_type = "sym" if _can_symlink_files(self.auxiliary_dir) else "hard"
469-
mappings = {self._normalize_output(k): v for k, v in output_mapping.items()}
470-
mappings.pop(None, None) # remove files that are not relative to build_lib
469+
mappings = {
470+
k: v
471+
for k, v in (
472+
(self._normalize_output(k), v) for k, v in output_mapping.items()
473+
)
474+
# remove files that are not relative to build_lib
475+
if k is not None
476+
}
471477

472478
for output in outputs:
473479
relative = self._normalize_output(output)

setuptools/dist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def assert_string_list(dist, attr, value):
5555
try:
5656
# verify that value is a list or tuple to exclude unordered
5757
# or single-use iterables
58-
assert isinstance(value, (list, tuple))
58+
assert isinstance(value, sequence)
5959
# verify that elements of value are strings
6060
assert ''.join(value) != value
6161
except (TypeError, ValueError, AttributeError, AssertionError) as e:

setuptools/extension.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
import re
23
import functools
34
import distutils.core
@@ -126,10 +127,12 @@ class Extension(_Extension):
126127
specified on Windows. (since v63)
127128
"""
128129

129-
def __init__(self, name, sources, *args, **kw):
130+
def __init__(
131+
self, name: str, sources, *args, py_limited_api: bool = False, **kw
132+
):
130133
# The *args is needed for compatibility as calls may use positional
131134
# arguments. py_limited_api may be set only via keyword.
132-
self.py_limited_api = kw.pop("py_limited_api", False)
135+
self.py_limited_api = py_limited_api
133136
super().__init__(name, sources, *args, **kw)
134137

135138
def _convert_pyx_sources_to_lang(self):

0 commit comments

Comments
 (0)