mypy: fix capa.features.common types

This commit is contained in:
William Ballenthin
2021-06-14 10:33:08 -06:00
parent 853d7285bd
commit 919aef90c0
2 changed files with 5 additions and 2 deletions

View File

@@ -170,6 +170,10 @@ class Regex(String):
if not isinstance(feature, (capa.features.common.String,)):
continue
if not isinstance(feature.value, str):
# this is a programming error: String should only contain str
raise ValueError("unexpected feature value type")
# `re.search` finds a match anywhere in the given string
# which implies leading and/or trailing whitespace.
# using this mode cleans is more convenient for rule authors,
@@ -214,7 +218,7 @@ class _MatchedRegex(Regex):
regex (Regex): the regex feature that matches.
match (Dict[string, List[int]]|None): mapping from matching string to its locations.
"""
super(_MatchedRegex, self).__init__(regex.value, description=regex.description)
super(_MatchedRegex, self).__init__(str(regex.value), description=regex.description)
# we want this to collide with the name of `Regex` above,
# so that it works nicely with the renderers.
self.name = "regex"

View File

@@ -319,7 +319,6 @@ def parse_description(s: Union[str, int, bytes], value_type: str, description=No
else:
# the value might be a number, like: `number: 10`
# or there might not be any description, like: `api: CreateFileA`
value = s
return value, description