From 5880769cbac1362aad46a34faec4c553fa9fcac6 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 20 Nov 2025 09:58:28 -0500 Subject: Add get and __contains__ methods to all *MetaClass Fixes: https://github.com/Vector35/binaryninja-api/issues/7588 --- python/binaryview.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'python/binaryview.py') 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): """ -- cgit v1.3.1