Skip to content

Commit fc810d2

Browse files
committed
Fix mypy error with setuptools 7.6.8 type hints
The hints in 7.6.0 seems to have had some changes that now forces us to be much more pedantic when defining the `user_options` attribute in `setuptools.Command` subclasses. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent ba041fe commit fc810d2

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/frequenz/repo/config/setuptools/grpc_tools.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import pathlib as _pathlib
1414
import subprocess as _subprocess
1515
import sys as _sys
16+
from typing import cast
1617

1718
import setuptools as _setuptools
1819
import setuptools.command.build as _build_command
@@ -38,24 +39,31 @@ class CompileProto(_setuptools.Command):
3839
description: str = "compile protobuf files"
3940
"""Description of the command."""
4041

41-
user_options: list[tuple[str, str | None, str]] = [
42-
(
43-
"proto-path=",
44-
None,
45-
"path of the root directory containing the protobuf files",
46-
),
47-
("proto-glob=", None, "glob pattern to use to find the protobuf files"),
48-
(
49-
"include-paths=",
50-
None,
51-
"comma-separated list of paths to include when compiling the protobuf files",
52-
),
53-
(
54-
"py-path=",
55-
None,
56-
"path of the root directory where the Python files will be generated",
57-
),
58-
]
42+
# We need the cast here because Command.user_options has the type annoatation
43+
# ClassVar[list[tuple[str, str, str]] | list[tuple[str, str | None, str]]] but the
44+
# expression resolves to list[tuple[str, None, str]] and mypy is not smart enough to
45+
# see that this is compatible with the list[tuple[str, str | None, str]] variant.
46+
user_options = cast(
47+
list[tuple[str, str, str]] | list[tuple[str, str | None, str]],
48+
[
49+
(
50+
"proto-path=",
51+
None,
52+
"path of the root directory containing the protobuf files",
53+
),
54+
("proto-glob=", None, "glob pattern to use to find the protobuf files"),
55+
(
56+
"include-paths=",
57+
None,
58+
"comma-separated list of paths to include when compiling the protobuf files",
59+
),
60+
(
61+
"py-path=",
62+
None,
63+
"path of the root directory where the Python files will be generated",
64+
),
65+
],
66+
)
5967
"""Options of the command."""
6068

6169
def initialize_options(self) -> None:

0 commit comments

Comments
 (0)