Skip to content

Commit 886cd60

Browse files
committed
Fix linting for python3.10
1 parent 31712eb commit 886cd60

8 files changed

Lines changed: 23 additions & 13 deletions

File tree

dissect/executable/elf/elf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io
44
from functools import cached_property, lru_cache
55
from operator import itemgetter
6-
from typing import TYPE_CHECKING, BinaryIO, Callable, Generic, TypeVar
6+
from typing import TYPE_CHECKING, BinaryIO, Generic, TypeVar
77

88
from dissect.executable.elf.c_elf import (
99
SHN,
@@ -19,7 +19,7 @@
1919
from dissect.executable.exception import InvalidSignatureError
2020

2121
if TYPE_CHECKING:
22-
from collections.abc import Iterator
22+
from collections.abc import Callable, Iterator
2323

2424
from dissect.cstruct import cstruct
2525

dissect/executable/pe/c_pe.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Generated by cstruct-stubgen
2-
from typing import BinaryIO, Literal, overload
2+
from typing import BinaryIO, Literal, TypeAlias, overload
33

44
import dissect.cstruct as __cs__
5-
from typing_extensions import TypeAlias
65

76
class _c_pe(__cs__.cstruct):
87
IMAGE_DOS_SIGNATURE: Literal[23117] = ...

dissect/executable/pe/directory/debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def signature(self) -> UUID | int | None:
123123
if isinstance(self.info, c_pe.CV_INFO_PDB20):
124124
return self.info.Signature
125125

126-
if isinstance(self.info, (c_pe.CV_INFO_PDB70, c_pe.CV_INFO_MTOC)):
126+
if isinstance(self.info, c_pe.CV_INFO_PDB70 | c_pe.CV_INFO_MTOC):
127127
return UUID(bytes_le=self.info.Signature)
128128

129129
return None

dissect/executable/pe/directory/delay_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def functions(self) -> list[DelayImportFunction]:
126126
return [
127127
DelayImportFunction(self, name_thunk, address_thunk, bound_thunk, unload_thunk)
128128
for name_thunk, address_thunk, bound_thunk, unload_thunk in zip(
129-
name_table, address_table, bound_table, unload_table
129+
name_table, address_table, bound_table, unload_table, strict=False
130130
)
131131
]
132132

dissect/executable/pe/directory/export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def functions(self) -> list[ExportFunction]:
7979
self.pe.vfh.seek(self.header.AddressOfNameOrdinals)
8080
ordinals = c_pe.USHORT[self.header.NumberOfNames](self.pe.vfh)
8181

82-
for name_ptr, ordinal in zip(names, ordinals):
82+
for name_ptr, ordinal in zip(names, ordinals, strict=False):
8383
self.pe.vfh.seek(name_ptr)
8484
name = c_pe.CHAR[None](self.pe.vfh).decode()
8585

dissect/executable/pe/directory/imports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def functions(self) -> list[ImportFunction]:
108108

109109
return [
110110
ImportFunction(self, lookup_thunk, address_thunk)
111-
for lookup_thunk, address_thunk in zip(lookup_table, address_table)
111+
for lookup_thunk, address_thunk in zip(lookup_table, address_table, strict=False)
112112
]
113113

114114
@cached_property

dissect/executable/pe/directory/resource.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from functools import cached_property
44
from io import BytesIO
5-
from typing import TYPE_CHECKING, Any, BinaryIO, Union
5+
from typing import TYPE_CHECKING, Any, BinaryIO
66

77
from dissect.util.ts import from_unix, wintimestamp
88

@@ -57,13 +57,13 @@ def __getitem__(self, idx: int | str | c_pe.RT) -> list[Resource] | None:
5757
if isinstance(idx, int):
5858
return self.resources[idx]
5959

60-
if isinstance(idx, (str, c_pe.RT)):
60+
if isinstance(idx, str | c_pe.RT):
6161
return self.get(idx)
6262

6363
raise TypeError(f"ResourceDirectory indices must be int, str or RT enum members, not {type(idx).__name__}")
6464

6565
def __contains__(self, idx: str | c_pe.RT) -> bool:
66-
if isinstance(idx, (str, c_pe.RT)):
66+
if isinstance(idx, str | c_pe.RT):
6767
return self.get(idx) is not None
6868

6969
return False
@@ -108,7 +108,7 @@ def find(self, type: int | str | c_pe.RT, name: str | int) -> Resource | None:
108108
if isinstance(name, str):
109109
name = TAG_TO_LCID.get(name, name)
110110

111-
if isinstance(name, (int, c_pe.RT)) and (entry := root.get(name)) is not None:
111+
if isinstance(name, int | c_pe.RT) and (entry := root.get(name)) is not None:
112112
return Resource(type, name, entry)
113113

114114
raise KeyError(f"Resource with type {type.name!r} and name {name!r} not found")
@@ -268,7 +268,7 @@ def vs_version_info(self, language: str | int | None = None) -> dict | None:
268268
if len(version) != 1:
269269
raise ValueError(f"Expected exactly one version resource, found {len(version)}")
270270

271-
_Node: TypeAlias = tuple[str, Union[str, bytes, None], list["_Node"]]
271+
_Node: TypeAlias = tuple[str, str | bytes | None, list["_Node"]]
272272

273273
def _parse_lvt(fh: BinaryIO) -> _Node | None:
274274
start = fh.tell()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Thoughts
2+
3+
An idea to just pass `fh` to the Directories?
4+
An idea to pass `is_64bit()` to Directories ... etc
5+
6+
Law of demeter. If I want this, but see no other solution, I will just mention it.
7+
8+
Feels like the PE itself doesn't need to be there
9+
10+
11+

0 commit comments

Comments
 (0)