| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,12 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | 5 | import os | |
| 6 | 6 | import sys | |
| 7 | - from typing import Union, Any | ||
| 7 | + from typing import Dict, Union, Any | ||
| 8 | 8 | ||
| 9 | 9 | if sys.version_info[:2] >= (3, 8): | |
| 10 | - from typing import Final, Literal, SupportsIndex # noqa: F401 | ||
| 10 | + from typing import Final, Literal, SupportsIndex, TypedDict # noqa: F401 | ||
| 11 | 11 | else: | |
| 12 | - from typing_extensions import Final, Literal, SupportsIndex # noqa: F401 | ||
| 12 | + from typing_extensions import Final, Literal, SupportsIndex, TypedDict # noqa: F401 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | if sys.version_info[:2] < (3, 9): | |
@@ -22,3 +22,21 @@ | |||
| 22 | 22 | TBD = Any | |
| 23 | 23 | ||
| 24 | 24 | Lit_config_levels = Literal['system', 'global', 'user', 'repository'] | |
| 25 | + | ||
| 26 | + | ||
| 27 | + class Files_TD(TypedDict): | ||
| 28 | + insertions: int | ||
| 29 | + deletions: int | ||
| 30 | + lines: int | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + class Total_TD(TypedDict): | ||
| 34 | + insertions: int | ||
| 35 | + deletions: int | ||
| 36 | + lines: int | ||
| 37 | + files: int | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + class HSH_TD(TypedDict): | ||
| 41 | + total: Total_TD | ||
| 42 | + files: Dict[str, Files_TD] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,7 @@ | |||
| 32 | 32 | from git.repo.base import Repo | |
| 33 | 33 | from git.config import GitConfigParser, SectionConstraint | |
| 34 | 34 | ||
| 35 | - from .types import PathLike, TBD, Literal, SupportsIndex | ||
| 35 | + from .types import PathLike, Literal, SupportsIndex, HSH_TD, Files_TD | ||
| 36 | 36 | ||
| 37 | 37 | # --------------------------------------------------------------------- | |
| 38 | 38 | ||
@@ -746,7 +746,9 @@ class Stats(object): | |||
| 746 | 746 | files = number of changed files as int""" | |
| 747 | 747 | __slots__ = ("total", "files") | |
| 748 | 748 | ||
| 749 | - def __init__(self, total: Dict[str, Dict[str, int]], files: Dict[str, Dict[str, int]]): | ||
| 749 | + from git.types import Total_TD, Files_TD | ||
| 750 | + | ||
| 751 | + def __init__(self, total: Total_TD, files: Dict[str, Files_TD]): | ||
| 750 | 752 | self.total = total | |
| 751 | 753 | self.files = files | |
| 752 | 754 | ||
@@ -756,13 +758,12 @@ def _list_from_string(cls, repo: 'Repo', text: str) -> 'Stats': | |||
| 756 | 758 | ||
| 757 | 759 | :return: git.Stat""" | |
| 758 | 760 | ||
| 759 | - # hsh: Dict[str, Dict[str, Union[int, Dict[str, int]]]] | ||
| 760 | - hsh: Dict[str, Dict[str, TBD]] = {'total': {'insertions': 0, | ||
| 761 | - 'deletions': 0, | ||
| 762 | - 'lines': 0, | ||
| 763 | - 'files': 0}, | ||
| 764 | - 'files': {} | ||
| 765 | - } # need typeddict? | ||
| 761 | + hsh: HSH_TD = {'total': {'insertions': 0, | ||
| 762 | + 'deletions': 0, | ||
| 763 | + 'lines': 0, | ||
| 764 | + 'files': 0}, | ||
| 765 | + 'files': {} | ||
| 766 | + } | ||
| 766 | 767 | for line in text.splitlines(): | |
| 767 | 768 | (raw_insertions, raw_deletions, filename) = line.split("\t") | |
| 768 | 769 | insertions = raw_insertions != '-' and int(raw_insertions) or 0 | |
@@ -771,9 +772,9 @@ def _list_from_string(cls, repo: 'Repo', text: str) -> 'Stats': | |||
| 771 | 772 | hsh['total']['deletions'] += deletions | |
| 772 | 773 | hsh['total']['lines'] += insertions + deletions | |
| 773 | 774 | hsh['total']['files'] += 1 | |
| 774 | - files_dict = {'insertions': insertions, | ||
| 775 | - 'deletions': deletions, | ||
| 776 | - 'lines': insertions + deletions} | ||
| 775 | + files_dict: Files_TD = {'insertions': insertions, | ||
| 776 | + 'deletions': deletions, | ||
| 777 | + 'lines': insertions + deletions} | ||
| 777 | 778 | hsh['files'][filename.strip()] = files_dict | |
| 778 | 779 | return Stats(hsh['total'], hsh['files']) | |
| 779 | 780 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments