Quellcode durchsuchen

Merge pull request #1184 from dimbleby/hashlib-typechecking-only

_hashlib import is needed only for typechecking
Jelmer Vernooij vor 1 Jahr
Ursprung
Commit
3eea76c7d4
1 geänderte Dateien mit 5 neuen und 3 gelöschten Zeilen
  1. 5 3
      dulwich/objects.py

+ 5 - 3
dulwich/objects.py

@@ -31,6 +31,7 @@ from collections import namedtuple
 from hashlib import sha1
 from io import BytesIO
 from typing import (
+    TYPE_CHECKING,
     BinaryIO,
     Dict,
     Iterable,
@@ -42,8 +43,6 @@ from typing import (
     Union,
 )
 
-from _hashlib import HASH
-
 from .errors import (
     ChecksumMismatch,
     FileFormatException,
@@ -55,6 +54,9 @@ from .errors import (
 )
 from .file import GitFile
 
+if TYPE_CHECKING:
+    from _hashlib import HASH
+
 ZERO_SHA = b"0" * 40
 
 # Header fields for commits
@@ -277,7 +279,7 @@ class ShaFile:
     type_name: bytes
     type_num: int
     _chunked_text: Optional[List[bytes]]
-    _sha: Union[FixedSha, None, HASH]
+    _sha: Union[FixedSha, None, "HASH"]
 
     @staticmethod
     def _parse_legacy_object_header(magic, f: BinaryIO) -> "ShaFile":