|
18 | 18 | # MA 02110-1301, USA. |
19 | 19 | # |
20 | 20 | # |
| 21 | + |
| 22 | +from contextlib import ContextDecorator |
21 | 23 | import _curses |
22 | | -from typing import Generator, List, Tuple, TypeVar, Union |
| 24 | +from typing import (Generator, Iterable, List, NoReturn, Tuple, TypeVar, |
| 25 | + Union) |
23 | 26 |
|
24 | 27 |
|
25 | 28 | Numeric = TypeVar("Numeric", int, float) |
|
39 | 42 |
|
40 | 43 | def _make_chunk(iterable: Union[Tuple, List], |
41 | 44 | chunk_length: int) -> Generator: |
42 | | - """Returns a tuple that contains the given iterator separated |
43 | | - into chunk_length bundles. |
| 45 | + """Returns a tuple that contains given iterable separated into |
| 46 | + ``chunk_length`` bundles. |
44 | 47 |
|
45 | | - :returns: Iterator separated into chunk_length bundles. |
| 48 | + :returns: Generator separated into ``chunk_length`` bundles. |
46 | 49 | """ |
47 | 50 | return (iterable[chunk:chunk + chunk_length] |
48 | | - for chunk in range(0, len(iterable), chunk_length)) |
| 51 | + for chunk in range(0, len(iterable), chunk_length)) |
49 | 52 |
|
50 | 53 |
|
51 | | -class TextAttributes: |
52 | | - """A context manager to manage curses text attributs. |
| 54 | +class TextAttributes(ContextDecorator): |
| 55 | + """A context manager to manage ``curses`` text attributes. |
53 | 56 |
|
54 | | - :param win: `curses` window object for which the attributes will be |
55 | | - managed. |
| 57 | + :param win: ``curses`` window object for which the attributes will |
| 58 | + be managed. |
56 | 59 |
|
57 | | - :param attributes: List of attributes to activate and desactivate. |
| 60 | + :param attributes: Iterable of ``curses`` text attributes to activate |
| 61 | + and desactivate. |
58 | 62 | """ |
59 | 63 | def __init__(self, |
60 | 64 | win: CursesWindow, |
61 | | - *attributes: CursesTextAttributesConstants): |
| 65 | + *attributes: Iterable[CursesTextAttributesConstant]): |
62 | 66 | self.win = win |
63 | 67 | self.attributes = attributes |
64 | 68 |
|
65 | | - def __enter__(self): |
66 | | - """Activates one by one the attributes contained in |
67 | | - self.attributes. |
| 69 | + def __enter__(self) -> NoReturn: |
| 70 | + """Activate one by one attributes contained in self.attributes |
| 71 | + on ``self.win``. |
68 | 72 | """ |
69 | 73 | for attr in self.attributes: |
70 | 74 | self.win.attron(attr) |
71 | 75 |
|
72 | | - def __exit__(self, type, value, traceback): |
73 | | - """Disable one by one the attributes contained in |
74 | | - self.attributes. |
| 76 | + def __exit__(self, type, value, traceback) -> NoReturn: |
| 77 | + """Disable one by one attributes contained in |
| 78 | + ``self.attributes`` on ``self.win``. |
75 | 79 | """ |
76 | 80 | for attr in self.attributes: |
77 | 81 | self.win.attroff(attr) |
0 commit comments