Skip to content

Commit 1d9d0be

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 45b4091 commit 1d9d0be

31 files changed

+48
-44
lines changed

pygit2/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,10 @@
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,
370+
mode: int | enums.RepositoryInitMode = enums.RepositoryInitMode.SHARED_UMASK,
373371
workdir_path: typing.Optional[str] = None,
374372
description: typing.Optional[str] = None,
375373
template_path: typing.Optional[str] = None,

pygit2/_pygit2.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
from collections.abc import Iterator, Sequence
12
from io import DEFAULT_BUFFER_SIZE, IOBase
23
from pathlib import Path
34
from queue import Queue
45
from threading import Event
5-
from typing import (
6+
from typing import ( # noqa: UP035
67
Generic,
7-
Iterator,
88
Literal,
99
Optional,
10-
Sequence,
1110
Type,
1211
TypedDict,
1312
TypeVar,

pygit2/blame.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
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 collections.abc import Iterator
27+
from typing import TYPE_CHECKING
2728

2829
from ._pygit2 import Oid, Repository, Signature
2930

pygit2/branches.py

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

2626
from __future__ import annotations
2727

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

3031
from ._pygit2 import Branch, Commit, Oid
3132
from .enums import BranchType, ReferenceType

pygit2/callbacks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@
6363
"""
6464

6565
# Standard Library
66+
from collections.abc import Callable, Generator
6667
from contextlib import contextmanager
6768
from functools import wraps
68-
from typing import TYPE_CHECKING, Callable, Generator, Optional, Union
69+
from typing import TYPE_CHECKING, Optional
6970

7071
# pygit2
7172
from ._pygit2 import DiffFile, Oid
@@ -151,7 +152,7 @@ def sideband_progress(self, string: str) -> None:
151152
def credentials(
152153
self,
153154
url: str,
154-
username_from_url: Union[str, None],
155+
username_from_url: str | None,
155156
allowed_types: CredentialType,
156157
) -> _Credentials:
157158
"""

pygit2/config.py

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

26+
from collections.abc import Callable, Iterator
2627
from os import PathLike
2728
from pathlib import Path
28-
from typing import TYPE_CHECKING, Callable, Iterator
29+
from typing import TYPE_CHECKING
2930

3031
try:
3132
from functools import cached_property

pygit2/filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
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 collections.abc import Callable
2727

2828
from ._pygit2 import FilterSource
2929

@@ -58,7 +58,7 @@ class Filter:
5858
def nattrs(cls) -> int:
5959
return len(cls.attributes.split())
6060

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

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
from __future__ import annotations
2727

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

3031
from pygit2 import Oid
3132

pygit2/refspec.py

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

26-
from typing import Callable
26+
from collections.abc import Callable
2727

2828
# Import from pygit2
2929
from .errors import check_error

0 commit comments

Comments
 (0)