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/debuginfo.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/debuginfo.py')
| -rw-r--r-- | python/debuginfo.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/python/debuginfo.py b/python/debuginfo.py index a76a8a6c..0b20ad69 100644 --- a/python/debuginfo.py +++ b/python/debuginfo.py @@ -19,7 +19,7 @@ # IN THE SOFTWARE. import ctypes -from typing import Optional, List, Iterator, Callable, Tuple +from typing import Optional, List, Iterator, Callable, Tuple, Any import traceback from dataclasses import dataclass, field @@ -78,6 +78,23 @@ class _DebugInfoParserMetaClass(type): assert parser_ref is not None, "core.BNNewDebugInfoParserReference returned None" return DebugInfoParser(parser_ref) + def __contains__(cls: '_DebugInfoParserMetaClass', name: object) -> bool: + if not isinstance(name, str): + return False + try: + cls[name] + return True + except KeyError: + return False + + def get(cls: '_DebugInfoParserMetaClass', name: str, default: Any = None) -> Optional['DebugInfoParser']: + try: + return cls[name] + except KeyError: + if default is not None: + return default + return None + @staticmethod def get_parsers_for_view(view: 'binaryview.BinaryView') -> List['DebugInfoParser']: """Returns a list of debug-info parsers that are valid for the provided binary view""" |
