|
6 | 6 |
|
7 | 7 | from pwnlib.term import termcap |
8 | 8 |
|
9 | | -# Accept any module attribute for type checking purposes. |
10 | | -# The actual implementation of __getattr__ is below, and |
11 | | -# only accepts a defined text decorator pattern, but generating |
12 | | -# all possible combinations of text decorators is not feasible. |
13 | | -# No IDE auto-complete but at least no type errors. |
14 | 9 | _WhenSetter: TypeAlias = Literal["always", "never", "auto"] | TextIO |
15 | 10 | class _TextDecorator(Protocol): |
16 | 11 | def __call__(self, desc: str, when: _WhenSetter | None = None) -> str: ... |
17 | 12 |
|
18 | 13 | if TYPE_CHECKING: |
| 14 | + # Accept any module attribute for type checking purposes. |
| 15 | + # The actual implementation of __getattr__ is below, and |
| 16 | + # only accepts a defined text decorator pattern, but generating |
| 17 | + # all possible combinations of text decorators is not feasible. |
| 18 | + # No IDE auto-complete but at least no type errors. |
19 | 19 | def __getattr__(name: str) -> _TextDecorator: ... |
20 | 20 | def get(desc: str) -> _TextDecorator: ... |
21 | 21 | when: bool | _WhenSetter |
@@ -108,6 +108,8 @@ def f(self, s, when = None): |
108 | 108 | return functools.partial(f, self) |
109 | 109 |
|
110 | 110 | def __getattr__(self, desc: str) -> _TextDecorator: |
| 111 | + if desc in ('_TextDecorator', '_WhenSetter'): |
| 112 | + return {'_TextDecorator': _TextDecorator, '_WhenSetter': _WhenSetter}[desc] |
111 | 113 | if desc.startswith('_'): |
112 | 114 | raise AttributeError(desc) |
113 | 115 |
|
|
0 commit comments