diff options
| author | Peter LaFosse <peter@vector35.com> | 2025-11-20 09:58:28 -0500 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2025-11-21 10:02:50 -0500 |
| commit | 5880769cbac1362aad46a34faec4c553fa9fcac6 (patch) | |
| tree | 02db205b7aa915900cbfc10384940b3750eb7d69 /python/update.py | |
| parent | f52693d50de6a5c97afa0274277edca18cfa00ea (diff) | |
Add get and __contains__ methods to all *MetaClass
Fixes: https://github.com/Vector35/binaryninja-api/issues/7588
Diffstat (limited to 'python/update.py')
| -rw-r--r-- | python/update.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/python/update.py b/python/update.py index 308094f7..f88770fd 100644 --- a/python/update.py +++ b/python/update.py @@ -20,6 +20,7 @@ import traceback import ctypes +from typing import Any, Optional # Binary Ninja components import binaryninja @@ -65,6 +66,23 @@ class _UpdateChannelMetaClass(type): raise KeyError("'%s' is not a valid channel" % str(name)) return result + def __contains__(cls: '_UpdateChannelMetaClass', name: object) -> bool: + if not isinstance(name, str): + return False + try: + cls[name] + return True + except KeyError: + return False + + def get(cls: '_UpdateChannelMetaClass', name: str, default: Any = None) -> Optional['UpdateChannel']: + try: + return cls[name] + except KeyError: + if default is not None: + return default + return None + class UpdateProgressCallback: def __init__(self, func): |
