From 3ca7e11863efdca35e860b1beb51f32d14e7113d Mon Sep 17 00:00:00 2001 From: alifeee Date: Tue, 31 Oct 2023 12:13:42 +0000 Subject: [PATCH 1/6] ignore mypy complaint for `format` --- gspread/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gspread/utils.py b/gspread/utils.py index e4a32b79f..45453a3a1 100644 --- a/gspread/utils.py +++ b/gspread/utils.py @@ -95,7 +95,7 @@ class ExportFormat(StrEnum): class PasteType(StrEnum): normal = "PASTE_NORMAL" values = "PASTE_VALUES" - format = "PASTE_FORMAT" + format = "PASTE_FORMAT" # type: ignore no_borders = "PASTE_NO_BORDERS" formula = "PASTE_NO_BORDERS" data_validation = "PASTE_DATA_VALIDATION" From f492ebac5a1d733cdaf98eb176d709d19c4e9397 Mon Sep 17 00:00:00 2001 From: alifeee Date: Tue, 31 Oct 2023 12:15:58 +0000 Subject: [PATCH 2/6] make default_blank type `Any` --- gspread/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gspread/utils.py b/gspread/utils.py index 45453a3a1..56b677e6d 100644 --- a/gspread/utils.py +++ b/gspread/utils.py @@ -160,7 +160,7 @@ def finditem(func: Callable[[T], bool], seq: Iterable[T]) -> T: def numericise( value: Optional[AnyStr], empty2zero: bool = False, - default_blank: Optional[AnyStr] = "", + default_blank: Any = "", allow_underscores_in_numeric_literals: bool = False, ) -> Optional[Union[int, float, AnyStr]]: """Returns a value that depends on the input: @@ -235,7 +235,7 @@ def numericise( def numericise_all( values: List[Optional[AnyStr]], empty2zero: bool = False, - default_blank: Optional[AnyStr] = "", + default_blank: Any = "", allow_underscores_in_numeric_literals: bool = False, ignore: List[int] = [], ) -> List[Optional[Union[int, float, AnyStr]]]: From 51b1f7d4c97f284d2664f7887f315fa722be6065 Mon Sep 17 00:00:00 2001 From: alifeee Date: Tue, 31 Oct 2023 12:27:27 +0000 Subject: [PATCH 3/6] replace spreadsheet `id` type with int from str --- gspread/http_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gspread/http_client.py b/gspread/http_client.py index 59c437678..551c5a823 100644 --- a/gspread/http_client.py +++ b/gspread/http_client.py @@ -259,7 +259,7 @@ def spreadsheets_get(self, id: str, params: Optional[ParamsType] = None) -> Any: return r.json() def spreadsheets_sheets_copy_to( - self, id: str, sheet_id: str, destination_spreadsheet_id: str + self, id: str, sheet_id: int, destination_spreadsheet_id: str ) -> Any: """Lower-level method that directly calls `spreadsheets.sheets.copyTo `_.""" url = SPREADSHEET_SHEETS_COPY_TO_URL % (id, sheet_id) From 8618e6cfcd8fa2470bf20e351a82e3eedc1059fd Mon Sep 17 00:00:00 2001 From: alifeee Date: Tue, 31 Oct 2023 12:29:31 +0000 Subject: [PATCH 4/6] make payload `Dict[str, Any]` --- gspread/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gspread/client.py b/gspread/client.py index 1f2ba2089..0e9d50a4f 100644 --- a/gspread/client.py +++ b/gspread/client.py @@ -194,7 +194,7 @@ def create(self, title: str, folder_id: Optional[str] = None) -> Spreadsheet: :returns: a :class:`~gspread.models.Spreadsheet` instance. """ - payload = { + payload: Dict[str, Any] = { "name": title, "mimeType": MimeType.google_sheets, } @@ -291,7 +291,7 @@ def copy( """ url = "{}/{}/copy".format(DRIVE_FILES_API_V3_URL, file_id) - payload = { + payload: Dict[str, Any] = { "name": title, "mimeType": MimeType.google_sheets, } From 4f24f594377cbf1b2127cf3580f7175d3d93c780 Mon Sep 17 00:00:00 2001 From: alifeee Date: Tue, 31 Oct 2023 12:32:09 +0000 Subject: [PATCH 5/6] make params `ParamsType` this feels like a band-aid patch mypy complained reasonably, as the enums are not in ParamsType --- gspread/worksheet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gspread/worksheet.py b/gspread/worksheet.py index c882f1ebd..ea9afc622 100644 --- a/gspread/worksheet.py +++ b/gspread/worksheet.py @@ -1910,7 +1910,7 @@ def append_rows( """ range_label = absolute_range_name(self.title, table_range) - params = { + params: ParamsType = { "valueInputOption": value_input_option, "insertDataOption": insert_data_option, "includeValuesInResponse": include_values_in_response, @@ -2025,7 +2025,7 @@ def insert_rows( range_label = absolute_range_name(self.title, "A%s" % row) - params = {"valueInputOption": value_input_option} + params: ParamsType = {"valueInputOption": value_input_option} body = {"majorDimension": Dimension.rows, "values": values} @@ -2090,7 +2090,7 @@ def insert_cols( range_label = absolute_range_name(self.title, rowcol_to_a1(1, col)) - params = {"valueInputOption": value_input_option} + params: ParamsType = {"valueInputOption": value_input_option} body = {"majorDimension": Dimension.cols, "values": values} From d0a0b48dcab9b6089a9c181837fb7b76d8cbba2e Mon Sep 17 00:00:00 2001 From: alifeee Date: Tue, 31 Oct 2023 12:32:29 +0000 Subject: [PATCH 6/6] add type check to lint --- .github/workflows/main.yaml | 1 - lint-requirements.txt | 3 +++ tox.ini | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 4928f6822..942f4b4bf 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -29,7 +29,6 @@ jobs: if: ${{ matrix.python >= '3.8' }} - run: tox -e lint - run: tox -e py - - run: mypy --install-types --non-interactive --ignore-missing-imports ./gspread || true - run: shopt -s globstar && pyupgrade --py3-only **/*.py # --py36-plus - run: safety check -i 42559 # pip <= 20.1.1, we upgrade it just above - run: tox -e build diff --git a/lint-requirements.txt b/lint-requirements.txt index c2b1fb04a..7280678b7 100644 --- a/lint-requirements.txt +++ b/lint-requirements.txt @@ -3,3 +3,6 @@ black==23.3.0 codespell==2.2.5 flake8==6.0.0 isort==5.12.0 +mypy==1.6.1 +mypy-extensions==1.0.0 +typing_extensions==4.8.0 diff --git a/tox.ini b/tox.ini index f4d98d593..9bcaf76eb 100644 --- a/tox.ini +++ b/tox.ini @@ -32,6 +32,7 @@ commands = black --check --diff --extend-exclude "./env" . codespell --skip=".tox,.git,./docs/build,.mypy_cache,./env" . flake8 . isort --check-only . + mypy --install-types --non-interactive --ignore-missing-imports ./gspread # Used by developers to format code, best advised to be run before commit [testenv:format]