Skip to content

Commit af60682

Browse files
author
Tavian Barnes
committed
mypy: Make the config stricter
1 parent dc65c0e commit af60682

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

python/bistring/_alignment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __init__(self, values: Iterable[Bounds]):
103103

104104
@classmethod
105105
def _create(cls, original: List[int], modified: List[int]) -> Alignment:
106-
result = super().__new__(cls)
106+
result: Alignment = super().__new__(cls)
107107
result._original = original
108108
result._modified = modified
109109
return result
@@ -146,7 +146,7 @@ def _parse_bounds(cls, args: Tuple[AnyBounds, ...]) -> Bounds:
146146
raise ValueError('slice with unspecified bounds')
147147
return arg.start, arg.stop
148148
elif isinstance(arg, tuple):
149-
return cast(Bounds, arg)
149+
return arg
150150
else:
151151
return 0, arg
152152
elif l == 2:

python/bistring/_bistr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __new__(cls, original: String, modified: Optional[str] = None, alignment: Op
9696
elif alignment.modified_bounds() != (0, len(modified)):
9797
raise ValueError('Alignment incompatible with modified string')
9898

99-
result = object.__new__(cls)
99+
result: bistr = object.__new__(cls)
100100
object.__setattr__(result, 'original', original)
101101
object.__setattr__(result, 'modified', modified)
102102
object.__setattr__(result, 'alignment', alignment)

python/bistring/_token.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from dataclasses import dataclass
1919
import icu
2020
import threading
21-
from typing import Callable, Iterable, Iterator, Sequence, Union, overload
21+
from typing import Callable, Iterable, Iterator, Optional, Sequence, Union, overload
2222

2323
from ._alignment import Alignment
2424
from ._bistr import bistr, String
@@ -360,9 +360,11 @@ def __init__(self, locale: str, constructor: Callable[[icu.Locale], icu.BreakIte
360360
self._break_iterator()
361361

362362
def _break_iterator(self) -> icu.BreakIterator:
363-
if not hasattr(self._local, 'bi'):
364-
self._local.bi = self._constructor(self._locale)
365-
return self._local.bi
363+
bi: Optional[icu.BreakIterator] = getattr(self._local, 'bi', None)
364+
if bi is None:
365+
bi = self._constructor(self._locale)
366+
self._local.bi = bi
367+
return bi
366368

367369
def tokenize(self, text: String) -> Tokenization:
368370
text = bistr(text)

python/mypy.ini

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
[mypy]
22
mypy_path = ./stubs
3+
disallow_subclassing_any = True
4+
disallow_untyped_calls = True
5+
disallow_untyped_defs = True
6+
disallow_incomplete_defs = True
7+
disallow_untyped_decorators = True
8+
no_implicit_optional = True
9+
warn_no_return = True
10+
warn_return_any = True
11+
warn_unreachable = True
12+
warn_incomplete_stub = True
13+
warn_redundant_casts = True
14+
show_error_context = True

python/stubs/icu.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CaseMap:
4040

4141

4242
class Edits:
43-
def __init__(self): ...
43+
def __init__(self) -> None: ...
4444

4545
def getFineIterator(self) -> Iterator[Tuple[bool, int, int, int, int, int]]: ...
4646

0 commit comments

Comments
 (0)