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

makinacorpus / django-leaflet / 7450289140

08 Jan 2024 04:26PM UTC coverage: 83.401% (+0.1%) from 83.299%
7450289140

push

github

web-flow
add django-geojson template filter to the documentation (#369)

412 of 494 relevant lines covered (83.4%)

13.33 hits per line

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

0.0
/leaflet/utils.py
1
from collections.abc import Sequence
×
2

3
from django.utils.functional import Promise
×
4

5

6
class memoized_lazy_function(Promise):
×
7
    """
8
    Represents a lazy value which is calculated by calling
9
    func(*args, **kwargs) and then is memoized.
10

11
    >>> f = memoized_lazy_function(lambda a: print('.') or a, 'hello')
12
    >>> f()
13
    .
14
    'hello'
15
    >>> f()
16
    'hello'
17
    """
18

19
    def __init__(self, func, *args, **kwargs):
×
20
        self._func = func
×
21
        self._args = args
×
22
        self._kwargs = kwargs
×
23

24
    def __call__(self):
×
25
        if not hasattr(self, '_result'):
×
26
            self._result = self._func(*self._args, **self._kwargs)
×
27
        return self._result
×
28

29

30
class ListWithLazyItems(Sequence):
×
31
    """
32
    Mimics a lazy list.
33

34
    It keeps items in lazy state and evaluates them when they're
35
    returned.
36

37
    An item is considered lazy when it is
38
    a `django.utils.functional.Promise` instance.
39
    """
40

41
    def __init__(self, iterable=()):
×
42
        if isinstance(iterable, ListWithLazyItems):
×
43
            iterable = iterable._list
×
44
        self._list = list(iterable)
×
45

46
    def __iter__(self):
×
47
        for item in self._list:
×
48
            yield self._resolve_lazy_item(item)
×
49

50
    def __len__(self):
×
51
        return len(self._list)
×
52

53
    def __getitem__(self, index):
×
54
        return self._resolve_lazy_item(self._list[index])
×
55

56
    def extend(self, iterable):
×
57
        if isinstance(iterable, ListWithLazyItems):
×
58
            iterable = iterable._list
×
59
        self._list.extend(iterable)
×
60

61
    def __radd__(self, iterable):
×
62
        lazy_list = type(self)(iterable)  # copy
×
63
        lazy_list.extend(self)
×
64
        return lazy_list
×
65

66
    def __add__(self, iterable):
×
67
        lazy_list = type(self)(self)  # copy
×
68
        lazy_list.extend(iterable)
×
69
        return lazy_list
×
70

71
    @classmethod
×
72
    def _resolve_lazy_item(cls, item):
73
        if cls.is_lazy_item(item):
×
74
            item = item()
×
75

76
        return item
×
77

78
    @classmethod
×
79
    def is_lazy_item(cls, item):
80
        return isinstance(item, Promise)
×
81

82

83
class ListWithLazyItemsRawIterator(ListWithLazyItems):
×
84
    """
85
    This lazy list yields raw items (i.e. Promises are not resolved)
86
    when iterated.
87
    """
88

89
    def __iter__(self):
×
90
        return iter(self._list)
×
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