• 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.62
/src/mwparserfromhell/nodes/extras/parameter.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
import re
10✔
24
from typing import TYPE_CHECKING, Any
10✔
25

26
from ...string_mixin import StringMixIn
10✔
27
from ...utils import parse_anything
10✔
28

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

32
__all__ = ["Parameter"]
10✔
33

34

35
class Parameter(StringMixIn):
10✔
36
    """Represents a parameter of a template.
37

38
    For example, the template ``{{foo|bar|spam=eggs}}`` contains two
39
    Parameters: one whose name is ``"1"``, value is ``"bar"``, and ``showkey``
40
    is ``False``, and one whose name is ``"spam"``, value is ``"eggs"``, and
41
    ``showkey`` is ``True``.
42
    """
43

44
    def __init__(self, name: Any, value: Any, showkey: bool = True) -> None:
10✔
45
        super().__init__()
10✔
46
        self.name = name
10✔
47
        self.value = value
10✔
48
        self.showkey = showkey
10✔
49

50
    def __str__(self) -> str:
10✔
51
        if self.showkey:
10✔
52
            return str(self.name) + "=" + str(self.value)
10✔
53
        return str(self.value)
10✔
54

55
    @staticmethod
10✔
56
    def can_hide_key(key: Any) -> re.Match | None:
10✔
57
        """Return whether or not the given key can be hidden."""
58
        return re.match(r"[1-9][0-9]*$", str(key).strip())
10✔
59

60
    @property
10✔
61
    def name(self) -> Wikicode:
10✔
62
        """The name of the parameter as a :class:`.Wikicode` object."""
63
        return self._name
10✔
64

65
    @name.setter
10✔
66
    def name(self, newval: Any) -> None:
10✔
67
        self._name = parse_anything(newval)
10✔
68

69
    @property
10✔
70
    def value(self) -> Wikicode:
10✔
71
        """The value of the parameter as a :class:`.Wikicode` object."""
72
        return self._value
10✔
73

74
    @value.setter
10✔
75
    def value(self, newval: Any) -> None:
10✔
76
        self._value = parse_anything(newval)
10✔
77

78
    @property
10✔
79
    def showkey(self) -> bool:
10✔
80
        """Whether to show the parameter's key (i.e., its "name")."""
81
        return self._showkey
10✔
82

83
    @showkey.setter
10✔
84
    def showkey(self, newval: Any) -> None:
10✔
85
        newval = bool(newval)
10✔
86
        if not newval and not self.can_hide_key(self.name):
10✔
87
            raise ValueError(f"parameter key {self.name!r} cannot be hidden")
10✔
88
        self._showkey = newval
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