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

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

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

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

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

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

4
from collections.abc import Mapping
1✔
5
from enum import Enum
1✔
6
from typing import TypeVar
1✔
7

8

9
class EnumMatchError(ValueError):
1✔
10
    """Issue when using match() on an enum."""
11

12

13
class InexhaustiveMatchError(EnumMatchError):
1✔
14
    """Not all values of the enum specified in the pattern match."""
15

16

17
class UnrecognizedMatchError(EnumMatchError):
1✔
18
    """A value is used that is not a part of the enum."""
19

20

21
_E = TypeVar("_E", bound=Enum)
1✔
22
_V = TypeVar("_V")
1✔
23

24

25
def match(enum_instance: _E, enum_values_to_results: Mapping[_E, _V]) -> _V:
1✔
26
    # TODO: consider memoizing the result of this entire method, as well as the value of
27
    # `all_instances` for a given enum class!
28
    all_instances: frozenset[_E] = frozenset(type(enum_instance))
1✔
29
    unrecognized_values = [value for value in enum_values_to_results if value not in all_instances]
1✔
30
    missing_values = [value for value in all_instances if value not in enum_values_to_results]
1✔
31
    if unrecognized_values:
1✔
UNCOV
32
        raise UnrecognizedMatchError(
×
33
            f"Match includes values not defined in the enum. Unrecognized: {unrecognized_values}"
34
        )
35
    if missing_values:
1✔
UNCOV
36
        raise InexhaustiveMatchError(
×
37
            f"All enum values must be covered by the match. Missing: {missing_values}"
38
        )
39
    return enum_values_to_results[enum_instance]
1✔
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