Ver código fonte

Merge pull request #1100 from jelmer/typing

Fix typing
Jelmer Vernooij 2 anos atrás
pai
commit
402c616cf6

+ 5 - 5
dulwich/bundle.py

@@ -27,12 +27,12 @@ from .pack import PackData, write_pack_data
 
 class Bundle(object):
 
-    version = None  # type: Optional[int]
+    version: Optional[int] = None
 
-    capabilities = {}  # type: Dict[str, str]
-    prerequisites = []  # type: List[Tuple[bytes, str]]
-    references = {}  # type: Dict[str, bytes]
-    pack_data = []  # type: Union[PackData, Sequence[bytes]]
+    capabilities: Dict[str, str] = {}
+    prerequisites: List[Tuple[bytes, str]] = []
+    references: Dict[str, bytes] = {}
+    pack_data: Union[PackData, Sequence[bytes]] = []
 
     def __eq__(self, other):
         if not isinstance(other, type(self)):

+ 1 - 1
dulwich/client.py

@@ -819,7 +819,7 @@ class GitClient(object):
             # TODO(jelmer): Avoid reading entire file into memory and
             # only processing it after the whole file has been fetched.
             from tempfile import SpooledTemporaryFile
-            f = SpooledTemporaryFile()  # type: IO[bytes]
+            f: IO[bytes] = SpooledTemporaryFile()
 
             def commit():
                 if f.tell():

+ 2 - 2
dulwich/ignore.py

@@ -204,7 +204,7 @@ class Pattern(object):
 
 class IgnoreFilter(object):
     def __init__(self, patterns: Iterable[bytes], ignorecase: bool = False, path=None):
-        self._patterns = []  # type: List[Pattern]
+        self._patterns: List[Pattern] = []
         self._ignorecase = ignorecase
         self._path = path
         for pattern in patterns:
@@ -304,7 +304,7 @@ class IgnoreFilterManager(object):
         global_filters: List[IgnoreFilter],
         ignorecase: bool,
     ):
-        self._path_filters = {}  # type: Dict[str, Optional[IgnoreFilter]]
+        self._path_filters: Dict[str, Optional[IgnoreFilter]] = {}
         self._top_path = top_path
         self._global_filters = global_filters
         self._ignorecase = ignorecase

+ 1 - 1
dulwich/index.py

@@ -462,7 +462,7 @@ def commit_tree(
     Returns:
       SHA1 of the created tree.
     """
-    trees = {b"": {}}  # type: Dict[bytes, Any]
+    trees: Dict[bytes, Any] = {b"": {}}
 
     def add_tree(path):
         if path in trees:

+ 1 - 1
dulwich/porcelain.py

@@ -1146,7 +1146,7 @@ def get_remote_repo(
 
     section = (b"remote", encoded_location)
 
-    remote_name = None  # type: Optional[str]
+    remote_name: Optional[str] = None
 
     if config.has_section(section):
         remote_name = encoded_location.decode()

+ 4 - 4
dulwich/repo.py

@@ -205,8 +205,8 @@ def get_user_identity(config: "StackedConfig", kind: Optional[str] = None) -> by
     Returns:
       A user identity
     """
-    user = None  # type: Optional[bytes]
-    email = None  # type: Optional[bytes]
+    user: Optional[bytes] = None
+    email: Optional[bytes] = None
     if kind:
         user_uc = os.environ.get("GIT_" + kind + "_NAME")
         if user_uc is not None:
@@ -373,8 +373,8 @@ class BaseRepo(object):
         self.object_store = object_store
         self.refs = refs
 
-        self._graftpoints = {}  # type: Dict[bytes, List[bytes]]
-        self.hooks = {}  # type: Dict[str, Hook]
+        self._graftpoints: Dict[bytes, List[bytes]] = {}
+        self.hooks: Dict[str, Hook] = {}
 
     def _determine_file_mode(self) -> bool:
         """Probe the file-system to determine whether permissions can be trusted.

+ 1 - 1
dulwich/tests/compat/test_web.py

@@ -90,7 +90,7 @@ class SmartWebTestCase(WebTests, CompatTestCase):
     This server test case does not use side-band-64k in git-receive-pack.
     """
 
-    min_git_version = (1, 6, 6)  # type: Tuple[int, ...]
+    min_git_version: Tuple[int, ...] = (1, 6, 6)
 
     def _handlers(self):
         return {b"git-receive-pack": NoSideBand64kReceivePackHandler}

+ 1 - 1
dulwich/tests/compat/utils.py

@@ -233,7 +233,7 @@ class CompatTestCase(TestCase):
     min_git_version.
     """
 
-    min_git_version = (1, 5, 0)  # type: Tuple[int, ...]
+    min_git_version: Tuple[int, ...] = (1, 5, 0)
 
     def setUp(self):
         super(CompatTestCase, self).setUp()

+ 1 - 1
dulwich/tests/test_web.py

@@ -110,7 +110,7 @@ class TestHTTPGitRequest(HTTPGitRequest):
 class WebTestCase(TestCase):
     """Base TestCase with useful instance vars and utility functions."""
 
-    _req_class = TestHTTPGitRequest  # type: Type[HTTPGitRequest]
+    _req_class: Type[HTTPGitRequest] = TestHTTPGitRequest
 
     def setUp(self):
         super(WebTestCase, self).setUp()

+ 2 - 2
dulwich/web.py

@@ -344,8 +344,8 @@ class HTTPGitRequest(object):
         self.dumb = dumb
         self.handlers = handlers
         self._start_response = start_response
-        self._cache_headers = []  # type: List[Tuple[str, str]]
-        self._headers = []  # type: List[Tuple[str, str]]
+        self._cache_headers: List[Tuple[str, str]] = []
+        self._headers: List[Tuple[str, str]] = []
 
     def add_header(self, name, value):
         """Add a header to the response."""