summaryrefslogtreecommitdiff
path: root/python/binaryview.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2025-11-20 09:58:28 -0500
committerPeter LaFosse <peter@vector35.com>2025-11-21 10:02:50 -0500
commit5880769cbac1362aad46a34faec4c553fa9fcac6 (patch)
tree02db205b7aa915900cbfc10384940b3750eb7d69 /python/binaryview.py
parentf52693d50de6a5c97afa0274277edca18cfa00ea (diff)
Add get and __contains__ methods to all *MetaClass
Fixes: https://github.com/Vector35/binaryninja-api/issues/7588
Diffstat (limited to 'python/binaryview.py')
-rw-r--r--python/binaryview.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 5c49a697..d0d20405 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -1448,6 +1448,23 @@ class _BinaryViewTypeMetaclass(type):
raise KeyError(f"'{value}' is not a valid view type")
return BinaryViewType(view_type)
+ def __contains__(cls: '_BinaryViewTypeMetaclass', name: object) -> bool:
+ if not isinstance(name, str):
+ return False
+ try:
+ cls[name]
+ return True
+ except KeyError:
+ return False
+
+ def get(cls: '_BinaryViewTypeMetaclass', name: str, default: Any = None) -> Optional['BinaryViewType']:
+ try:
+ return cls[name]
+ except KeyError:
+ if default is not None:
+ return default
+ return None
+
class BinaryViewType(metaclass=_BinaryViewTypeMetaclass):
"""