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

earwig / mwparserfromhell / 15962349696

30 Jun 2025 02:19AM UTC coverage: 98.662% (-0.2%) from 98.886%
15962349696

push

github

earwig
Fix coverage action and add pre-commit hook action

3097 of 3139 relevant lines covered (98.66%)

9.86 hits per line

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

93.02
/src/mwparserfromhell/string_mixin.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
"""
22
This module contains the :class:`.StringMixIn` type, which implements the
23
interface for the ``str`` type in a dynamic manner.
24
"""
25

26
from __future__ import annotations
10✔
27

28
from sys import getdefaultencoding
10✔
29

30
__all__ = ["StringMixIn"]
10✔
31

32

33
def inheritdoc(method):
10✔
34
    """Set __doc__ of *method* to __doc__ of *method* in its parent class.
35

36
    Since this is used on :class:`.StringMixIn`, the "parent class" used is
37
    ``str``. This function can be used as a decorator.
38
    """
39
    method.__doc__ = getattr(str, method.__name__).__doc__
×
40
    return method
×
41

42

43
class StringMixIn:
10✔
44
    """Implement the interface for ``str`` in a dynamic manner.
45

46
    To use this class, inherit from it and override the :meth:`__str__` method
47
    to return the string representation of the object. The various string
48
    methods will operate on the value of :meth:`__str__` instead of the
49
    immutable ``self`` like the regular ``str`` type.
50
    """
51

52
    def __str__(self):
10✔
53
        raise NotImplementedError()
×
54

55
    def __bytes__(self):
10✔
56
        return bytes(self.__str__(), getdefaultencoding())
10✔
57

58
    def __repr__(self):
10✔
59
        return repr(self.__str__())
10✔
60

61
    def __lt__(self, other):
10✔
62
        return self.__str__() < other
10✔
63

64
    def __le__(self, other):
10✔
65
        return self.__str__() <= other
10✔
66

67
    def __eq__(self, other):
10✔
68
        return self.__str__() == other
10✔
69

70
    def __ne__(self, other):
10✔
71
        return self.__str__() != other
10✔
72

73
    def __gt__(self, other):
10✔
74
        return self.__str__() > other
10✔
75

76
    def __ge__(self, other):
10✔
77
        return self.__str__() >= other
10✔
78

79
    def __bool__(self):
10✔
80
        return bool(self.__str__())
10✔
81

82
    def __len__(self):
10✔
83
        return len(self.__str__())
10✔
84

85
    def __iter__(self):
10✔
86
        yield from self.__str__()
10✔
87

88
    def __getitem__(self, key):
10✔
89
        return self.__str__()[key]
10✔
90

91
    def __reversed__(self):
10✔
92
        return reversed(self.__str__())
10✔
93

94
    def __contains__(self, item):
10✔
95
        return str(item) in self.__str__()
10✔
96

97
    def __getattr__(self, attr):
10✔
98
        if not hasattr(str, attr):
10✔
99
            raise AttributeError(
10✔
100
                f"{type(self).__name__!r} object has no attribute {attr!r}"
101
            )
102
        return getattr(self.__str__(), attr)
10✔
103

104
    maketrans = str.maketrans  # Static method can't rely on __getattr__
10✔
105

106

107
del inheritdoc
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

© 2025 Coveralls, Inc