Skip to content

Commit bd96d77

Browse files
committed
Use modern python syntax for types and others
Since the minium declared python version is 3.10 we don't need the Union and Option and many type imports should be done from collections.abc. so i ran `fd --extension py --type f --exec pyupgrade --py310-plus` on the repo. All changes are automated, i.e. no manual edit.
1 parent 2a57752 commit bd96d77

34 files changed

+121
-102
lines changed

pygit2/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,17 @@
364364

365365

366366
def init_repository(
367-
path: typing.Union[str, bytes, os.PathLike, None],
367+
path: str | bytes | os.PathLike | None,
368368
bare: bool = False,
369369
flags: enums.RepositoryInitFlag = enums.RepositoryInitFlag.MKPATH,
370-
mode: typing.Union[
371-
int, enums.RepositoryInitMode
372-
] = enums.RepositoryInitMode.SHARED_UMASK,
373-
workdir_path: typing.Optional[str] = None,
374-
description: typing.Optional[str] = None,
375-
template_path: typing.Optional[str] = None,
376-
initial_head: typing.Optional[str] = None,
377-
origin_url: typing.Optional[str] = None,
370+
mode: (
371+
int | enums.RepositoryInitMode
372+
) = enums.RepositoryInitMode.SHARED_UMASK,
373+
workdir_path: str | None = None,
374+
description: str | None = None,
375+
template_path: str | None = None,
376+
initial_head: str | None = None,
377+
origin_url: str | None = None,
378378
) -> Repository:
379379
"""
380380
Creates a new Git repository in the given *path*.

pygit2/blame.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
2424
# Boston, MA 02110-1301, USA.
2525

26-
from typing import TYPE_CHECKING, Iterator
26+
from typing import TYPE_CHECKING
27+
28+
from collections.abc import Iterator
2729

2830
from ._pygit2 import Oid, Repository, Signature
2931

pygit2/blob.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class _BlobIO(io.RawIOBase):
2020
def __init__(
2121
self,
2222
blob: Blob,
23-
as_path: Optional[str] = None,
23+
as_path: str | None = None,
2424
flags: BlobFilter = BlobFilter.CHECK_FOR_BINARY,
25-
commit_id: Optional[Oid] = None,
25+
commit_id: Oid | None = None,
2626
):
2727
super().__init__()
2828
self._blob = blob
29-
self._queue: Optional[Queue] = Queue(maxsize=1)
29+
self._queue: Queue | None = Queue(maxsize=1)
3030
self._ready = threading.Event()
3131
self._writer_closed = threading.Event()
32-
self._chunk: Optional[bytes] = None
32+
self._chunk: bytes | None = None
3333
self._thread = threading.Thread(
3434
target=self._blob._write_to_queue,
3535
args=(self._queue, self._ready, self._writer_closed),
@@ -127,9 +127,9 @@ class BlobIO(io.BufferedReader, AbstractContextManager):
127127
def __init__(
128128
self,
129129
blob: Blob,
130-
as_path: Optional[str] = None,
130+
as_path: str | None = None,
131131
flags: BlobFilter = BlobFilter.CHECK_FOR_BINARY,
132-
commit_id: Optional[Oid] = None,
132+
commit_id: Oid | None = None,
133133
):
134134
"""Wrap the specified blob.
135135

pygit2/branches.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
from __future__ import annotations
2727

28-
from typing import TYPE_CHECKING, Iterator
28+
from typing import TYPE_CHECKING
29+
30+
from collections.abc import Iterator
2931

3032
from ._pygit2 import Branch, Commit, Oid
3133
from .enums import BranchType, ReferenceType
@@ -36,8 +38,8 @@
3638

3739

3840
class Branches:
39-
local: 'Branches'
40-
remote: 'Branches'
41+
local: Branches
42+
remote: Branches
4143

4244
def __init__(
4345
self,
@@ -100,7 +102,7 @@ def _valid(self, branch: Branch) -> bool:
100102
or self._repository.descendant_of(branch_direct.target, self._commit)
101103
)
102104

103-
def with_commit(self, commit: Commit | Oid | str | None) -> 'Branches':
105+
def with_commit(self, commit: Commit | Oid | str | None) -> Branches:
104106
assert self._commit is None
105107
return Branches(self._repository, self._flag, commit)
106108

pygit2/callbacks.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@
6565
# Standard Library
6666
from contextlib import contextmanager
6767
from functools import wraps
68-
from typing import TYPE_CHECKING, Callable, Generator, Optional, Union
68+
from typing import TYPE_CHECKING, Optional, Union
69+
70+
from collections.abc import Callable, Generator
6971

7072
# pygit2
7173
from ._pygit2 import DiffFile, Oid
@@ -151,7 +153,7 @@ def sideband_progress(self, string: str) -> None:
151153
def credentials(
152154
self,
153155
url: str,
154-
username_from_url: Union[str, None],
156+
username_from_url: str | None,
155157
allowed_types: CredentialType,
156158
) -> _Credentials:
157159
"""
@@ -298,9 +300,9 @@ def checkout_notify(
298300
self,
299301
why: CheckoutNotify,
300302
path: str,
301-
baseline: Optional[DiffFile],
302-
target: Optional[DiffFile],
303-
workdir: Optional[DiffFile],
303+
baseline: DiffFile | None,
304+
target: DiffFile | None,
305+
workdir: DiffFile | None,
304306
) -> None:
305307
"""
306308
Checkout will invoke an optional notification callback for

pygit2/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
from os import PathLike
2727
from pathlib import Path
28-
from typing import TYPE_CHECKING, Callable, Iterator
28+
from typing import TYPE_CHECKING
29+
30+
from collections.abc import Callable, Iterator
2931

3032
try:
3133
from functools import cached_property

pygit2/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from ._pygit2 import GitError
2828
from .ffi import C, ffi
2929

30-
value_errors = set([C.GIT_EEXISTS, C.GIT_EINVALIDSPEC, C.GIT_EAMBIGUOUS])
30+
value_errors = {C.GIT_EEXISTS, C.GIT_EINVALIDSPEC, C.GIT_EAMBIGUOUS}
3131

3232

3333
def check_error(err, io=False):
@@ -51,7 +51,7 @@ def check_error(err, io=False):
5151

5252
if err == C.GIT_ENOTFOUND:
5353
if io:
54-
raise IOError(message)
54+
raise OSError(message)
5555

5656
raise KeyError(message)
5757

pygit2/filter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
2424
# Boston, MA 02110-1301, USA.
2525

26-
from typing import Callable, List, Optional
26+
from typing import List, Optional
27+
28+
from collections.abc import Callable
2729

2830
from ._pygit2 import FilterSource
2931

@@ -58,7 +60,7 @@ class Filter:
5860
def nattrs(cls) -> int:
5961
return len(cls.attributes.split())
6062

61-
def check(self, src: FilterSource, attr_values: List[Optional[str]]) -> None:
63+
def check(self, src: FilterSource, attr_values: list[str | None]) -> None:
6264
"""
6365
Check whether this filter should be applied to the given source.
6466

pygit2/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ class MergeFileResult:
392392
automergeable: bool
393393
'True if the output was automerged, false if the output contains conflict markers'
394394

395-
path: typing.Union[str, None, PathLike[str]]
395+
path: str | None | PathLike[str]
396396
'The path that the resultant merge file should use, or None if a filename conflict would occur'
397397

398398
mode: FileMode

pygit2/references.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
from __future__ import annotations
2727

28-
from typing import TYPE_CHECKING, Iterator
28+
from typing import TYPE_CHECKING
29+
30+
from collections.abc import Iterator
2931

3032
from pygit2 import Oid
3133

@@ -41,10 +43,10 @@ class References:
4143
def __init__(self, repository: BaseRepository) -> None:
4244
self._repository = repository
4345

44-
def __getitem__(self, name: str) -> 'Reference':
46+
def __getitem__(self, name: str) -> Reference:
4547
return self._repository.lookup_reference(name)
4648

47-
def get(self, key: str) -> 'Reference' | None:
49+
def get(self, key: str) -> Reference | None:
4850
try:
4951
return self[key]
5052
except KeyError:
@@ -61,7 +63,7 @@ def __iter__(self) -> Iterator[str]:
6163

6264
def iterator(
6365
self, references_return_type: ReferenceFilter = ReferenceFilter.ALL
64-
) -> Iterator['Reference']:
66+
) -> Iterator[Reference]:
6567
"""Creates a new iterator and fetches references for a given repository.
6668
6769
Can also filter and pass all refs or only branches or only tags.
@@ -93,7 +95,7 @@ def iterator(
9395
else:
9496
return
9597

96-
def create(self, name: str, target: Oid | str, force: bool = False) -> 'Reference':
98+
def create(self, name: str, target: Oid | str, force: bool = False) -> Reference:
9799
return self._repository.create_reference(name, target, force)
98100

99101
def delete(self, name: str) -> None:
@@ -103,7 +105,7 @@ def __contains__(self, name: str) -> bool:
103105
return self.get(name) is not None
104106

105107
@property
106-
def objects(self) -> list['Reference']:
108+
def objects(self) -> list[Reference]:
107109
return self._repository.listall_reference_objects()
108110

109111
def compress(self) -> None:

0 commit comments

Comments
 (0)