Skip to content

Commit 79d5665

Browse files
committed
Changed the type of error raised by setuptools.command.easy_install.CommandSpec.from_paramon unsupported argument fromAttributeErrortoTypeError
1 parent f9398b1 commit 79d5665

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

newsfragments/4548.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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`

setuptools/command/easy_install.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2072,8 +2072,7 @@ def from_param(cls, param: Self | str | Iterable[str] | None) -> Self:
20722072
return cls(param)
20732073
if param is None:
20742074
return cls.from_environment()
2075-
# AttributeError to keep backwards compatibility, this should really be a TypeError though
2076-
raise AttributeError(f"Argument has an unsupported type {type(param)}")
2075+
raise TypeError(f"Argument has an unsupported type {type(param)}")
20772076

20782077
@classmethod
20792078
def from_environment(cls):

setuptools/tests/test_easy_install.py

+16
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,22 @@ def test_from_simple_string_uses_shlex(self):
13321332
assert len(cmd) == 2
13331333
assert '"' not in cmd.as_header()
13341334

1335+
def test_from_param_raises_expected_error(self) -> None:
1336+
"""
1337+
from_param should raise its own TypeError when the argument's type is unsupported
1338+
"""
1339+
try:
1340+
ei.CommandSpec.from_param(object()) # type: ignore[arg-type] # We want a type error here
1341+
except Exception as error:
1342+
assert type(error) is TypeError, error
1343+
assert (
1344+
str(error) == "Argument has an unsupported type <class 'object'>"
1345+
), error
1346+
else:
1347+
raise AssertionError(
1348+
"from_param did not raise any error for argument of unsupported type"
1349+
)
1350+
13351351

13361352
class TestWindowsScriptWriter:
13371353
def test_header(self):

0 commit comments

Comments
 (0)