Skip to content

Commit 1733245

Browse files
committed
Unabled ruff PYI ruleset for type hint best practices
1 parent a130889 commit 1733245

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

cmd2/argparse_custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens)
264264
)
265265

266266

267-
def generate_range_error(range_min: int, range_max: Union[int, float]) -> str:
267+
def generate_range_error(range_min: int, range_max: float) -> str:
268268
"""Generate an error message when the the number of arguments provided is not within the expected range"""
269269
err_str = "expected "
270270

cmd2/table_creator.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
Optional,
2222
Sequence,
2323
Tuple,
24-
Union,
2524
)
2625

2726
from wcwidth import ( # type: ignore[import]
@@ -69,7 +68,7 @@ def __init__(
6968
data_horiz_align: HorizontalAlignment = HorizontalAlignment.LEFT,
7069
data_vert_align: VerticalAlignment = VerticalAlignment.TOP,
7170
style_data_text: bool = True,
72-
max_data_lines: Union[int, float] = constants.INFINITY,
71+
max_data_lines: float = constants.INFINITY,
7372
) -> None:
7473
"""
7574
Column initializer
@@ -156,7 +155,7 @@ def __init__(self, cols: Sequence[Column], *, tab_width: int = 4) -> None:
156155
col.width = max(1, ansi.widest_line(col.header))
157156

158157
@staticmethod
159-
def _wrap_long_word(word: str, max_width: int, max_lines: Union[int, float], is_last_word: bool) -> Tuple[str, int, int]:
158+
def _wrap_long_word(word: str, max_width: int, max_lines: float, is_last_word: bool) -> Tuple[str, int, int]:
160159
"""
161160
Used by _wrap_text() to wrap a long word over multiple lines
162161
@@ -220,7 +219,7 @@ def _wrap_long_word(word: str, max_width: int, max_lines: Union[int, float], is_
220219
return wrapped_buf.getvalue(), total_lines, cur_line_width
221220

222221
@staticmethod
223-
def _wrap_text(text: str, max_width: int, max_lines: Union[int, float]) -> str:
222+
def _wrap_text(text: str, max_width: int, max_lines: float) -> str:
224223
"""
225224
Wrap text into lines with a display width no longer than max_width. This function breaks words on whitespace
226225
boundaries. If a word is longer than the space remaining on a line, then it will start on a new line.

cmd2/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def __bool__(self) -> bool:
709709
def __enter__(self) -> None:
710710
self.__count += 1
711711

712-
def __exit__(self, *args: Any) -> None:
712+
def __exit__(self, *args: object) -> None:
713713
self.__count -= 1
714714
if self.__count < 0:
715715
raise ValueError("count has gone below 0")

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ select = [
201201
# "PLW", # Pylint Warnings
202202
# "PT", # flake8-pytest-style (warnings about unit test best practices)
203203
# "PTH", # flake8-use-pathlib (force use of pathlib instead of os.path)
204-
# "PYI", # flake8-pyi (warnings related to type hint best practices)
204+
"PYI", # flake8-pyi (warnings related to type hint best practices)
205205
# "Q", # flake8-quotes (force double quotes)
206206
# "RET", # flake8-return (various warnings related to implicit vs explicit return statements)
207207
"RSE", # flake8-raise (warn about unnecessary parentheses on raised exceptions)
@@ -238,6 +238,10 @@ per-file-ignores."cmd2/__init__.py" = [
238238
"F401", # Unused import
239239
]
240240

241+
per-file-ignores."cmd2/cmd2.py" = [
242+
"PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple`
243+
]
244+
241245
per-file-ignores."docs/conf.py" = [
242246
"F401", # Unused import
243247
]
@@ -251,7 +255,7 @@ per-file-ignores."examples/scripts/*.py" = [
251255
]
252256

253257
per-file-ignores."examples/unicode_commands.py" = [
254-
"PLC2401", # Allow non-ASCII characters in function names
258+
"PLC2401", # non-ASCII characters in function names
255259
]
256260

257261
per-file-ignores."tests/pyscript/*.py" = [

0 commit comments

Comments
 (0)