Skip to content

Commit

Permalink
gh-129805: Fix bytes annotation in Tools/jit (#129806)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored Feb 17, 2025
1 parent cfe4103 commit 422f8e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Tools/jit/_stencils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ class Hole:
def __post_init__(self) -> None:
self.func = _PATCH_FUNCS[self.kind]

def fold(self, other: typing.Self, body: bytes) -> typing.Self | None:
def fold(
self,
other: typing.Self,
body: bytes | bytearray,
) -> typing.Self | None:
"""Combine two holes into a single hole, if possible."""
instruction_a = int.from_bytes(
body[self.offset : self.offset + 4], byteorder=sys.byteorder
Expand Down
17 changes: 13 additions & 4 deletions Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _handle_section(self, section: _S, group: _stencils.StencilGroup) -> None:
raise NotImplementedError(type(self))

def _handle_relocation(
self, base: int, relocation: _R, raw: bytes
self, base: int, relocation: _R, raw: bytes | bytearray
) -> _stencils.Hole:
raise NotImplementedError(type(self))

Expand Down Expand Up @@ -257,7 +257,10 @@ def _unwrap_dllimport(self, name: str) -> tuple[_stencils.HoleValue, str | None]
return _stencils.symbol_to_value(name)

def _handle_relocation(
self, base: int, relocation: _schema.COFFRelocation, raw: bytes
self,
base: int,
relocation: _schema.COFFRelocation,
raw: bytes | bytearray,
) -> _stencils.Hole:
match relocation:
case {
Expand Down Expand Up @@ -348,7 +351,10 @@ def _handle_section(
}, section_type

def _handle_relocation(
self, base: int, relocation: _schema.ELFRelocation, raw: bytes
self,
base: int,
relocation: _schema.ELFRelocation,
raw: bytes | bytearray,
) -> _stencils.Hole:
symbol: str | None
match relocation:
Expand Down Expand Up @@ -424,7 +430,10 @@ def _handle_section(
stencil.holes.append(hole)

def _handle_relocation(
self, base: int, relocation: _schema.MachORelocation, raw: bytes
self,
base: int,
relocation: _schema.MachORelocation,
raw: bytes | bytearray,
) -> _stencils.Hole:
symbol: str | None
match relocation:
Expand Down

0 comments on commit 422f8e9

Please sign in to comment.