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/lineformatter.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/lineformatter.py')
| -rw-r--r-- | python/lineformatter.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/python/lineformatter.py b/python/lineformatter.py index 7f74572b..f63526f1 100644 --- a/python/lineformatter.py +++ b/python/lineformatter.py @@ -21,7 +21,7 @@ import ctypes import traceback from dataclasses import dataclass -from typing import List, Optional, Union +from typing import List, Optional, Union, Any # Binary Ninja components import binaryninja @@ -118,6 +118,23 @@ class _LineFormatterMetaClass(type): raise KeyError("'%s' is not a valid formatter" % str(value)) return CoreLineFormatter(handle=lang) + def __contains__(cls: '_LineFormatterMetaClass', name: object) -> bool: + if not isinstance(name, str): + return False + try: + cls[name] + return True + except KeyError: + return False + + def get(cls: '_LineFormatterMetaClass', name: str, default: Any = None) -> Optional['LineFormatter']: + try: + return cls[name] + except KeyError: + if default is not None: + return default + return None + class LineFormatter(metaclass=_LineFormatterMetaClass): """ |
