Skip to content

Commit eec7ae6

Browse files
committed
Modernize typings
1 parent 3e94d0c commit eec7ae6

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

dissect/xfs/xfs.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import stat
77
from datetime import datetime
88
from functools import lru_cache
9-
from typing import BinaryIO, Iterator, Optional, Union
9+
from typing import BinaryIO, Iterator
1010
from uuid import UUID
1111

1212
from dissect.util import ts
@@ -55,7 +55,7 @@ def __init__(self, fh: BinaryIO):
5555

5656
self.root = self.get_inode(self.sb.sb_rootino)
5757

58-
def get(self, path: Union[int, str], node: Optional[INode] = None) -> INode:
58+
def get(self, path: int | str, node: INode | None = None) -> INode:
5959
if isinstance(path, int):
6060
return self.get_inode(path)
6161

@@ -102,14 +102,14 @@ def walk_extents(self, block: int) -> Iterator[tuple[int, int, int, int]]:
102102
for record in self.walk_large_tree(block, 16, (c_xfs.XFS_BMAP_MAGIC, c_xfs.XFS_BMAP_CRC_MAGIC)):
103103
yield parse_fsblock(record)
104104

105-
def walk_large_tree(self, block: int, leaf_size: int, magic: Optional[list[int]] = None) -> Iterator[bytes]:
105+
def walk_large_tree(self, block: int, leaf_size: int, magic: list[int] | None = None) -> Iterator[bytes]:
106106
self.fh.seek(block * self.block_size)
107107
root = self._lblock_s(self.fh)
108108

109109
yield from self._walk_large_tree(root, leaf_size, magic)
110110

111111
def walk_small_tree(
112-
self, block: int, agnum: int, leaf_size: int, magic: Optional[list[int]] = None
112+
self, block: int, agnum: int, leaf_size: int, magic: list[int] | None = None
113113
) -> Iterator[bytes]:
114114
block = agnum * self.sb.sb_agblocks + block
115115
self.fh.seek(block * self.block_size)
@@ -122,7 +122,7 @@ def _walk_small_tree(
122122
node: c_xfs.xfs_btree_sblock | c_xfs.xfs_btree_sblock_crc,
123123
leaf_size: int,
124124
agnum: int,
125-
magic: Optional[list[int]] = None,
125+
magic: list[int] | None = None,
126126
) -> Iterator[bytes]:
127127
fh = self.fh
128128
if magic and node.bb_magic not in magic:
@@ -148,7 +148,7 @@ def _walk_large_tree(
148148
self,
149149
node: c_xfs.xfs_btree_lblock | c_xfs.xfs_btree_lblock_crc,
150150
leaf_size: int,
151-
magic: Optional[list[int]] = None,
151+
magic: list[int] | None = None,
152152
) -> Iterator[bytes]:
153153
fh = self.fh
154154
if magic and node.bb_magic not in magic:
@@ -210,9 +210,9 @@ def __init__(self, xfs: XFS, fh: BinaryIO, num: int):
210210
def get_inode(
211211
self,
212212
inum: int,
213-
filename: Optional[str] = None,
214-
filetype: Optional[int] = None,
215-
parent: Optional[INode] = None,
213+
filename: str | None = None,
214+
filetype: int | None = None,
215+
parent: INode | None = None,
216216
lazy: bool = False,
217217
) -> INode:
218218
inode = INode(self, inum, filename, filetype, parent=parent)
@@ -230,7 +230,7 @@ def walk_extents(self, fsb: int) -> Iterator[tuple[int, int, int, int]]:
230230
def walk_agi(self) -> Iterator[c_xfs.xfs_inobt_rec]:
231231
yield from self.xfs.walk_agi(self.agi.agi_root, self.num)
232232

233-
def walk_tree(self, fsb: int, magic: Optional[list[int]] = None, small: bool = False):
233+
def walk_tree(self, fsb: int, magic: list[int] | None = None, small: bool = False):
234234
agnum, blknum = fsb_to_bb(fsb, self.sb.sb_agblklog)
235235
block = agnum * self.xfs.sb.sb_agblocks + blknum
236236

@@ -245,9 +245,9 @@ def __init__(
245245
self,
246246
ag: AllocationGroup,
247247
inum: int,
248-
filename: Optional[str] = None,
249-
filetype: Optional[int] = None,
250-
parent: Optional[INode] = None,
248+
filename: str | None = None,
249+
filetype: int | None = None,
250+
parent: INode | None = None,
251251
):
252252
self.ag = ag
253253
self.xfs = ag.xfs
@@ -517,7 +517,7 @@ def attrfork(self) -> BinaryIO:
517517

518518
return RangeStream(self._buf, offset, size)
519519

520-
def dataruns(self) -> list[tuple[Optional[int], int]]:
520+
def dataruns(self) -> list[tuple[int | None, int]]:
521521
if not self._runlist:
522522
runs = []
523523
run_offset = 0

0 commit comments

Comments
 (0)