Skip to content

Commit

Permalink
Update tests expected error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Aug 18, 2024
1 parent 5c5b846 commit 108b843
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

__all__ = ['Distribution']

sequence = tuple, list
sequence = Tuple[str, ...], List[str]
"""
Supported iterable types that are known to be:
- ordered (which `set` isn't)
Expand All @@ -53,6 +53,10 @@
for use with `isinstance`.
"""
_Sequence: TypeAlias = Union[Tuple[str, ...], List[str]]
# This is how stringifying _Sequence would look in Python 3.10
_requence_type_repr = " | ".join(
str(type).lower().replace("typing.", "") for type in sequence
)


def check_importable(dist, attr, value):
Expand All @@ -75,7 +79,7 @@ def assert_string_list(dist, attr: str, value: _Sequence):
assert ''.join(value) != value
except (TypeError, ValueError, AttributeError, AssertionError) as e:
raise DistutilsSetupError(
f"{attr!r} must be of type {_Sequence} (got {value!r})"
f"{attr!r} must be of type <{_requence_type_repr}> (got {value!r})"
) from e


Expand Down Expand Up @@ -787,7 +791,7 @@ def _exclude_misc(self, name: str, value: _Sequence):
"""Handle 'exclude()' for list/tuple attrs without a special handler"""
if not isinstance(value, sequence):
raise DistutilsSetupError(
f"{name}: setting must be of type {_Sequence} (got {value!r})"
f"{name}: setting must be of type <{_requence_type_repr}> (got {value!r})"
)
try:
old = getattr(self, name)
Expand All @@ -805,7 +809,7 @@ def _include_misc(self, name: str, value: _Sequence):

if not isinstance(value, sequence):
raise DistutilsSetupError(
f"{name}: setting must be of type {_Sequence} (got {value!r})"
f"{name}: setting must be of type <{_requence_type_repr}> (got {value!r})"
)
try:
old = getattr(self, name)
Expand Down Expand Up @@ -847,7 +851,7 @@ def exclude(self, **attrs):
def _exclude_packages(self, packages: _Sequence):
if not isinstance(packages, sequence):
raise DistutilsSetupError(
f"packages: setting must be of type {_Sequence} (got {packages!r})"
f"packages: setting must be of type <{_requence_type_repr}> (got {packages!r})"
)
list(map(self.exclude_package, packages))

Expand Down
8 changes: 4 additions & 4 deletions setuptools/tests/test_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def test_provides_extras_deterministic_order():
'hello': '*.msg',
},
(
"\"values of 'package_data' dict\" "
"must be a list of strings (got '*.msg')"
"\"values of 'package_data' dict\" must be of type <tuple[str, ...] | list>"
" (got '*.msg')"
),
),
# Invalid value type (generators are single use)
Expand All @@ -127,8 +127,8 @@ def test_provides_extras_deterministic_order():
'hello': (x for x in "generator"),
},
(
"\"values of 'package_data' dict\" must be a list of strings "
"(got <generator object"
"\"values of 'package_data' dict\" must be of type <tuple[str, ...] | list>"
" (got <generator object"
),
),
)
Expand Down

0 comments on commit 108b843

Please sign in to comment.