improve type annotations

This commit is contained in:
Jan Petykiewicz 2024-08-01 00:21:55 -07:00
parent fec96b92a7
commit 5f2b1a432e
3 changed files with 11 additions and 12 deletions

View File

@ -1,8 +1,8 @@
"""
Abstract class for cross-platform memory editing.
"""
from typing import Generator
from typing import Self
from collections.abc import Generator
from abc import ABCMeta, abstractmethod
from contextlib import contextmanager
import copy
@ -346,7 +346,7 @@ class Process(metaclass=ABCMeta):
@classmethod
@contextmanager
def open_process(cls, process_id: int) -> Generator['Process', None, None]:
def open_process(cls: type[Self], process_id: int) -> Generator[Self, None, None]:
"""
Context manager which automatically closes the constructed Process:
```

View File

@ -11,16 +11,15 @@ Utility functions and types:
Check if two buffers (ctypes objects) store equal values:
ctypes_equal(a, b)
"""
from typing import Union
import ctypes
ctypes_buffer_t = Union[
ctypes._SimpleCData,
ctypes.Array,
ctypes.Structure,
ctypes.Union,
]
ctypes_buffer_t = (
ctypes._SimpleCData
| ctypes.Array
| ctypes.Structure
| ctypes.Union
)
class MemEditError(Exception):

View File

@ -92,7 +92,7 @@ class MEMORY_BASIC_INFORMATION64(ctypes.Structure):
PTR_SIZE = ctypes.sizeof(ctypes.c_void_p)
MEMORY_BASIC_INFORMATION: ctypes.Structure
MEMORY_BASIC_INFORMATION: type[ctypes.Structure]
if PTR_SIZE == 8: # 64-bit python
MEMORY_BASIC_INFORMATION = MEMORY_BASIC_INFORMATION64
elif PTR_SIZE == 4: # 32-bit python
@ -256,7 +256,7 @@ class Process(AbstractProcess):
start = sys_info.lpMinimumApplicationAddress
stop = sys_info.lpMaximumApplicationAddress
def get_mem_info(address):
def get_mem_info(address: int) -> MEMORY_BASIC_INFORMATION:
"""
Query the memory region starting at or before 'address' to get its size/type/state/permissions.
"""