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

earwig / mwparserfromhell / 15949141982

28 Jun 2025 11:18PM UTC coverage: 98.886% (-0.3%) from 99.204%
15949141982

push

github

earwig
Fix a failing test

3106 of 3141 relevant lines covered (98.89%)

9.85 hits per line

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

97.92
/src/mwparserfromhell/nodes/argument.py
1
# Copyright (C) 2012-2025 Ben Kurtovic <ben.kurtovic@gmail.com>
2
#
3
# Permission is hereby granted, free of charge, to any person obtaining a copy
4
# of this software and associated documentation files (the "Software"), to deal
5
# in the Software without restriction, including without limitation the rights
6
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
# copies of the Software, and to permit persons to whom the Software is
8
# furnished to do so, subject to the following conditions:
9
#
10
# The above copyright notice and this permission notice shall be included in
11
# all copies or substantial portions of the Software.
12
#
13
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
# SOFTWARE.
20

21
from __future__ import annotations
10✔
22

23
from collections.abc import Generator
10✔
24
from typing import TYPE_CHECKING, Any, Callable
10✔
25

26
from ..utils import parse_anything
10✔
27
from ._base import Node
10✔
28

29
if TYPE_CHECKING:
10✔
30
    from ..wikicode import Wikicode
×
31

32
__all__ = ["Argument"]
10✔
33

34

35
class Argument(Node):
10✔
36
    """Represents a template argument substitution, like ``{{{foo}}}``."""
37

38
    def __init__(self, name: Any, default: Any = None):
10✔
39
        super().__init__()
10✔
40
        self.name = name
10✔
41
        self.default = default
10✔
42

43
    def __str__(self) -> str:
10✔
44
        start = "{{{" + str(self.name)
10✔
45
        if self.default is not None:
10✔
46
            return start + "|" + str(self.default) + "}}}"
10✔
47
        return start + "}}}"
10✔
48

49
    def __children__(self) -> Generator[Wikicode, None, None]:
10✔
50
        yield self.name
10✔
51
        if self.default is not None:
10✔
52
            yield self.default
10✔
53

54
    def __strip__(self, **kwargs: Any) -> str | None:
10✔
55
        if self.default is not None:
10✔
56
            return self.default.strip_code(**kwargs)
10✔
57
        return None
10✔
58

59
    def __showtree__(
10✔
60
        self,
61
        write: Callable[[str], None],
62
        get: Callable[[Wikicode], None],
63
        mark: Callable[[], None],
64
    ) -> None:
65
        write("{{{")
10✔
66
        get(self.name)
10✔
67
        if self.default is not None:
10✔
68
            write("    | ")
10✔
69
            mark()
10✔
70
            get(self.default)
10✔
71
        write("}}}")
10✔
72

73
    @property
10✔
74
    def name(self) -> Wikicode:
10✔
75
        """The name of the argument to substitute."""
76
        return self._name
10✔
77

78
    @name.setter
10✔
79
    def name(self, value: Any) -> None:
10✔
80
        self._name = parse_anything(value)
10✔
81

82
    @property
10✔
83
    def default(self) -> Wikicode | None:
10✔
84
        """The default value to substitute if none is passed.
85

86
        This will be ``None`` if the argument wasn't defined with one. The
87
        MediaWiki parser handles this by rendering the argument itself in the
88
        result, complete braces. To have the argument render as nothing, set
89
        default to ``""`` (``{{{arg}}}`` vs. ``{{{arg|}}}``).
90
        """
91
        return self._default
10✔
92

93
    @default.setter
10✔
94
    def default(self, default: Any) -> None:
10✔
95
        if default is None:
10✔
96
            self._default = None
10✔
97
        else:
98
            self._default = parse_anything(default)
10✔
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