Skip to content

Mypy#20

Merged
lacraig2 merged 6 commits intomainfrom
mypy
Mar 13, 2026
Merged

Mypy#20
lacraig2 merged 6 commits intomainfrom
mypy

Conversation

@lacraig2
Copy link
Contributor

This PR adds static type checking to everything in our source directory.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens DFFI.addressof() / pointer dereferencing behavior (including C-like array-to-pointer decay) and introduces stricter typing across the codebase, backed by new tests and a mypy CI step.

Changes:

  • Add tests that validate addressof() type-info normalization, nested-field addressing, array decay, and safe deref.
  • Refine internal typing (Protocols/type aliases) and add mypy strict configuration + CI check.
  • Harden a few runtime paths (symbol shifting, pointer deref / stride logic) to avoid crashes on unexpected None/type shapes.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/test_addressof_enhancement.py Adds regression tests for addressof() normalization/decay and deref safety.
src/dwarffi/dffi.py Normalizes addressof() target type info to dicts and applies array decay; improves typing in multiple APIs.
src/dwarffi/instances.py Tightens typing for bound instances/pointers; adjusts deref/arithmetic logic and cache/field access typing.
src/dwarffi/types.py Introduces typing helpers/aliases, narrows cache field types, and improves type flattening metadata.
src/dwarffi/parser.py Small robustness improvements around symbol shifting and type-size computation typing.
src/dwarffi/dtyping.py New Protocol/type-alias module to centralize shared typing without runtime circular imports.
pyproject.toml Adds mypy to dev deps and configures strict mypy settings.
.github/workflows/ci.yml Adds a mypy step to CI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +67 to +68
# Clear the cache to ensure new types are recognized
self._parse_ctype_string.cache_clear() # type: ignore[attr-defined]
current_type: Union[TypeInfoDict, Vtype] = cdata._instance_type_def
for field_name in fields_or_indexes:
if not isinstance(current_type, VtypeUserType):
break # Should be caught by offsetof, but safety first
Comment on lines +992 to +996
# Build a multiplier format string, e.g., "<1000I"
fmt = f"{base_struct.format[0]}{count}{base_struct.format[1:]}"
buf = cdata._parent_instance._instance_buffer
offset = cdata._parent_instance._instance_offset + cdata._array_start_offset_in_parent
return list(struct.unpack_from(fmt, buf, offset)) # type: ignore[arg-type]
else:
subtype = self._subtype_info

# If the target is ALSO a pointer, we must read the raw pointer value from memory

def __ne__(self, other):
def __eq__(self, other: Any) -> bool:
return self.address == (other.address if isinstance(other, Ptr) else other)

# Pre-fetch the concrete type object
resolved_obj = None
# Explicity type this to prevent None union drift
import base64
import struct
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Tuple, Union, cast
@@ -0,0 +1,42 @@
from typing import TYPE_CHECKING, Any, Dict, Optional, Protocol, Tuple, Union, runtime_checkable
@lacraig2 lacraig2 merged commit 0e319ec into main Mar 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants