|
@@ -27,6 +27,12 @@ from collections import namedtuple
|
|
import os
|
|
import os
|
|
import posixpath
|
|
import posixpath
|
|
import stat
|
|
import stat
|
|
|
|
+from typing import (
|
|
|
|
+ Optional,
|
|
|
|
+ Dict,
|
|
|
|
+ Union,
|
|
|
|
+ Type,
|
|
|
|
+ )
|
|
import warnings
|
|
import warnings
|
|
import zlib
|
|
import zlib
|
|
from hashlib import sha1
|
|
from hashlib import sha1
|
|
@@ -146,13 +152,13 @@ def filename_to_hex(filename):
|
|
return hex
|
|
return hex
|
|
|
|
|
|
|
|
|
|
-def object_header(num_type, length):
|
|
|
|
|
|
+def object_header(num_type: int, length: int) -> bytes:
|
|
"""Return an object header for the given numeric type and text length."""
|
|
"""Return an object header for the given numeric type and text length."""
|
|
return (object_class(num_type).type_name +
|
|
return (object_class(num_type).type_name +
|
|
b' ' + str(length).encode('ascii') + b'\0')
|
|
b' ' + str(length).encode('ascii') + b'\0')
|
|
|
|
|
|
|
|
|
|
-def serializable_property(name, docstring=None):
|
|
|
|
|
|
+def serializable_property(name: str, docstring:Optional[str]=None):
|
|
"""A property that helps tracking whether serialization is necessary.
|
|
"""A property that helps tracking whether serialization is necessary.
|
|
"""
|
|
"""
|
|
def set(obj, value):
|
|
def set(obj, value):
|
|
@@ -253,6 +259,9 @@ class ShaFile(object):
|
|
|
|
|
|
__slots__ = ('_chunked_text', '_sha', '_needs_serialization')
|
|
__slots__ = ('_chunked_text', '_sha', '_needs_serialization')
|
|
|
|
|
|
|
|
+ type_name:bytes
|
|
|
|
+ type_num:int
|
|
|
|
+
|
|
@staticmethod
|
|
@staticmethod
|
|
def _parse_legacy_object_header(magic, f):
|
|
def _parse_legacy_object_header(magic, f):
|
|
"""Parse a legacy object, creating it but not reading the file."""
|
|
"""Parse a legacy object, creating it but not reading the file."""
|
|
@@ -1417,7 +1426,7 @@ OBJECT_CLASSES = (
|
|
Tag,
|
|
Tag,
|
|
)
|
|
)
|
|
|
|
|
|
-_TYPE_MAP = {}
|
|
|
|
|
|
+_TYPE_MAP:Dict[Union[bytes,int],Type[ShaFile]] = {}
|
|
|
|
|
|
for cls in OBJECT_CLASSES:
|
|
for cls in OBJECT_CLASSES:
|
|
_TYPE_MAP[cls.type_name] = cls
|
|
_TYPE_MAP[cls.type_name] = cls
|
|
@@ -1429,6 +1438,6 @@ _parse_tree_py = parse_tree
|
|
_sorted_tree_items_py = sorted_tree_items
|
|
_sorted_tree_items_py = sorted_tree_items
|
|
try:
|
|
try:
|
|
# Try to import C versions
|
|
# Try to import C versions
|
|
- from dulwich._objects import parse_tree, sorted_tree_items
|
|
|
|
|
|
+ from dulwich._objects import parse_tree, sorted_tree_items # type: ignore
|
|
except ImportError:
|
|
except ImportError:
|
|
pass
|
|
pass
|