diff --git a/newsfragments/4548.feature.rst b/newsfragments/4548.feature.rst new file mode 100644 index 0000000000..7fcf5f4377 --- /dev/null +++ b/newsfragments/4548.feature.rst @@ -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` diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index bdf9fa242b..63bff97fc1 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -2073,8 +2073,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): diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index ca6af9667e..de257db80c 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -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 " + ), exc_info.value + class TestWindowsScriptWriter: def test_header(self):