Skip to content

Commit 276c5ce

Browse files
author
Arnaud Riess
committed
refactor: improve type casting and validation in _get_normalized function
1 parent 61c8842 commit 276c5ce

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/extensions/score_metamodel/checks/check_options.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
import re
14+
from typing import cast
1415

1516
from score_metamodel import (
1617
CheckLogger,
@@ -40,8 +41,13 @@ def _get_normalized(need: NeedItem, key: str, remove_prefix: bool = False) -> li
4041
if remove_prefix:
4142
return [_remove_namespace_prefix_(raw_value)]
4243
return [raw_value]
43-
if isinstance(raw_value, list) and all(isinstance(v, str) for v in raw_value):
44-
str_list: list[str] = raw_value
44+
if isinstance(raw_value, list):
45+
# Verify all elements are strings
46+
raw_list = cast(list[object], raw_value)
47+
for item in raw_list:
48+
if not isinstance(item, str):
49+
raise ValueError
50+
str_list = cast(list[str], raw_value)
4551
if remove_prefix:
4652
return [_remove_namespace_prefix_(v) for v in str_list]
4753
return str_list

0 commit comments

Comments
 (0)