Skip to content

Commit d84703e

Browse files
committed
Improve docstring of utils._make_chunk and utils.TextAttributes, fix type hinting.
1 parent 199bd21 commit d84703e

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

visualdialog/utils.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
# MA 02110-1301, USA.
1919
#
2020
#
21+
22+
from contextlib import ContextDecorator
2123
import _curses
22-
from typing import Generator, List, Tuple, TypeVar, Union
24+
from typing import (Generator, Iterable, List, NoReturn, Tuple, TypeVar,
25+
Union)
2326

2427

2528
Numeric = TypeVar("Numeric", int, float)
@@ -39,39 +42,40 @@
3942

4043
def _make_chunk(iterable: Union[Tuple, List],
4144
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.
4447
45-
:returns: Iterator separated into chunk_length bundles.
48+
:returns: Generator separated into ``chunk_length`` bundles.
4649
"""
4750
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))
4952

5053

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.
5356
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.
5659
57-
:param attributes: List of attributes to activate and desactivate.
60+
:param attributes: Iterable of ``curses`` text attributes to activate
61+
and desactivate.
5862
"""
5963
def __init__(self,
6064
win: CursesWindow,
61-
*attributes: CursesTextAttributesConstants):
65+
*attributes: Iterable[CursesTextAttributesConstant]):
6266
self.win = win
6367
self.attributes = attributes
6468

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``.
6872
"""
6973
for attr in self.attributes:
7074
self.win.attron(attr)
7175

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``.
7579
"""
7680
for attr in self.attributes:
7781
self.win.attroff(attr)

0 commit comments

Comments
 (0)