Skip to content

Commit

Permalink
Fix python 3.9 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Jul 21, 2023
1 parent b11d9db commit 244f485
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions dulwich/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class Stage(Enum):
@dataclass
class SerializedIndexEntry:
name: bytes
ctime: int | float | Tuple[int, int]
mtime: int | float | Tuple[int, int]
ctime: Union[int, float, Tuple[int, int]]
mtime: Union[int, float, Tuple[int, int]]
dev: int
ino: int
mode: int
Expand All @@ -100,8 +100,8 @@ def stage(self) -> Stage:

@dataclass
class IndexEntry:
ctime: int | float | Tuple[int, int]
mtime: int | float | Tuple[int, int]
ctime: Union[int, float, Tuple[int, int]]
mtime: Union[int, float, Tuple[int, int]]
dev: int
ino: int
mode: int
Expand Down Expand Up @@ -312,14 +312,14 @@ def read_index(f: BinaryIO) -> Iterator[SerializedIndexEntry]:
yield read_cache_entry(f, version)


def read_index_dict(f) -> Dict[bytes, IndexEntry | ConflictedIndexEntry]:
def read_index_dict(f) -> Dict[bytes, Union[IndexEntry, ConflictedIndexEntry]]:
"""Read an index file and return it as a dictionary.
Dict Key is tuple of path and stage number, as
path alone is not unique
Args:
f: File object to read fromls.
"""
ret: Dict[bytes, IndexEntry | ConflictedIndexEntry] = {}
ret: Dict[bytes, Union[IndexEntry, ConflictedIndexEntry]] = {}
for entry in read_index(f):
stage = entry.stage()
if stage == Stage.NORMAL:
Expand Down Expand Up @@ -355,7 +355,7 @@ def write_index(f: BinaryIO, entries: List[SerializedIndexEntry], version: Optio

def write_index_dict(
f: BinaryIO,
entries: Dict[bytes, IndexEntry | ConflictedIndexEntry],
entries: Dict[bytes, Union[IndexEntry, ConflictedIndexEntry]],
version: Optional[int] = None,
) -> None:
"""Write an index file based on the contents of a dictionary.
Expand Down Expand Up @@ -402,7 +402,7 @@ def cleanup_mode(mode: int) -> int:
class Index:
"""A Git Index file."""

_byname: Dict[bytes, IndexEntry | ConflictedIndexEntry]
_byname: Dict[bytes, Union[IndexEntry, ConflictedIndexEntry]]

def __init__(self, filename: Union[bytes, str], read=True) -> None:
"""Create an index object associated with the given filename.
Expand Down Expand Up @@ -452,7 +452,7 @@ def __len__(self) -> int:
"""Number of entries in this index file."""
return len(self._byname)

def __getitem__(self, key: bytes) -> IndexEntry | ConflictedIndexEntry:
def __getitem__(self, key: bytes) -> Union[IndexEntry, ConflictedIndexEntry]:
"""Retrieve entry by relative path and stage.
Returns: tuple with (ctime, mtime, dev, ino, mode, uid, gid, size, sha,
Expand Down Expand Up @@ -499,20 +499,20 @@ def clear(self):
"""Remove all contents from this index."""
self._byname = {}

def __setitem__(self, name: bytes, value: IndexEntry | ConflictedIndexEntry) -> None:
def __setitem__(self, name: bytes, value: Union[IndexEntry, ConflictedIndexEntry]) -> None:
assert isinstance(name, bytes)
self._byname[name] = value

def __delitem__(self, name: bytes) -> None:
del self._byname[name]

def iteritems(self) -> Iterator[Tuple[bytes, IndexEntry | ConflictedIndexEntry]]:
def iteritems(self) -> Iterator[Tuple[bytes, Union[IndexEntry, ConflictedIndexEntry]]]:
return iter(self._byname.items())

def items(self) -> Iterator[Tuple[bytes, IndexEntry | ConflictedIndexEntry]]:
def items(self) -> Iterator[Tuple[bytes, Union[IndexEntry, ConflictedIndexEntry]]]:
return iter(self._byname.items())

def update(self, entries: Dict[bytes, IndexEntry | ConflictedIndexEntry]):
def update(self, entries: Dict[bytes, Union[IndexEntry, ConflictedIndexEntry]]):
for key, value in entries.items():
self[key] = value

Expand Down

0 comments on commit 244f485

Please sign in to comment.