summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/types.py24
-rw-r--r--git/util.py25
-rw-r--r--t.py28
3 files changed, 34 insertions, 43 deletions
diff --git a/git/types.py b/git/types.py
index a410cb36..8c431e53 100644
--- a/git/types.py
+++ b/git/types.py
@@ -4,12 +4,12 @@
import os
import sys
-from typing import Union, Any
+from typing import Dict, Union, Any
if sys.version_info[:2] >= (3, 8):
- from typing import Final, Literal, SupportsIndex # noqa: F401
+ from typing import Final, Literal, SupportsIndex, TypedDict # noqa: F401
else:
- from typing_extensions import Final, Literal, SupportsIndex # noqa: F401
+ from typing_extensions import Final, Literal, SupportsIndex, TypedDict # noqa: F401
if sys.version_info[:2] < (3, 9):
@@ -22,3 +22,21 @@ elif sys.version_info[:2] >= (3, 9):
TBD = Any
Lit_config_levels = Literal['system', 'global', 'user', 'repository']
+
+
+class Files_TD(TypedDict):
+ insertions: int
+ deletions: int
+ lines: int
+
+
+class Total_TD(TypedDict):
+ insertions: int
+ deletions: int
+ lines: int
+ files: int
+
+
+class HSH_TD(TypedDict):
+ total: Total_TD
+ files: Dict[str, Files_TD]
diff --git a/git/util.py b/git/util.py
index 245f45d1..0783918d 100644
--- a/git/util.py
+++ b/git/util.py
@@ -32,7 +32,7 @@ if TYPE_CHECKING:
from git.repo.base import Repo
from git.config import GitConfigParser, SectionConstraint
-from .types import PathLike, TBD, Literal, SupportsIndex
+from .types import PathLike, Literal, SupportsIndex, HSH_TD, Files_TD
# ---------------------------------------------------------------------
@@ -746,7 +746,9 @@ class Stats(object):
files = number of changed files as int"""
__slots__ = ("total", "files")
- def __init__(self, total: Dict[str, Dict[str, int]], files: Dict[str, Dict[str, int]]):
+ from git.types import Total_TD, Files_TD
+
+ def __init__(self, total: Total_TD, files: Dict[str, Files_TD]):
self.total = total
self.files = files
@@ -756,13 +758,12 @@ class Stats(object):
:return: git.Stat"""
- # hsh: Dict[str, Dict[str, Union[int, Dict[str, int]]]]
- hsh: Dict[str, Dict[str, TBD]] = {'total': {'insertions': 0,
- 'deletions': 0,
- 'lines': 0,
- 'files': 0},
- 'files': {}
- } # need typeddict?
+ hsh: HSH_TD = {'total': {'insertions': 0,
+ 'deletions': 0,
+ 'lines': 0,
+ 'files': 0},
+ 'files': {}
+ }
for line in text.splitlines():
(raw_insertions, raw_deletions, filename) = line.split("\t")
insertions = raw_insertions != '-' and int(raw_insertions) or 0
@@ -771,9 +772,9 @@ class Stats(object):
hsh['total']['deletions'] += deletions
hsh['total']['lines'] += insertions + deletions
hsh['total']['files'] += 1
- files_dict = {'insertions': insertions,
- 'deletions': deletions,
- 'lines': insertions + deletions}
+ files_dict: Files_TD = {'insertions': insertions,
+ 'deletions': deletions,
+ 'lines': insertions + deletions}
hsh['files'][filename.strip()] = files_dict
return Stats(hsh['total'], hsh['files'])
diff --git a/t.py b/t.py
deleted file mode 100644
index 215c2667..00000000
--- a/t.py
+++ /dev/null
@@ -1,28 +0,0 @@
-import warnings
-
-
-class Watcher(type):
- def __init__(cls, name, bases, clsdict):
- for base in bases:
- if type(base) == Watcher:
- warnings.warn(f"GitPython Iterable subclassed by {name}. "
- "Iterable is deprecated due to naming clash, "
- "Use IterableObj instead \n",
- DeprecationWarning,
- stacklevel=2)
-
-
-class SuperClass(metaclass=Watcher):
- pass
-
-
-class SubClass0(SuperClass):
- pass
-
-
-class SubClass1(SuperClass):
- print("test")
-
-
-class normo():
- print("wooo")