Skip to content

Commit fb74ed1

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

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

pwnlib/term/text.py

Lines changed: 14 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
@@ -80,6 +80,15 @@ def has_bright(self):
8080
def has_gray(self):
8181
return self.has_bright
8282

83+
# Export the _WhenSetter and _TextDecorator types for type checking purposes.
84+
@property
85+
def _WhenSetter(self):
86+
return _WhenSetter
87+
88+
@property
89+
def _TextDecorator(self):
90+
return _TextDecorator
91+
8392
def _fg_color(self, c):
8493
c = termcap.get('setaf', c) or termcap.get('setf', c)
8594
if not hasattr(c, 'encode'):

0 commit comments

Comments
 (0)