| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,14 +40,15 @@ | |||
| 40 | 40 | from io import BytesIO | |
| 41 | 41 | ||
| 42 | 42 | T_ConfigParser = TypeVar('T_ConfigParser', bound='GitConfigParser') | |
| 43 | + T_OMD_value = TypeVar('T_OMD_value', str, bytes, int, float, bool) | ||
| 43 | 44 | ||
| 44 | 45 | if sys.version_info[:3] < (3, 7, 2): | |
| 45 | 46 | # typing.Ordereddict not added until py 3.7.2 | |
| 46 | 47 | from collections import OrderedDict # type: ignore # until 3.6 dropped | |
| 47 | 48 | OrderedDict_OMD = OrderedDict # type: ignore # until 3.6 dropped | |
| 48 | 49 | else: | |
| 49 | 50 | from typing import OrderedDict # type: ignore # until 3.6 dropped | |
| 50 | - OrderedDict_OMD = OrderedDict[str, List[_T]] # type: ignore[assignment, misc] | ||
| 51 | + OrderedDict_OMD = OrderedDict[str, List[T_OMD_value]] # type: ignore[assignment, misc] | ||
| 51 | 52 | ||
| 52 | 53 | # ------------------------------------------------------------- | |
| 53 | 54 | ||
@@ -97,23 +98,23 @@ def __new__(cls, name: str, bases: TBD, clsdict: Dict[str, Any]) -> TBD: | |||
| 97 | 98 | return new_type | |
| 98 | 99 | ||
| 99 | 100 | ||
| 100 | - def needs_values(func: Callable) -> Callable: | ||
| 101 | + def needs_values(func: Callable[..., _T]) -> Callable[..., _T]: | ||
| 101 | 102 | """Returns method assuring we read values (on demand) before we try to access them""" | |
| 102 | 103 | ||
| 103 | 104 | @wraps(func) | |
| 104 | - def assure_data_present(self, *args: Any, **kwargs: Any) -> Any: | ||
| 105 | + def assure_data_present(self: GitConfigParser, *args: Any, **kwargs: Any) -> _T: | ||
| 105 | 106 | self.read() | |
| 106 | 107 | return func(self, *args, **kwargs) | |
| 107 | 108 | # END wrapper method | |
| 108 | 109 | return assure_data_present | |
| 109 | 110 | ||
| 110 | 111 | ||
| 111 | - def set_dirty_and_flush_changes(non_const_func: Callable) -> Callable: | ||
| 112 | + def set_dirty_and_flush_changes(non_const_func: Callable[..., _T]) -> Callable[..., _T]: | ||
| 112 | 113 | """Return method that checks whether given non constant function may be called. | |
| 113 | 114 | If so, the instance will be set dirty. | |
| 114 | 115 | Additionally, we flush the changes right to disk""" | |
| 115 | 116 | ||
| 116 | - def flush_changes(self, *args: Any, **kwargs: Any) -> Any: | ||
| 117 | + def flush_changes(self: GitConfigParser, *args: Any, **kwargs: Any) -> _T: | ||
| 117 | 118 | rval = non_const_func(self, *args, **kwargs) | |
| 118 | 119 | self._dirty = True | |
| 119 | 120 | self.write() | |
@@ -356,7 +357,7 @@ def __enter__(self) -> 'GitConfigParser': | |||
| 356 | 357 | self._acquire_lock() | |
| 357 | 358 | return self | |
| 358 | 359 | ||
| 359 | - def __exit__(self, exception_type, exception_value, traceback) -> None: | ||
| 360 | + def __exit__(self, *args: Any) -> None: | ||
| 360 | 361 | self.release() | |
| 361 | 362 | ||
| 362 | 363 | def release(self) -> None: | |
@@ -613,12 +614,15 @@ def read(self) -> None: # type: ignore[override] | |||
| 613 | 614 | def _write(self, fp: IO) -> None: | |
| 614 | 615 | """Write an .ini-format representation of the configuration state in | |
| 615 | 616 | git compatible format""" | |
| 616 | - def write_section(name, section_dict): | ||
| 617 | + def write_section(name: str, section_dict: _OMD) -> None: | ||
| 617 | 618 | fp.write(("[%s]\n" % name).encode(defenc)) | |
| 619 | + | ||
| 620 | + values: Sequence[Union[str, bytes, int, float, bool]] | ||
| 618 | 621 | for (key, values) in section_dict.items_all(): | |
| 619 | 622 | if key == "__name__": | |
| 620 | 623 | continue | |
| 621 | 624 | ||
| 625 | + v: Union[str, bytes, int, float, bool] | ||
| 622 | 626 | for v in values: | |
| 623 | 627 | fp.write(("\t%s = %s\n" % (key, self._value_to_string(v).replace('\n', '\n\t'))).encode(defenc)) | |
| 624 | 628 | # END if key is not __name__ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -408,7 +408,7 @@ def expand_path(p: Union[None, PathLike], expand_vars: bool = True) -> Optional[ | |||
| 408 | 408 | return None | |
| 409 | 409 | ||
| 410 | 410 | ||
| 411 | - def remove_password_if_present(cmdline): | ||
| 411 | + def remove_password_if_present(cmdline: Sequence[str]) -> List[str]: | ||
| 412 | 412 | """ | |
| 413 | 413 | Parse any command line argument and if on of the element is an URL with a | |
| 414 | 414 | password, replace it by stars (in-place). | |
@@ -1033,7 +1033,7 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None: | |||
| 1033 | 1033 | ||
| 1034 | 1034 | class IterableClassWatcher(type): | |
| 1035 | 1035 | """ Metaclass that watches """ | |
| 1036 | - def __init__(cls, name, bases, clsdict): | ||
| 1036 | + def __init__(cls, name: str, bases: List, clsdict: Dict) -> None: | ||
| 1037 | 1037 | for base in bases: | |
| 1038 | 1038 | if type(base) == IterableClassWatcher: | |
| 1039 | 1039 | warnings.warn(f"GitPython Iterable subclassed by {name}. " | |
@@ -1052,7 +1052,7 @@ class Iterable(metaclass=IterableClassWatcher): | |||
| 1052 | 1052 | _id_attribute_ = "attribute that most suitably identifies your instance" | |
| 1053 | 1053 | ||
| 1054 | 1054 | @classmethod | |
| 1055 | - def list_items(cls, repo, *args, **kwargs): | ||
| 1055 | + def list_items(cls, repo: 'Repo', *args: Any, **kwargs: Any) -> Any: | ||
| 1056 | 1056 | """ | |
| 1057 | 1057 | Deprecated, use IterableObj instead. | |
| 1058 | 1058 | Find all items of this type - subclasses can specify args and kwargs differently. | |
@@ -1062,7 +1062,7 @@ def list_items(cls, repo, *args, **kwargs): | |||
| 1062 | 1062 | :note: Favor the iter_items method as it will | |
| 1063 | 1063 | ||
| 1064 | 1064 | :return:list(Item,...) list of item instances""" | |
| 1065 | - out_list = IterableList(cls._id_attribute_) | ||
| 1065 | + out_list: Any = IterableList(cls._id_attribute_) | ||
| 1066 | 1066 | out_list.extend(cls.iter_items(repo, *args, **kwargs)) | |
| 1067 | 1067 | return out_list | |
| 1068 | 1068 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ filterwarnings = 'ignore::DeprecationWarning' | |||
| 19 | 19 | # filterwarnings ignore::WarningType # ignores those warnings | |
| 20 | 20 | ||
| 21 | 21 | [tool.mypy] | |
| 22 | - #disallow_untyped_defs = true | ||
| 22 | + # disallow_untyped_defs = true | ||
| 23 | 23 | no_implicit_optional = true | |
| 24 | 24 | warn_redundant_casts = true | |
| 25 | 25 | # warn_unused_ignores = True | |
| Back | FazBrowse Home | New Git URL |
0 commit comments