| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,7 +89,7 @@ def _set_cache_(self, attr: str) -> None: | |||
| 89 | 89 | """Retrieve object information""" | |
| 90 | 90 | if attr == "size": | |
| 91 | 91 | oinfo = self.repo.odb.info(self.binsha) | |
| 92 | - self.size = oinfo.size | ||
| 92 | + self.size = oinfo.size # type: int | ||
| 93 | 93 | # assert oinfo.type == self.type, _assertion_msg_format % (self.binsha, oinfo.type, self.type) | |
| 94 | 94 | else: | |
| 95 | 95 | super(Object, self)._set_cache_(attr) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,9 @@ | |||
| 14 | 14 | if TYPE_CHECKING: | |
| 15 | 15 | from git.repo import Repo | |
| 16 | 16 | from git.util import Actor | |
| 17 | + from .commit import Commit | ||
| 18 | + from .blob import Blob | ||
| 19 | + from .tree import Tree | ||
| 17 | 20 | ||
| 18 | 21 | __all__ = ("TagObject", ) | |
| 19 | 22 | ||
@@ -42,7 +45,7 @@ def __init__(self, repo: 'Repo', binsha: bytes, object: Union[None, base.Object] | |||
| 42 | 45 | authored_date is in, in a format similar to time.altzone""" | |
| 43 | 46 | super(TagObject, self).__init__(repo, binsha) | |
| 44 | 47 | if object is not None: | |
| 45 | - self.object = object | ||
| 48 | + self.object = object # type: Union['Commit', 'Blob', 'Tree', 'TagObject'] | ||
| 46 | 49 | if tag is not None: | |
| 47 | 50 | self.tag = tag | |
| 48 | 51 | if tagger is not None: | |
@@ -62,8 +65,9 @@ def _set_cache_(self, attr: str) -> None: | |||
| 62 | 65 | ||
| 63 | 66 | _obj, hexsha = lines[0].split(" ") | |
| 64 | 67 | _type_token, type_name = lines[1].split(" ") | |
| 68 | + object_type = get_object_type_by_name(type_name.encode('ascii')) | ||
| 65 | 69 | self.object = \ | |
| 66 | - get_object_type_by_name(type_name.encode('ascii'))(self.repo, hex_to_bin(hexsha)) | ||
| 70 | + object_type(self.repo, hex_to_bin(hexsha)) | ||
| 67 | 71 | ||
| 68 | 72 | self.tag = lines[2][4:] # tag <tag name> | |
| 69 | 73 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ | |||
| 18 | 18 | from datetime import datetime, timedelta, tzinfo | |
| 19 | 19 | ||
| 20 | 20 | # typing ------------------------------------------------------------ | |
| 21 | - from typing import Literal, TYPE_CHECKING, Tuple, Union | ||
| 21 | + from typing import Literal, TYPE_CHECKING, Tuple, Type, Union, cast | ||
| 22 | 22 | ||
| 23 | 23 | if TYPE_CHECKING: | |
| 24 | 24 | from .commit import Commit | |
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | #{ Functions | |
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | - def mode_str_to_int(modestr: str) -> int: | ||
| 39 | + def mode_str_to_int(modestr: Union[bytes, str]) -> int: | ||
| 40 | 40 | """ | |
| 41 | 41 | :param modestr: string like 755 or 644 or 100644 - only the last 6 chars will be used | |
| 42 | 42 | :return: | |
@@ -46,12 +46,14 @@ def mode_str_to_int(modestr: str) -> int: | |||
| 46 | 46 | for example.""" | |
| 47 | 47 | mode = 0 | |
| 48 | 48 | for iteration, char in enumerate(reversed(modestr[-6:])): | |
| 49 | + char = cast(Union[str, int], char) | ||
| 49 | 50 | mode += int(char) << iteration * 3 | |
| 50 | 51 | # END for each char | |
| 51 | 52 | return mode | |
| 52 | 53 | ||
| 53 | 54 | ||
| 54 | - def get_object_type_by_name(object_type_name: str) -> Union['Commit', 'TagObject', 'Tree', 'Blob']: | ||
| 55 | + def get_object_type_by_name(object_type_name: bytes | ||
| 56 | + ) -> Union[Type['Commit'], Type['TagObject'], Type['Tree'], Type['Blob']]: | ||
| 55 | 57 | """ | |
| 56 | 58 | :return: type suitable to handle the given object type name. | |
| 57 | 59 | Use the type to create new instances. | |
@@ -72,7 +74,7 @@ def get_object_type_by_name(object_type_name: str) -> Union['Commit', 'TagObject | |||
| 72 | 74 | from . import tree | |
| 73 | 75 | return tree.Tree | |
| 74 | 76 | else: | |
| 75 | - raise ValueError("Cannot handle unknown object type: %s" % object_type_name) | ||
| 77 | + raise ValueError("Cannot handle unknown object type: %s" % object_type_name.decode()) | ||
| 76 | 78 | ||
| 77 | 79 | ||
| 78 | 80 | def utctz_to_altz(utctz: str) -> int: | |
@@ -116,7 +118,7 @@ def __init__(self, secs_west_of_utc: float, name: Union[None, str] = None) -> No | |||
| 116 | 118 | self._offset = timedelta(seconds=-secs_west_of_utc) | |
| 117 | 119 | self._name = name or 'fixed' | |
| 118 | 120 | ||
| 119 | - def __reduce__(self) -> Tuple['tzoffset', Tuple[float, str]]: | ||
| 121 | + def __reduce__(self) -> Tuple[Type['tzoffset'], Tuple[float, str]]: | ||
| 120 | 122 | return tzoffset, (-self._offset.total_seconds(), self._name) | |
| 121 | 123 | ||
| 122 | 124 | def utcoffset(self, dt) -> timedelta: | |
@@ -163,18 +165,18 @@ def parse_date(string_date: str) -> Tuple[int, int]: | |||
| 163 | 165 | # git time | |
| 164 | 166 | try: | |
| 165 | 167 | if string_date.count(' ') == 1 and string_date.rfind(':') == -1: | |
| 166 | - timestamp, offset = string_date.split() | ||
| 168 | + timestamp, offset_str = string_date.split() | ||
| 167 | 169 | if timestamp.startswith('@'): | |
| 168 | 170 | timestamp = timestamp[1:] | |
| 169 | - timestamp = int(timestamp) | ||
| 170 | - return timestamp, utctz_to_altz(verify_utctz(offset)) | ||
| 171 | + timestamp_int = int(timestamp) | ||
| 172 | + return timestamp_int, utctz_to_altz(verify_utctz(offset_str)) | ||
| 171 | 173 | else: | |
| 172 | - offset = "+0000" # local time by default | ||
| 174 | + offset_str = "+0000" # local time by default | ||
| 173 | 175 | if string_date[-5] in '-+': | |
| 174 | - offset = verify_utctz(string_date[-5:]) | ||
| 176 | + offset_str = verify_utctz(string_date[-5:]) | ||
| 175 | 177 | string_date = string_date[:-6] # skip space as well | |
| 176 | 178 | # END split timezone info | |
| 177 | - offset = utctz_to_altz(offset) | ||
| 179 | + offset = utctz_to_altz(offset_str) | ||
| 178 | 180 | ||
| 179 | 181 | # now figure out the date and time portion - split time | |
| 180 | 182 | date_formats = [] | |
@@ -235,7 +237,7 @@ def parse_actor_and_date(line: str) -> Tuple[Actor, int, int]: | |||
| 235 | 237 | author Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700 | |
| 236 | 238 | ||
| 237 | 239 | :return: [Actor, int_seconds_since_epoch, int_timezone_offset]""" | |
| 238 | - actor, epoch, offset = '', 0, 0 | ||
| 240 | + actor, epoch, offset = '', '0', '0' | ||
| 239 | 241 | m = _re_actor_epoch.search(line) | |
| 240 | 242 | if m: | |
| 241 | 243 | actor, epoch, offset = m.groups() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments