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/platform.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'python/platform.py') diff --git a/python/platform.py b/python/platform.py index 98f3109a..4ecd57af 100644 --- a/python/platform.py +++ b/python/platform.py @@ -22,7 +22,7 @@ import os import ctypes import traceback import warnings -from typing import List, Dict, Optional, Tuple +from typing import List, Dict, Optional, Tuple, Any # Binary Ninja components import binaryninja @@ -56,6 +56,23 @@ class _PlatformMetaClass(type): raise KeyError("'%s' is not a valid platform" % str(value)) return CorePlatform(handle=platform) + def __contains__(cls: '_PlatformMetaClass', name: object) -> bool: + if not isinstance(name, str): + return False + try: + cls[name] + return True + except KeyError: + return False + + def get(cls: '_PlatformMetaClass', name: str, default: Any = None) -> Optional['Platform']: + try: + return cls[name] + except KeyError: + if default is not None: + return default + return None + class Platform(metaclass=_PlatformMetaClass): """ -- cgit v1.3.1