diff options
| author | Yobmod <yobmod@gmail.com> | 2021-06-24 05:52:48 +0100 |
|---|---|---|
| committer | Yobmod <yobmod@gmail.com> | 2021-06-24 05:52:48 +0100 |
| commit | 42e4f5e26b812385df65f8f32081035e2fb2a121 (patch) | |
| tree | b391428ad23747b8cb8ee34908f0a4e4711c45a5 /git/objects/fun.py | |
| parent | 6500844a925f0df90a0926dbdfc7b5ebb4a97bc9 (diff) | |
| download | gitpython-42e4f5e26b812385df65f8f32081035e2fb2a121.tar.gz | |
Add types to tree.Tree
Diffstat (limited to 'git/objects/fun.py')
| -rw-r--r-- | git/objects/fun.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/git/objects/fun.py b/git/objects/fun.py index 9b36712e..339a53b8 100644 --- a/git/objects/fun.py +++ b/git/objects/fun.py @@ -1,10 +1,19 @@ """Module with functions which are supposed to be as fast as possible""" from stat import S_ISDIR + from git.compat import ( safe_decode, defenc ) +# typing ---------------------------------------------- + +from typing import List, Tuple + + +# --------------------------------------------------- + + __all__ = ('tree_to_stream', 'tree_entries_from_data', 'traverse_trees_recursive', 'traverse_tree_recursive') @@ -38,7 +47,7 @@ def tree_to_stream(entries, write): # END for each item -def tree_entries_from_data(data): +def tree_entries_from_data(data: bytes) -> List[Tuple[bytes, int, str]]: """Reads the binary representation of a tree and returns tuples of Tree items :param data: data block with tree data (as bytes) :return: list(tuple(binsha, mode, tree_relative_path), ...)""" @@ -72,8 +81,8 @@ def tree_entries_from_data(data): # default encoding for strings in git is utf8 # Only use the respective unicode object if the byte stream was encoded - name = data[ns:i] - name = safe_decode(name) + name_bytes = data[ns:i] + name = safe_decode(name_bytes) # byte is NULL, get next 20 i += 1 |
