diff options
Diffstat (limited to 'git/objects')
-rw-r--r-- | git/objects/fun.py | 2 | ||||
-rw-r--r-- | git/objects/submodule/base.py | 3 | ||||
-rw-r--r-- | git/objects/tree.py | 2 | ||||
-rw-r--r-- | git/objects/util.py | 18 |
4 files changed, 15 insertions, 10 deletions
diff --git a/git/objects/fun.py b/git/objects/fun.py index d6cdafe1..19b4e525 100644 --- a/git/objects/fun.py +++ b/git/objects/fun.py @@ -51,7 +51,7 @@ def tree_to_stream(entries: Sequence[EntryTup], write: Callable[['ReadableBuffer if isinstance(name, str): name_bytes = name.encode(defenc) else: - name_bytes = name + name_bytes = name # type: ignore[unreachable] # check runtime types - is always str? write(b''.join((mode_str, b' ', name_bytes, b'\0', binsha))) # END for each item diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index 559d2585..d306c91d 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -379,6 +379,7 @@ class Submodule(IndexObject, TraversableIterableObj): :return: The newly created submodule instance :note: works atomically, such that no change will be done if the repository update fails for instance""" + if repo.bare: raise InvalidGitRepositoryError("Cannot add submodules to bare repositories") # END handle bare repos @@ -434,7 +435,7 @@ class Submodule(IndexObject, TraversableIterableObj): url = urls[0] else: # clone new repo - kwargs: Dict[str, Union[bool, int, Sequence[TBD]]] = {'n': no_checkout} + kwargs: Dict[str, Union[bool, int, str, Sequence[TBD]]] = {'n': no_checkout} if not branch_is_default: kwargs['b'] = br.name # END setup checkout-branch diff --git a/git/objects/tree.py b/git/objects/tree.py index 0cceb59a..22531895 100644 --- a/git/objects/tree.py +++ b/git/objects/tree.py @@ -215,7 +215,7 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable): super(Tree, self).__init__(repo, binsha, mode, path) @ classmethod - def _get_intermediate_items(cls, index_object: 'Tree', + def _get_intermediate_items(cls, index_object: IndexObjUnion, ) -> Union[Tuple['Tree', ...], Tuple[()]]: if index_object.type == "tree": return tuple(index_object._iter_convert_to_object(index_object._cache)) diff --git a/git/objects/util.py b/git/objects/util.py index f627211e..16d4c0ac 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -167,7 +167,7 @@ def from_timestamp(timestamp: float, tz_offset: float) -> datetime: return utc_dt -def parse_date(string_date: str) -> Tuple[int, int]: +def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: """ Parse the given date as one of the following @@ -181,9 +181,13 @@ def parse_date(string_date: str) -> Tuple[int, int]: :raise ValueError: If the format could not be understood :note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY. """ - if isinstance(string_date, datetime) and string_date.tzinfo: - offset = -int(string_date.utcoffset().total_seconds()) - return int(string_date.astimezone(utc).timestamp()), offset + if isinstance(string_date, datetime): + if string_date.tzinfo: + utcoffset = cast(timedelta, string_date.utcoffset()) # typeguard, if tzinfoand is not None + offset = -int(utcoffset.total_seconds()) + return int(string_date.astimezone(utc).timestamp()), offset + else: + raise ValueError(f"string_date datetime object without tzinfo, {string_date}") # git time try: @@ -245,7 +249,7 @@ def parse_date(string_date: str) -> Tuple[int, int]: raise ValueError("no format matched") # END handle format except Exception as e: - raise ValueError("Unsupported date format: %s" % string_date) from e + raise ValueError(f"Unsupported date format or type: {string_date}, type={type(string_date)}") from e # END handle exceptions @@ -338,7 +342,7 @@ class Traversable(Protocol): """ # Commit and Submodule have id.__attribute__ as IterableObj # Tree has id.__attribute__ inherited from IndexObject - if isinstance(self, (TraversableIterableObj, Has_id_attribute)): + if isinstance(self, Has_id_attribute): id = self._id_attribute_ else: id = "" # shouldn't reach here, unless Traversable subclass created with no _id_attribute_ @@ -346,7 +350,7 @@ class Traversable(Protocol): if not as_edge: out: IterableList[Union['Commit', 'Submodule', 'Tree', 'Blob']] = IterableList(id) - out.extend(self.traverse(as_edge=as_edge, *args, **kwargs)) # type: ignore + out.extend(self.traverse(as_edge=as_edge, *args, **kwargs)) return out # overloads in subclasses (mypy does't allow typing self: subclass) # Union[IterableList['Commit'], IterableList['Submodule'], IterableList[Union['Submodule', 'Tree', 'Blob']]] |