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

pantsbuild / pants / 24044100840

06 Apr 2026 06:11PM UTC coverage: 45.109% (-47.8%) from 92.908%
24044100840

Pull #23205

github

web-flow
Merge 4b5d6fed1 into 542ca048d
Pull Request #23205: Bump the gha-deps group across 1 directory with 5 updates

10790 of 23920 relevant lines covered (45.11%)

2.65 hits per line

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

64.0
/src/python/pants/util/frozendict.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 Callable, ItemsView, Iterable, Mapping, ValuesView
2✔
7
from typing import TypeVar, cast, overload
2✔
8

9
from pants.engine.internals.native_engine import FrozenDict as FrozenDict
2✔
10
from pants.util.memo import memoized_method
2✔
11

12
K = TypeVar("K")
2✔
13
V = TypeVar("V")
2✔
14
T = TypeVar("T")
2✔
15

16

17
class LazyFrozenDict(FrozenDict[K, V]):
2✔
18
    """A lazy version of `FrozenDict` where the values are not loaded until referenced."""
19

20
    @overload
21
    def __new__(
22
        cls, __items: Iterable[tuple[K, Callable[[], V]]], **kwargs: Callable[[], V]
23
    ) -> LazyFrozenDict[K, V]: ...
24

25
    @overload
26
    def __new__(
27
        cls, __other: Mapping[K, Callable[[], V]], **kwargs: Callable[[], V]
28
    ) -> LazyFrozenDict[K, V]: ...
29

30
    @overload
31
    def __new__(cls, **kwargs: Callable[[], V]) -> LazyFrozenDict[K, V]: ...
32

33
    def __new__(
2✔
34
        cls,
35
        *item: Mapping[K, Callable[[], V]] | Iterable[tuple[K, Callable[[], V]]],
36
        **kwargs: Callable[[], V],
37
    ) -> LazyFrozenDict[K, V]:
38
        return super().__new__(cls, *item, **kwargs)  # type: ignore[arg-type]
×
39

40
    def __getitem__(self, k: K) -> V:
2✔
41
        return self._get_value(k)
×
42

43
    @overload
44
    def get(self, key: K, /) -> V | None: ...
45
    @overload
46
    def get(self, key: K, /, default: T = ...) -> V | T: ...
47

48
    def get(self, key: K, /, default: T | None = None) -> V | T | None:
2✔
49
        try:
×
50
            return self._get_value(key)
×
51
        except KeyError:
×
52
            return default
×
53

54
    @memoized_method
2✔
55
    def _get_value(self, k: K) -> V:
2✔
56
        return cast("Callable[[], V]", super().__getitem__(k))()
×
57

58
    def items(self) -> ItemsView[K, V]:
2✔
59
        return ItemsView(self)
×
60

61
    def values(self) -> ValuesView[V]:
2✔
62
        return ValuesView(self)
×
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