• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 19381742489

15 Nov 2025 12:52AM UTC coverage: 49.706% (-30.6%) from 80.29%
19381742489

Pull #22890

github

web-flow
Merge d961abf79 into 42e1ebd41
Pull Request #22890: Updated all python subsystem constraints to 3.14

4 of 5 new or added lines in 5 files covered. (80.0%)

14659 existing lines in 485 files now uncovered.

31583 of 63540 relevant lines covered (49.71%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.19
/src/python/pants/engine/collection.py
1
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
2✔
5

6
from collections.abc import Iterable
2✔
7
from typing import Any, ClassVar, TypeVar, cast, overload
2✔
8

9
from pants.util.ordered_set import FrozenOrderedSet
2✔
10

11
T = TypeVar("T")
2✔
12

13

14
class Collection(tuple[T, ...]):
2✔
15
    """A light newtype around immutable sequences for use with the V2 engine.
16

17
    This should be subclassed when you want to create a distinct collection type, such as:
18

19
        @dataclass(frozen=True)
20
        class Example:
21
            val1: str
22

23
        class Examples(Collection[Example]):
24
            pass
25

26
    N.B: Collection instances are only considered equal if both their types and contents are equal.
27
    """
28

29
    @overload  # type: ignore[override]  # noqa: F811
30
    def __getitem__(self, index: int) -> T: ...
31

32
    @overload  # noqa: F811
33
    def __getitem__(self, index: slice) -> Collection[T]: ...
34

35
    def __getitem__(self, index: int | slice) -> T | Collection[T]:  # noqa: F811
2✔
36
        result = super().__getitem__(index)
2✔
37
        if isinstance(index, int):
2✔
38
            return cast(T, result)
2✔
UNCOV
39
        return self.__class__(cast(tuple[T, ...], result))
×
40

41
    def __eq__(self, other: Any) -> bool:
2✔
42
        if self is other:
2✔
43
            return True
×
44
        return type(self) is type(other) and super().__eq__(other)
2✔
45

46
    def __ne__(self, other: Any) -> bool:
2✔
47
        # We must explicitly override to provide the inverse of _our_ __eq__ and not get the
48
        # inverse of tuple.__eq__.
UNCOV
49
        return not self == other
×
50

51
    # Unlike in Python 2 we must explicitly implement __hash__ since we explicitly implement __eq__
52
    # per the Python 3 data model.
53
    # See: https://docs.python.org/3/reference/datamodel.html#object.__hash__
54
    def __hash__(self):
2✔
55
        return super().__hash__()
2✔
56

57
    def __repr__(self) -> str:
2✔
UNCOV
58
        return f"{self.__class__.__name__}({list(self)})"
×
59

60

61
# NB: This name is clunky. It would be more appropriate to call it `Set`, but that is claimed by
62
#  `typing.Set` already. See
63
#  https://github.com/pantsbuild/pants/pull/9590#pullrequestreview-395970440.
64
class DeduplicatedCollection(FrozenOrderedSet[T]):
2✔
65
    """A light newtype around FrozenOrderedSet for use with the V2 engine.
66

67
    This should be subclassed when you want to create a distinct collection type, such as:
68

69
        @dataclass(frozen=True)
70
        class Example:
71
            val1: str
72

73
        class Examples(DeduplicatedCollection[Example]):
74
            pass
75

76
    If it is safe to sort the inputs, you should do so for more cache hits by setting the class
77
    property `sort_input = True`.
78
    """
79

80
    sort_input: ClassVar[bool] = False
2✔
81

82
    def __init__(self, iterable: Iterable[T] = ()) -> None:
2✔
83
        super().__init__(
2✔
84
            iterable if not self.sort_input else sorted(iterable)  # type: ignore[type-var]
85
        )
86

87
    def __repr__(self) -> str:
2✔
88
        return f"{self.__class__.__name__}({list(self._items)})"
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc