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

basilisp-lang / basilisp / 12239089198

09 Dec 2024 03:42PM UTC coverage: 98.737%. Remained the same
12239089198

Pull #1169

github

web-flow
Merge 797e50f69 into ab7b96dd0
Pull Request #1169: Prepare for release v0.3.4

1030 of 1037 branches covered (99.32%)

Branch coverage included in aggregate %.

8824 of 8943 relevant lines covered (98.67%)

0.99 hits per line

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

87.27
/src/basilisp/lang/tagged.py
1
from typing import Optional, TypeVar, Union
1✔
2

3
from typing_extensions import Unpack
1✔
4

5
from basilisp.lang.interfaces import ILispObject, ILookup
1✔
6
from basilisp.lang.keyword import keyword
1✔
7
from basilisp.lang.obj import PrintSettings, lrepr
1✔
8
from basilisp.lang.symbol import Symbol
1✔
9

10
K = TypeVar("K")
1✔
11
V = TypeVar("V")
1✔
12
T = Union[None, V, Symbol]
1✔
13

14
_TAG_KW = keyword("tag")
1✔
15
_FORM_KW = keyword("form")
1✔
16

17

18
class TaggedLiteral(ILispObject, ILookup[K, T]):
1✔
19
    """Basilisp TaggedLiteral. https://clojure.org/reference/reader#tagged_literals"""
20

21
    __slots__ = ("_tag", "_form", "_hash")
1✔
22

23
    def __init__(self, tag: Symbol, form) -> None:
1✔
24
        self._tag = tag
1✔
25
        self._form = form
1✔
26
        self._hash: Optional[int] = None
1✔
27

28
    @property
1✔
29
    def tag(self) -> Symbol:
1✔
30
        return self._tag
1✔
31

32
    @property
1✔
33
    def form(self):
1✔
34
        return self._form
1✔
35

36
    def __bool__(self):
1✔
37
        return True
×
38

39
    def __eq__(self, other):
1✔
40
        if self is other:
1✔
41
            return True
1✔
42
        if not isinstance(other, TaggedLiteral):
1✔
43
            return NotImplemented
×
44
        return self._tag == other._tag and self._form == other._form
1✔
45

46
    def __hash__(self):
1✔
47
        if self._hash is None:
×
48
            self._hash = hash((self._tag, self._form))
×
49
        return self._hash
×
50

51
    def __getitem__(self, item):
1✔
52
        return self.val_at(item)
×
53

54
    def val_at(self, k: K, default: Optional[V] = None) -> T:
1✔
55
        if k == _TAG_KW:
1✔
56
            return self._tag
1✔
57
        elif k == _FORM_KW:
1✔
58
            return self._form
1✔
59
        else:
60
            return default
1✔
61

62
    def _lrepr(self, **kwargs: Unpack[PrintSettings]) -> str:
1✔
63
        return f"#{self._tag} {lrepr(self._form, **kwargs)}"
1✔
64

65

66
def tagged_literal(tag: Symbol, form):
1✔
67
    """Construct a data representation of a tagged literal from a
68
    tag symbol and a form."""
69
    if not isinstance(tag, Symbol):
1✔
70
        raise TypeError(f"tag must be a Symbol, not '{type(tag)}'")
1✔
71
    return TaggedLiteral(tag, form)
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