summaryrefslogtreecommitdiff
path: root/python/languagerepresentation.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/languagerepresentation.py
parentf52693d50de6a5c97afa0274277edca18cfa00ea (diff)
Add get and __contains__ methods to all *MetaClass
Fixes: https://github.com/Vector35/binaryninja-api/issues/7588
Diffstat (limited to 'python/languagerepresentation.py')
-rw-r--r--python/languagerepresentation.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/python/languagerepresentation.py b/python/languagerepresentation.py
index b7dc840d..ba5c44d0 100644
--- a/python/languagerepresentation.py
+++ b/python/languagerepresentation.py
@@ -20,7 +20,7 @@
import ctypes
import traceback
-from typing import List, Optional, Union
+from typing import List, Optional, Union, Any
# Binary Ninja components
import binaryninja
@@ -664,6 +664,23 @@ class _LanguageRepresentationFunctionTypeMetaClass(type):
raise KeyError("'%s' is not a valid language" % str(value))
return CoreLanguageRepresentationFunctionType(handle=lang)
+ def __contains__(cls: '_LanguageRepresentationFunctionTypeMetaClass', name: object) -> bool:
+ if not isinstance(name, str):
+ return False
+ try:
+ cls[name]
+ return True
+ except KeyError:
+ return False
+
+ def get(cls: '_LanguageRepresentationFunctionTypeMetaClass', name: str, default: Any = None) -> Optional['LanguageRepresentationFunctionType']:
+ try:
+ return cls[name]
+ except KeyError:
+ if default is not None:
+ return default
+ return None
+
class LanguageRepresentationFunctionType(metaclass=_LanguageRepresentationFunctionTypeMetaClass):
"""