create function assert_never

This commit is contained in:
cl3o
2021-12-04 19:02:54 +01:00
parent 39536e2727
commit 061a66e437
2 changed files with 9 additions and 2 deletions

View File

@@ -7,6 +7,7 @@
# See the License for the specific language governing permissions and limitations under the License.
import os
from typing import NoReturn
_hex = hex
@@ -30,3 +31,7 @@ def is_runtime_ida():
return False
else:
return True
def assert_never(value: NoReturn) -> NoReturn:
assert False, f'Unhandled value: {value} ({type(value).__name__})'

View File

@@ -16,6 +16,8 @@ import functools
import collections
from enum import Enum
from capa.helpers import assert_never
try:
from functools import lru_cache
except ImportError:
@@ -1090,7 +1092,7 @@ class RuleSet:
rec(rule_name, child)
else:
# programming error
raise Exception("programming error: unexpected node type: %s" % (node))
assert_never(node)
for rule in rules:
rule_name = rule.meta["name"]
@@ -1195,7 +1197,7 @@ class RuleSet:
easy_rules_by_feature = self._easy_basic_block_rules_by_feature
hard_rule_names = self._hard_basic_block_rules
else:
raise Exception("programming error: unexpected scope")
assert_never(scope)
candidate_rule_names = set()
for feature in features: