Skip to content

Commit 000a413

Browse files
abravalheriAvasam
authored andcommitted
Deprecate public access to setuptools.dist.sequence
1 parent 00995c1 commit 000a413

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

setuptools/dist.py

+30-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@
88
import sys
99
from glob import iglob
1010
from pathlib import Path
11-
from typing import TYPE_CHECKING, List, MutableMapping, NoReturn, Tuple, Union, overload
11+
from typing import (
12+
TYPE_CHECKING,
13+
Any,
14+
List,
15+
MutableMapping,
16+
NoReturn,
17+
Tuple,
18+
Union,
19+
overload,
20+
)
1221

1322
from more_itertools import partition, unique_everseen
1423
from packaging.markers import InvalidMarker, Marker
@@ -42,8 +51,10 @@
4251

4352
__all__ = ['Distribution']
4453

45-
sequence = tuple, list
54+
_sequence = tuple, list
4655
"""
56+
:meta private:
57+
4758
Supported iterable types that are known to be:
4859
- ordered (which `set` isn't)
4960
- not match a str (which `Sequence[str]` does)
@@ -55,6 +66,17 @@
5566
_requence_type_repr = "tuple[str, ...] | list[str]"
5667

5768

69+
def __getattr__(name: str) -> Any: # pragma: no cover
70+
if name == "sequence":
71+
SetuptoolsDeprecationWarning.emit(
72+
"`setuptools.dist.sequence` is an internal implementation detail.",
73+
"Please define your own `sequence = tuple, list` instead.",
74+
due_date=(2025, 8, 28), # Originally added on 2024-08-27
75+
)
76+
return _sequence
77+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
78+
79+
5880
def check_importable(dist, attr, value):
5981
try:
6082
ep = metadata.EntryPoint(value=value, name=None, group=None)
@@ -70,7 +92,7 @@ def assert_string_list(dist, attr: str, value: _Sequence) -> None:
7092
try:
7193
# verify that value is a list or tuple to exclude unordered
7294
# or single-use iterables
73-
assert isinstance(value, sequence)
95+
assert isinstance(value, _sequence)
7496
# verify that elements of value are strings
7597
assert ''.join(value) != value
7698
except (TypeError, ValueError, AttributeError, AssertionError) as e:
@@ -786,15 +808,15 @@ def has_contents_for(self, package):
786808

787809
def _exclude_misc(self, name: str, value: _Sequence) -> None:
788810
"""Handle 'exclude()' for list/tuple attrs without a special handler"""
789-
if not isinstance(value, sequence):
811+
if not isinstance(value, _sequence):
790812
raise DistutilsSetupError(
791813
f"{name}: setting must be of type <{_requence_type_repr}> (got {value!r})"
792814
)
793815
try:
794816
old = getattr(self, name)
795817
except AttributeError as e:
796818
raise DistutilsSetupError("%s: No such distribution setting" % name) from e
797-
if old is not None and not isinstance(old, sequence):
819+
if old is not None and not isinstance(old, _sequence):
798820
raise DistutilsSetupError(
799821
name + ": this setting cannot be changed via include/exclude"
800822
)
@@ -804,7 +826,7 @@ def _exclude_misc(self, name: str, value: _Sequence) -> None:
804826
def _include_misc(self, name: str, value: _Sequence) -> None:
805827
"""Handle 'include()' for list/tuple attrs without a special handler"""
806828

807-
if not isinstance(value, sequence):
829+
if not isinstance(value, _sequence):
808830
raise DistutilsSetupError(
809831
f"{name}: setting must be of type <{_requence_type_repr}> (got {value!r})"
810832
)
@@ -814,7 +836,7 @@ def _include_misc(self, name: str, value: _Sequence) -> None:
814836
raise DistutilsSetupError("%s: No such distribution setting" % name) from e
815837
if old is None:
816838
setattr(self, name, value)
817-
elif not isinstance(old, sequence):
839+
elif not isinstance(old, _sequence):
818840
raise DistutilsSetupError(
819841
name + ": this setting cannot be changed via include/exclude"
820842
)
@@ -846,7 +868,7 @@ def exclude(self, **attrs):
846868
self._exclude_misc(k, v)
847869

848870
def _exclude_packages(self, packages: _Sequence) -> None:
849-
if not isinstance(packages, sequence):
871+
if not isinstance(packages, _sequence):
850872
raise DistutilsSetupError(
851873
f"packages: setting must be of type <{_requence_type_repr}> (got {packages!r})"
852874
)

0 commit comments

Comments
 (0)