Passed
Push — main ( 6d4817...ffd182 )
by Douglas
01:37
created

pocketutils.core.decorators.pending_deprecation()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
"""
2
Code for decorateme.
3
"""
4
from __future__ import annotations
5
6
import enum
7
import html as _html
8
from abc import abstractmethod
9
from collections.abc import Callable, Collection
10
from functools import total_ordering, wraps
11
from typing import Literal, TypeVar, final
0 ignored issues
show
Bug introduced by
The name Literal does not seem to exist in module typing.
Loading history...
Bug introduced by
The name final does not seem to exist in module typing.
Loading history...
12
from warnings import warn
13
14
T = TypeVar("T", bound=type)
0 ignored issues
show
Coding Style Naming introduced by
Class name "T" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
15
16
17
def reserved(cls: T) -> T:
18
    """
19
    Empty but is declared for future use.
20
    """
21
    return cls
22
23
24
class CodeIncompleteError(NotImplementedError):
25
    """The code is not finished."""
26
27
28
class CodeRemovedError(NotImplementedError):
29
    """The code was removed."""
30
31
32
class PreviewWarning(UserWarning):
33
    """The code being called is a preview, unstable. or immature."""
34
35
36
@enum.unique
37
class CodeStatus(enum.Enum):
38
    """
39
    An enum for the quality/maturity of code,
40
    ranging from incomplete to deprecated.
41
    """
42
43
    INCOMPLETE = -2
44
    PREVIEW = -1
45
    STABLE = 0
46
    PENDING_DEPRECATION = 1
47
    DEPRECATED = 2
48
    REMOVED = 3
49
50
    @classmethod
51
    def of(cls, x: int | str | CodeStatus) -> CodeStatus:
0 ignored issues
show
Coding Style Naming introduced by
Method name "of" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style Naming introduced by
Argument name "x" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
52
        if isinstance(x, str):
53
            return cls[x.lower().strip()]
54
        if isinstance(x, CodeStatus):
55
            return x
56
        if isinstance(x, int):
57
            return cls(x)
58
        raise TypeError(f"Invalid type {type(x)} for {x}")
59
60
61
def status(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "vr" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
62
    level: int | str | CodeStatus,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
63
    vr: str | None = "",
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
64
    msg: str | None = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
65
):
66
    """
67
    Annotate code quality. Emits a warning if bad code is called.
68
69
    Args:
70
        level: The quality / maturity
71
        vr: First version the status / warning applies to
72
        msg: Explanation and/or when it will be removed or completed
73
    """
74
75
    level = CodeStatus.of(level)
76
77
    @wraps(status)
78
    def dec(func):
79
        func.__status__ = level
80
        if level is CodeStatus.STABLE:
0 ignored issues
show
unused-code introduced by
Unnecessary "elif" after "return"
Loading history...
81
            return func
82
        elif level is CodeStatus.REMOVED:
83
84
            def my_fn(*_, **__):
85
                raise CodeRemovedError(f"{func.__name__} was removed (as of version: {vr}). {msg}")
86
87
            return wraps(func)(my_fn)
88
89
        elif level is CodeStatus.INCOMPLETE:
90
91
            def my_fn(*_, **__):
92
                raise CodeIncompleteError(
93
                    f"{func.__name__} is incomplete (as of version: {vr}). {msg}"
94
                )
95
96
            return wraps(func)(my_fn)
97
        elif level is CodeStatus.PREVIEW:
98
99
            def my_fn(*args, **kwargs):
100
                warn(
101
                    f"{func.__name__} is a preview or immature (as of version: {vr}). {msg}",
102
                    PreviewWarning,
103
                )
104
                return func(*args, **kwargs)
105
106
            return wraps(func)(my_fn)
107
        elif level is CodeStatus.PENDING_DEPRECATION:
108
109
            def my_fn(*args, **kwargs):
110
                warn(
111
                    f"{func.__name__} is pending deprecation (as of version: {vr}). {msg}",
112
                    PendingDeprecationWarning,
113
                )
114
                return func(*args, **kwargs)
115
116
            return wraps(func)(my_fn)
117
        elif level is CodeStatus.DEPRECATED:
118
119
            def my_fn(*args, **kwargs):
120
                warn(
121
                    f"{func.__name__} is deprecated (as of version: {vr}). {msg}",
122
                    DeprecationWarning,
123
                )
124
                return func(*args, **kwargs)
125
126
            return wraps(func)(my_fn)
127
        raise AssertionError(f"What is {level}?")
128
129
    return dec
130
131
132
def incomplete(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "vr" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
133
    vr: str | None = "",
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
134
    msg: str | None = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
135
):
136
    return status(CodeStatus.INCOMPLETE, vr, msg)
137
138
139
def preview(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "vr" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
140
    vr: str | None = "",
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
141
    msg: str | None = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
142
):
143
    return status(CodeStatus.PREVIEW, vr, msg)
144
145
146
def pending_deprecation(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "vr" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
147
    vr: str | None = "",
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
148
    msg: str | None = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
149
):
150
    return status(CodeStatus.PENDING_DEPRECATION, vr, msg)
151
152
153
def deprecated(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "vr" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
154
    vr: str | None = "",
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
155
    msg: str | None = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
156
):
157
    return status(CodeStatus.DEPRECATED, vr, msg)
158
159
160
def removed(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "vr" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
161
    vr: str | None = "",
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
162
    msg: str | None = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
163
):
164
    return status(CodeStatus.REMOVED, vr, msg)
165
166
167
class _SpecialStr(str):
168
    """
169
    A string that can be displayed with Jupyter with line breaks and tabs.
170
    """
171
172
    def _repr_html_(self):
173
        return str(self.replace("\n", "<br />").replace("\t", "&emsp;&emsp;&emsp;&emsp;"))
174
175
176
class _Utils:
177
    @classmethod
178
    def exclude_fn(cls, *items) -> Callable[str, bool]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
introduced by
Value 'Callable' is unsubscriptable
Loading history...
179
        fns = [cls._exclude_fn(x) for x in items]
180
181
        def exclude(s: str):
0 ignored issues
show
Coding Style Naming introduced by
Argument name "s" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
182
            return any(fn(s) for fn in fns)
183
184
        return exclude
185
186
    @classmethod
187
    def _exclude_fn(cls, exclude) -> Callable[str, bool]:
0 ignored issues
show
introduced by
Value 'Callable' is unsubscriptable
Loading history...
188
        if exclude is None or exclude is False:
189
            return lambda s: False
190
        if isinstance(exclude, str):
0 ignored issues
show
unused-code introduced by
Unnecessary "elif" after "return"
Loading history...
191
            return lambda s: s == exclude
192
        elif isinstance(exclude, Collection):
193
            return lambda s: s in exclude
194
        elif callable(exclude):
195
            return exclude
196
        else:
197
            raise TypeError(str(exclude))
198
199
    @classmethod
200
    def gen_str(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
201
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
202
        obj,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
203
        fields: Collection[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Collection' is unsubscriptable
Loading history...
204
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
205
        exclude: Callable[[str], bool] = lambda _: False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Callable' is unsubscriptable
Loading history...
206
        address: bool = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
207
        angular: bool = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
208
    ):
209
        _name = obj.__class__.__name__
210
        _fields = ", ".join(
211
            k + "=" + ('"' + v + '"' if isinstance(v, str) else str(v))
212
            for k, v in cls.gen_list(obj, fields, exclude=exclude, address=address)
213
        )
214
        if angular:
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
215
            return f"<{_name} {_fields}>"
216
        else:
217
            return f"{_name}({_fields})"
218
219
    @classmethod
220
    def gen_html(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
221
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
222
        obj,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
223
        fields: Collection[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Collection' is unsubscriptable
Loading history...
224
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
225
        exclude: Callable[[str], bool] = lambda _: False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Callable' is unsubscriptable
Loading history...
226
        address: bool = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
227
        angular: bool = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
228
    ):
229
        _name = obj.__class__.__name__
230
        _fields = ", ".join(
231
            f"{k}={_html.escape(v)}"
232
            for k, v in cls.gen_list(obj, fields, exclude=exclude, address=address)
233
        )
234
        if angular:
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
235
            return f"&lt;<strong>{_name}</strong> {_fields}&gt;"
236
        else:
237
            return f"{_name}({_fields})"
238
239
    @classmethod
240
    def gen_list(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
241
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
242
        obj,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
243
        fields: Collection[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Collection' is unsubscriptable
Loading history...
244
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
245
        exclude: Callable[[str], bool] = lambda _: False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Callable' is unsubscriptable
Loading history...
246
        address: bool = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
247
    ):
248
        yield from _Utils.var_items(obj, fields, exclude=exclude)
249
        if address:
250
            yield "@", str(hex(id(obj)))
251
252
    @classmethod
253
    def var_items(cls, obj, fields, exclude):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
254
        yield from [
255
            (key, value)
256
            for key, value in vars(obj).items()
257
            if (fields is None) or (key in fields)
258
            if not key.startswith(f"_{obj.__class__.__name__}__")  # imperfect exclude mangled
259
            and not exclude(key)
260
        ]
261
262
263
def add_reprs(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (16/15).
Loading history...
264
    fields: Collection[str] | None = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Collection' is unsubscriptable
Loading history...
265
    *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
266
    exclude: Collection[str] | Callable[[str], bool] | None | Literal[False] = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Collection' is unsubscriptable
Loading history...
introduced by
Value 'Callable' is unsubscriptable
Loading history...
267
    exclude_from_str: Collection[str] | Callable[[str], bool] | None | Literal[False] = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Collection' is unsubscriptable
Loading history...
introduced by
Value 'Callable' is unsubscriptable
Loading history...
268
    exclude_from_repr: Collection[str] | Callable[[str], bool] | None | Literal[False] = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Collection' is unsubscriptable
Loading history...
introduced by
Value 'Callable' is unsubscriptable
Loading history...
269
    exclude_html: Collection[str] | Callable[[str], bool] | None | Literal[False] = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Collection' is unsubscriptable
Loading history...
introduced by
Value 'Callable' is unsubscriptable
Loading history...
270
    exclude_rich: Collection[str] | Callable[[str], bool] | None | Literal[False] = None,
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
introduced by
Value 'Collection' is unsubscriptable
Loading history...
introduced by
Value 'Callable' is unsubscriptable
Loading history...
271
    address: bool = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
272
    angular: bool = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
273
    html: bool = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
274
    rich: bool = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
275
):
276
    """
277
    Auto-adds ``__repr__``, ``__str__``, ``_repr_html``, and ``__rich_repr__``
278
    that use instances' attributes (``vars``).
279
    """
280
    exclude_from_repr = _Utils.exclude_fn(exclude, exclude_from_repr)
281
    exclude_from_str = _Utils.exclude_fn(exclude, exclude_from_str)
282
    exclude_html = _Utils.exclude_fn(exclude, exclude_html)
283
    exclude_rich = _Utils.exclude_fn(exclude, exclude_rich)
284
285
    def __repr(self) -> str:
286
        return _Utils.gen_str(self, fields, exclude=exclude_from_repr, address=address)
287
288
    def __str(self) -> str:
289
        return _Utils.gen_str(self, fields, exclude=exclude_from_str)
290
291
    def __html(self) -> str:
292
        return _Utils.gen_html(self, fields, exclude=exclude_html)
293
294
    if rich:
295
        from rich.repr import RichReprResult
0 ignored issues
show
introduced by
Unable to import 'rich.repr'
Loading history...
introduced by
Import outside toplevel (rich.repr.RichReprResult)
Loading history...
296
297
        def __rich(self) -> RichReprResult:
298
            yield from _Utils.gen_list(self, fields, exclude=exclude_rich)
299
300
    @wraps(add_reprs)
301
    def dec(cls):
302
        if cls.__str__ is object.__str__:
303
            cls.__str__ = __str
304
        if cls.__repr__ is object.__repr__:
305
            cls.__repr__ = __repr
306
        if not hasattr(cls, "_repr_html") and html:
307
            cls._repr_html_ = __html
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _repr_html_ was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
308
        if not hasattr(cls, "__rich_repr__") and rich:
309
            cls.__rich_repr__ = __rich
0 ignored issues
show
introduced by
The variable __rich does not seem to be defined in case rich on line 294 is False. Are you sure this can never be the case?
Loading history...
310
            cls.__rich_repr__.angular = angular
311
        return cls
312
313
    return dec
314
315
316
__all__ = [
317
    "abstractmethod",
318
    "total_ordering",
319
    "final",
320
    "CodeStatus",
321
    "status",
322
    "CodeIncompleteError",
323
    "PreviewWarning",
324
    "CodeRemovedError",
325
    "add_reprs",
326
    "deprecated",
327
    "pending_deprecation",
328
    "incomplete",
329
    "preview",
330
    "removed",
331
]
332