Skip to content

Commit 4e8ea46

Browse files
Make types more allowing and run mypy in CI
1 parent 96bfb3e commit 4e8ea46

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

.github/workflows/lint.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,16 @@ jobs:
2626
with:
2727
skip: '*.po'
2828
ignore_words_list: te,ot
29+
30+
mypy:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v2
34+
- uses: actions/setup-python@v2
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install mypy
39+
pip install "blessings>=1.5" cwcwidth "backports.cached-property; python_version < '3.9'" pyte
40+
- name: Check with mypy
41+
run: python -m mypy

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [0.3.8] - 2021-09-27
4+
- Change typing of `event_trigger(event_type)` to allow a function that returns None
5+
36
## [0.3.7] - 2021-09-27
47
- Fixed ctrl-c not being reported until another key was pressed in Python 3.5+
58

curtsies/formatstring.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __len__(self) -> int:
137137

138138
@property
139139
def width(self) -> int:
140-
width = wcswidth(self._s)
140+
width = wcswidth(self._s, None)
141141
if len(self._s) > 0 and width < 1:
142142
raise ValueError("Can't calculate width of string %r" % self._s)
143143
return width
@@ -240,7 +240,7 @@ def request(self, max_width: int) -> Optional[Tuple[int, Chunk]]:
240240
replacement_char = " "
241241

242242
while True:
243-
w = wcswidth(s[i])
243+
w = wcswidth(s[i], None)
244244

245245
# If adding a character puts us over the requested width, return what we've got so far
246246
if width + w > max_width:
@@ -644,7 +644,7 @@ def __getitem__(self, index: Union[int, slice]) -> "FmtStr":
644644

645645
def width_aware_slice(self, index: Union[int, slice]) -> "FmtStr":
646646
"""Slice based on the number of columns it would take to display the substring."""
647-
if wcswidth(self.s) == -1:
647+
if wcswidth(self.s, None) == -1:
648648
raise ValueError("bad values for width aware slicing")
649649
index = normalize_slice(self.width, index)
650650
counter = 0
@@ -672,7 +672,7 @@ def width_aware_splitlines(self, columns: int) -> Iterator["FmtStr"]:
672672
"""
673673
if columns < 2:
674674
raise ValueError("Column width %s is too narrow." % columns)
675-
if wcswidth(self.s) == -1:
675+
if wcswidth(self.s, None) == -1:
676676
raise ValueError("bad values for width aware slicing")
677677
return self._width_aware_splitlines(columns)
678678

curtsies/input.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181

8282
self.readers: List[int] = []
8383
self.queued_interrupting_events: List[Union[events.Event, str]] = []
84-
self.queued_events: List[events.Event] = []
84+
self.queued_events: List[Union[events.Event, None]] = []
8585
self.queued_scheduled_events: List[Tuple[float, events.ScheduledEvent]] = []
8686

8787
# prospective: this could be useful for an external select loop
@@ -313,7 +313,9 @@ def _nonblocking_read(self) -> int:
313313
else:
314314
return 0
315315

316-
def event_trigger(self, event_type: Type[events.Event]) -> Callable:
316+
def event_trigger(
317+
self, event_type: Union[Type[events.Event], Callable[..., None]]
318+
) -> Callable:
317319
"""Returns a callback that creates events.
318320
319321
Returned callback function will add an event of type event_type

0 commit comments

Comments
 (0)