Skip to content

Commit

Permalink
Changed the type of error raised by ``setuptools.command.easy_install…
Browse files Browse the repository at this point in the history
….CommandSpec.from_param``on unsupported argument from`AttributeError`to`TypeError`
  • Loading branch information
Avasam committed Aug 9, 2024
1 parent f9398b1 commit 9674f40
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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 @@ -2072,8 +2072,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
8 changes: 8 additions & 0 deletions setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,14 @@ 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 error:
ei.CommandSpec.from_param(object()) # type: ignore[arg-type] # We want a type error here
assert str(error) == "Argument has an unsupported type <class 'object'>", error


class TestWindowsScriptWriter:
def test_header(self):
Expand Down

0 comments on commit 9674f40

Please sign in to comment.