summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2023-01-10 14:27:01 -0500
committerJosh Ferrell <josh@vector35.com>2023-01-10 14:27:01 -0500
commit8d8ff383fcadfae36136ddb09faea6774b0419d0 (patch)
tree82180b332b536b809388649be1fa838e7f2c2c30
parent3db9560c0d290e13a7bc24e486d4942fd9b491f8 (diff)
Annotate TypeBuilder.builder(...) as returning proper subclass
-rw-r--r--python/types.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/python/types.py b/python/types.py
index bc074206..90eba4d7 100644
--- a/python/types.py
+++ b/python/types.py
@@ -19,10 +19,10 @@
# IN THE SOFTWARE.
import ctypes
-from typing import Generator, List, Union, Mapping, Tuple, Optional, Iterable, Dict
+import typing
+from typing import Generator, List, Union, Tuple, Optional, Iterable, Dict, Generic, TypeVar
from dataclasses import dataclass
import uuid
-from abc import abstractmethod
# Binary Ninja components
from . import _binaryninjacore as core
@@ -58,6 +58,8 @@ MemberName = str
MemberIndex = int
MemberOffset = int
+TB = TypeVar('TB', bound='TypeBuilder')
+
class QualifiedName:
def __init__(self, name: Optional[QualifiedNameType] = None):
@@ -478,8 +480,8 @@ class BoolWithConfidence:
@dataclass
-class MutableTypeBuilder:
- type: 'TypeBuilder'
+class MutableTypeBuilder(Generic[TB]):
+ type: TB
container: TypeContainer
name: QualifiedName
platform: Optional['_platform.Platform']
@@ -566,9 +568,9 @@ class TypeBuilder:
@classmethod
def builder(
- cls, container: TypeContainer, name: 'QualifiedName', user: bool = True, platform: Optional['_platform.Platform'] = None,
+ cls: typing.Type[TB], container: TypeContainer, name: 'QualifiedName', user: bool = True, platform: Optional['_platform.Platform'] = None,
confidence: int = core.max_confidence
- ) -> 'MutableTypeBuilder':
+ ) -> 'MutableTypeBuilder[TB]':
return MutableTypeBuilder(cls.create(), container, name, platform, confidence, user)
@staticmethod
@@ -1896,7 +1898,7 @@ class Type:
self._platform = value
def mutable_copy(self) -> 'TypeBuilder':
- TypeBuilders = {
+ TypeBuilders: Dict[TypeClass, typing.Type[TypeBuilder]] = {
TypeClass.VoidTypeClass: VoidBuilder, TypeClass.BoolTypeClass: BoolBuilder,
TypeClass.IntegerTypeClass: IntegerBuilder, TypeClass.FloatTypeClass: FloatBuilder,
TypeClass.PointerTypeClass: PointerBuilder, TypeClass.ArrayTypeClass: ArrayBuilder,