Skip to content

Commit

Permalink
modernize type anno
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Feb 8, 2021
1 parent 5640f14 commit c494fb2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/gitutils/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
https://stackoverflow.com/a/45028375
"""

from __future__ import annotations
import argparse
import typing as T
from pathlib import Path
import asyncio
import logging
Expand All @@ -24,7 +24,7 @@
SWITCH = ["checkout"] # Git < 2.23


async def different_branch(main: T.Sequence[str], path: Path) -> T.Tuple[str, str]:
async def different_branch(main: list[str], path: Path) -> tuple[str, str]:
"""
does branch not match specified name
Expand Down Expand Up @@ -62,7 +62,7 @@ async def different_branch(main: T.Sequence[str], path: Path) -> T.Tuple[str, st
return None


async def git_branch(branch: T.Sequence[str], path: Path) -> T.List[T.Tuple[str, str]]:
async def git_branch(branch: list[str], path: Path) -> list[tuple[str, str]]:

different = []
for r in asyncio.as_completed([different_branch(branch, d) for d in gitdirs(path)]):
Expand Down Expand Up @@ -96,8 +96,8 @@ def branch_switch(path: Path, old_branch: str, new_branch: str):
stderr = ret.stderr.strip()
if stderr in {
f"fatal: invalid reference: {new_branch}", # switch
f"error: pathspec '{new_branch}' did not match any file(s) known to git",
}: # checkout
f"error: pathspec '{new_branch}' did not match any file(s) known to git", # checkout
}:
continue
else:
raise ValueError(
Expand Down
6 changes: 3 additions & 3 deletions src/gitutils/email.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
operations for Git author attributions
"""

from __future__ import annotations
from pathlib import Path
import typing as T
import collections
Expand All @@ -10,9 +12,7 @@
from .git import gitdirs, GITEXE, TIMEOUT


def gitemail(
path: Path, exclude: str = None
) -> T.Iterator[T.Tuple[Path, T.List[T.Tuple[str, int]]]]:
def gitemail(path: Path, exclude: str = None) -> T.Iterator[tuple[Path, list[tuple[str, int]]]]:
"""
returns email addresses of everyone who ever made a Git commit in this repo.
Expand Down
4 changes: 3 additions & 1 deletion src/gitutils/git.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Git utilities: focused on speed for very large numbers of Git repos
"""

from __future__ import annotations
from pathlib import Path
import subprocess
import typing
Expand Down Expand Up @@ -77,7 +79,7 @@ def baddir(path: Path) -> bool:
return bad


def listchanged(path: Path) -> typing.List[str]:
def listchanged(path: Path) -> list[str]:
"""very quick check if any files were modified in this Git repo
Parameters
Expand Down
4 changes: 2 additions & 2 deletions src/gitutils/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
Git fetch / pull functions
"""

from __future__ import annotations
import argparse
import asyncio
import subprocess
import logging
from pathlib import Path
import typing as T

from . import _log
from .git import GITEXE, gitdirs
Expand Down Expand Up @@ -63,7 +63,7 @@ async def fetchpull(mode: str, path: Path) -> Path:
return None


async def git_pullfetch(mode: str, path: Path) -> T.List[Path]:
async def git_pullfetch(mode: str, path: Path) -> list[Path]:

failed = []
for r in asyncio.as_completed([fetchpull(mode, d) for d in gitdirs(path)]):
Expand Down
6 changes: 3 additions & 3 deletions src/gitutils/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
DOES NOT WORK git log --branches --not --remotes # check for uncommitted branches
"""

from __future__ import annotations
import argparse
import asyncio
import subprocess
import logging
from pathlib import Path
import typing as T

from . import _log
from .git import gitdirs, GITEXE, MAGENTA, BLACK, TIMEOUT
Expand Down Expand Up @@ -54,7 +54,7 @@ def git_porcelain(path: Path) -> bool:
return not ret.stdout


async def _git_status(path: Path) -> T.Tuple[str, str]:
async def _git_status(path: Path) -> tuple[str, str]:
"""
Notes which Git repos have local changes that haven't been pushed to remote
Expand Down Expand Up @@ -103,7 +103,7 @@ async def _git_status(path: Path) -> T.Tuple[str, str]:
return None


async def git_status(path: Path, verbose: bool = False) -> T.List[str]:
async def git_status(path: Path, verbose: bool = False) -> list[str]:

c = MAGENTA if verbose else ""

Expand Down

0 comments on commit c494fb2

Please sign in to comment.