Skip to content
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/4548.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed the type of error raised by ``setuptools.command.easy_install.CommandSpec.from_param`` on unsupported argument from `AttributeError` to `TypeError` -- by :user:`Avasam`
3 changes: 1 addition & 2 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2068,8 +2068,7 @@ def from_param(cls, param: Self | str | Iterable[str] | None) -> Self:
return cls(param)
if param is None:
return cls.from_environment()
# AttributeError to keep backwards compatibility, this should really be a TypeError though
raise AttributeError(f"Argument has an unsupported type {type(param)}")
raise TypeError(f"Argument has an unsupported type {type(param)}")

@classmethod
def from_environment(cls):
Expand Down
10 changes: 10 additions & 0 deletions setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,16 @@ def test_from_simple_string_uses_shlex(self):
assert len(cmd) == 2
assert '"' not in cmd.as_header()

def test_from_param_raises_expected_error(self) -> None:
"""
from_param should raise its own TypeError when the argument's type is unsupported
"""
with pytest.raises(TypeError) as exc_info:
ei.CommandSpec.from_param(object()) # type: ignore[arg-type] # We want a type error here
assert (
str(exc_info.value) == "Argument has an unsupported type <class 'object'>"
), exc_info.value


class TestWindowsScriptWriter:
def test_header(self):
Expand Down