From db8be1fc63f268716afa0acc9b1f86756bc554d5 Mon Sep 17 00:00:00 2001 From: Andreas Backx Date: Sat, 9 Nov 2024 16:49:06 +0000 Subject: [PATCH] Finalisation + extend tox typing to include all platforms. --- src/click/_compat.py | 4 ++-- src/click/_termui_impl.py | 5 ++--- src/click/_winconsole.py | 2 ++ tox.ini | 12 +++++++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/click/_compat.py b/src/click/_compat.py index 560899c08..f2726b93a 100644 --- a/src/click/_compat.py +++ b/src/click/_compat.py @@ -10,8 +10,8 @@ from types import TracebackType from weakref import WeakKeyDictionary -CYGWIN = sys.platform == "cygwin" -WIN = sys.platform == "win32" +CYGWIN = sys.platform.startswith("cygwin") +WIN = sys.platform.startswith("win") auto_wrap_for_ansi: t.Callable[[t.TextIO], t.TextIO] | None = None _ansi_re = re.compile(r"\033\[[;?0-9]*[a-zA-Z]") diff --git a/src/click/_termui_impl.py b/src/click/_termui_impl.py index ed5a15505..833b9fe5d 100644 --- a/src/click/_termui_impl.py +++ b/src/click/_termui_impl.py @@ -711,12 +711,11 @@ def getchar(echo: bool) -> str: # # Anyway, Click doesn't claim to do this Right(tm), and using `getwch` # is doing the right thing in more situations than with `getch`. - func: t.Callable[[], str] if echo: - func = msvcrt.getwche + func = t.cast(t.Callable[[], str], msvcrt.getwche) else: - func = msvcrt.getwch + func = t.cast(t.Callable[[], str], msvcrt.getwch) rv = func() diff --git a/src/click/_winconsole.py b/src/click/_winconsole.py index 25acadf50..b01035b29 100644 --- a/src/click/_winconsole.py +++ b/src/click/_winconsole.py @@ -70,6 +70,8 @@ if t.TYPE_CHECKING: try: + # Using `typing_extensions.Buffer` instead of `collections.abc` + # on Windows for some reason does not have `Sized` implemented. from collections.abc import Buffer # type: ignore except ImportError: from typing_extensions import Buffer diff --git a/tox.ini b/tox.ini index 5d0d18693..744b162e6 100644 --- a/tox.ini +++ b/tox.ini @@ -23,9 +23,15 @@ commands = pre-commit run --all-files [testenv:typing] deps = -r requirements/typing.txt commands = - mypy - pyright tests/typing - pyright --verifytypes click --ignoreexternal + mypy --platform linux + mypy --platform darwin + mypy --platform win32 + pyright tests/typing --pythonplatform Linux + pyright tests/typing --pythonplatform Darwin + pyright tests/typing --pythonplatform Windows + pyright --verifytypes click --ignoreexternal --pythonplatform Linux + pyright --verifytypes click --ignoreexternal --pythonplatform Darwin + pyright --verifytypes click --ignoreexternal --pythonplatform Windows [testenv:docs] deps = -r requirements/docs.txt