Skip to content

Commit d1122fd

Browse files
committed
Fix term.text type export
1 parent e82b3de commit d1122fd

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

pwnlib/term/text.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
from pwnlib.term import termcap
88

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.
149
_WhenSetter: TypeAlias = Literal["always", "never", "auto"] | TextIO
1510
class _TextDecorator(Protocol):
1611
def __call__(self, desc: str, when: _WhenSetter | None = None) -> str: ...
1712

1813
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.
1919
def __getattr__(name: str) -> _TextDecorator: ...
2020
def get(desc: str) -> _TextDecorator: ...
2121
when: bool | _WhenSetter
@@ -108,6 +108,8 @@ def f(self, s, when = None):
108108
return functools.partial(f, self)
109109

110110
def __getattr__(self, desc: str) -> _TextDecorator:
111+
if desc in ('_TextDecorator', '_WhenSetter'):
112+
return {'_TextDecorator': _TextDecorator, '_WhenSetter': _WhenSetter}[desc]
111113
if desc.startswith('_'):
112114
raise AttributeError(desc)
113115

0 commit comments

Comments
 (0)