Skip to content

Commit ee1f9a6

Browse files
Review comments
1 parent 55632ba commit ee1f9a6

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

configuration/steps/generators/cmake/options.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
try:
66
# breaking change introduced in python 3.11
7-
from enum import StrEnum
7+
from enum import StrEnum # pyright: ignore
88
except ImportError: # pragma: no cover
9-
from configuration.steps.generators.base.options import StrEnum
9+
from configuration.steps.generators.base.options import StrEnum # pyright: ignore
1010

1111

1212
# Flag names use UPPER_CASE
@@ -158,32 +158,31 @@ class CMakeVariableOption(Option):
158158

159159
def __init__(self, name: StrEnum, value: Union[str, bool]):
160160
if isinstance(value, bool):
161-
if isinstance(name, PLUGIN):
162-
value = "YES" if value else "NO"
163-
else:
164-
value = "ON" if value else "OFF"
161+
value = "ON" if value else "OFF"
165162
super().__init__(name, value)
166163

167164
def as_cmd_arg(self) -> str:
168165
return f"-D{self.name}={self.value}"
169166

170167

168+
class CMakePluginOption(CMakeVariableOption):
169+
def __init__(self, name: PLUGIN, value: bool):
170+
assert isinstance(value, bool)
171+
super().__init__(name, "YES" if value else "NO")
172+
173+
171174
class CMakeFlagOption(Option):
172175
"""
173176
Represents a flag-like option (e.g., --trace, --trace-expand).
174177
"""
175178

176179
def __init__(self, name: StrEnum, value: bool):
177-
if isinstance(value, bool):
178-
value = f"--{name}" if value else ""
179-
else:
180-
raise ValueError(
181-
f"Flag option '{type(name)}-{name}' must be initialized with a boolean value at creation time. Got {type(value)} instead."
182-
)
183-
super().__init__(name, value)
180+
assert isinstance(value, bool)
181+
flag = f"--{name}" if value else ""
182+
super().__init__(name, flag)
184183

185184
def as_cmd_arg(self) -> str:
186-
return f"{self.value}"
185+
return str(self.value)
187186

188187

189188
class CMakeWarnOption(Option):
@@ -192,16 +191,12 @@ class CMakeWarnOption(Option):
192191
"""
193192

194193
def __init__(self, name: StrEnum, value: bool):
195-
if isinstance(value, bool):
196-
value = f"-W{'' if value else 'no-'}{name}"
197-
else:
198-
raise ValueError(
199-
f"Flag option '{type(name)}-{name}' must be initialized with a boolean value at creation time. Got {type(value)} instead."
200-
)
201-
super().__init__(name, value)
194+
assert isinstance(value, bool)
195+
flag = f"-W{'' if value else 'no-'}{name}"
196+
super().__init__(name, flag)
202197

203198
def as_cmd_arg(self) -> str:
204-
return f"{self.value}"
199+
return str(self.value)
205200

206201

207202
class CMakeOption:
@@ -235,7 +230,7 @@ class CMakeOption:
235230
def __new__(cls, obj: StrEnum, value: Union[str, bool]) -> Option:
236231
for base_classes, handler_class in cls.HANDLERS:
237232
if isinstance(obj, base_classes):
238-
return handler_class(obj, value)
233+
return handler_class(obj, value) # pyright: ignore
239234
raise ValueError(
240235
f"No handler found for object of type {type(obj)}. Cannot create a CMake option."
241236
)

0 commit comments

Comments
 (0)