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

pantsbuild / pants / 21552830208

31 Jan 2026 11:40PM UTC coverage: 80.277% (-0.05%) from 80.324%
21552830208

Pull #23062

github

web-flow
Merge 808a9786c into 2c4dcf9cf
Pull Request #23062: Remove support for Get

18 of 25 new or added lines in 4 files covered. (72.0%)

17119 existing lines in 541 files now uncovered.

78278 of 97510 relevant lines covered (80.28%)

3.36 hits per line

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

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

4
import dataclasses
12✔
5

6
import pytest
12✔
7

8

9
@pytest.fixture(autouse=True, scope="session")
12✔
10
def dedicated_target_fields():
12✔
11
    """Ensures we follow our convention of dedicated source and dependencies field per-target.
12

13
    This helps ensure that plugin authors can do dependency inference on _specific_ field types, and
14
    not have to filter targets using generic field types.
15

16
    Note that this can't help us if a target type should use an _even more specialized_ dependencies
17
    field type (E.g. 100 different target subclasses could use 1 custom dependencies field type,
18
    when in reality there should be many more). However, this is a good sanity check.
19
    """
20
    from pants.engine.target import Dependencies, SourcesField, Target
12✔
21

22
    for cls in Target.__subclasses__():
12✔
23
        if hasattr(cls, "core_fields"):
12✔
24
            for field_cls in cls.core_fields:
12✔
25
                # NB: We want to check for all kinds of SourcesFields, like SingleSourceField and
26
                # MultipleSourcesField.
27
                if (
12✔
28
                    issubclass(field_cls, SourcesField)
29
                    and field_cls.__module__ is SourcesField.__module__
30
                ):
31
                    raise ValueError(
×
32
                        f"{cls.__name__} should have a dedicated field type for the source(s) field."
33
                    )
34
                if (
12✔
35
                    issubclass(field_cls, Dependencies)
36
                    and field_cls.__module__ is Dependencies.__module__
37
                ):
38
                    raise ValueError(
×
39
                        f"{cls.__name__} should have a dedicated field type for the dependencies field."
40
                    )
41

42

43
def _check_frozen_dataclass_attributes() -> None:
12✔
44
    """Ensures that calls to `object.__setattr__` in a frozen dataclass' `__init__` are valid."""
45

46
    actual_dataclass_decorator = dataclasses.dataclass
12✔
47

48
    def new_dataclass_decorator(*args, **kwargs):
12✔
49
        if not kwargs.get("frozen", False):
12✔
50
            return actual_dataclass_decorator(*args, **kwargs)
12✔
51

52
        def wrapper(cls):
12✔
53
            dataclass_cls = actual_dataclass_decorator(*args, **kwargs)(cls)
12✔
54

55
            if dataclass_cls.__init__ is cls.__init__:
12✔
56
                old__init__ = getattr(dataclass_cls, "__init__")
12✔
57

58
                def new__init__(self, *args, **kwargs):
12✔
59
                    old__init__(self, *args, **kwargs)
12✔
60
                    expected = sorted(field.name for field in dataclasses.fields(self))
12✔
61
                    if hasattr(self, "__dict__"):
12✔
62
                        actual = sorted(self.__dict__)
12✔
63
                        assert expected == actual
12✔
64
                    else:
UNCOV
65
                        for attrname in self.__slots__:
3✔
66
                            # The only way to validate it was initialized is to trigger the descriptor.
UNCOV
67
                            getattr(self, attrname)
3✔
68

69
                setattr(dataclass_cls, "__init__", new__init__)
12✔
70

71
            return dataclass_cls
12✔
72

73
        return wrapper
12✔
74

75
    dataclasses.dataclass = new_dataclass_decorator
12✔
76

77

78
def pytest_configure() -> None:
12✔
79
    _check_frozen_dataclass_attributes()
12✔
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

© 2026 Coveralls, Inc