Skip to content

Commit

Permalink
Merge pull request #4548 from Avasam/from_param-TypeError
Browse files Browse the repository at this point in the history
Raise `TypeError` in `easy_install.CommandSpec.from_param`
  • Loading branch information
abravalheri authored Aug 27, 2024
2 parents 11a6b59 + fbc75bc commit 5f8215d
Show file tree
Hide file tree
Showing 3 changed files with 12 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 @@ -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):
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

0 comments on commit 5f8215d

Please sign in to comment.