Skip to content

Commit 0a2d3cc

Browse files
committed
Add static typing for vcs module
1 parent 914ea66 commit 0a2d3cc

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

src/diffuse/vcs/folder_set.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import os
2121

22+
from typing import List
23+
2224

2325
class FolderSet:
2426
'''Utility class to help support Git and Monotone.
@@ -27,18 +29,18 @@ class FolderSet:
2729
"mtn automate inventory."
2830
'''
2931

30-
def __init__(self, names):
31-
self.folders = f = []
32+
def __init__(self, names: List[str]) -> None:
33+
self.folders: List[str] = []
3234
for name in names:
3335
name = os.path.abspath(name)
3436
# ensure all names end with os.sep
3537
if not name.endswith(os.sep):
3638
name += os.sep
37-
f.append(name)
39+
self.folders.append(name)
3840

3941
# returns True if the given abspath is a file that should be included in
4042
# the interesting file subset
41-
def contains(self, abspath):
43+
def contains(self, abspath: str) -> bool:
4244
if not abspath.endswith(os.sep):
4345
abspath += os.sep
4446
for f in self.folders:

src/diffuse/vcs/hg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# Mercurial support
3131
class Hg(VcsInterface):
3232
def __init__(self, root: str):
33-
VcsInterface.__init__(self, root)
33+
super().__init__(root)
3434
self.working_rev: Optional[str] = None
3535

3636
def _getPreviousRevision(self, prefs, rev):

src/diffuse/vcs/svn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# SVK support subclasses from this
3434
class Svn(VcsInterface):
3535
def __init__(self, root: str):
36-
VcsInterface.__init__(self, root)
36+
super().__init__(root)
3737
self.url: Optional[str] = None
3838

3939
@staticmethod
@@ -61,7 +61,7 @@ def _getPreviousRevision(rev: Optional[str]) -> str:
6161
m = int(rev)
6262
return str(max(m > 1, 0))
6363

64-
def _getURL(self, prefs):
64+
def _getURL(self, prefs: Preferences) -> Optional[str]:
6565
if self.url is None:
6666
vcs, prefix = self._getVcs(), self._getURLPrefix()
6767
n = len(prefix)

src/diffuse/vcs/vcs_interface.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
# with this program; if not, write to the Free Software Foundation, Inc.,
1818
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1919

20+
from abc import ABCMeta, abstractmethod
2021
from typing import List, Optional, Tuple
2122

2223
from diffuse.preferences import Preferences
2324

2425

25-
class VcsInterface:
26+
class VcsInterface(metaclass=ABCMeta):
2627
"""Interface for the VCSs."""
2728

2829
PathRevisionPair = Tuple[Optional[str], Optional[str]]
@@ -32,15 +33,19 @@ def __init__(self, root: str):
3233
"""The object will initialized with the repository's root folder."""
3334
self.root = root
3435

36+
@abstractmethod
3537
def getFileTemplate(self, prefs: Preferences, name: str) -> PathRevisionList:
3638
"""Indicates which revisions to display for a file when none were explicitly
3739
requested."""
3840

41+
@abstractmethod
3942
def getCommitTemplate(self, prefs, rev, names):
4043
"""Indicates which file revisions to display for a commit."""
4144

45+
@abstractmethod
4246
def getFolderTemplate(self, prefs, names):
4347
"""Indicates which file revisions to display for a set of folders."""
4448

49+
@abstractmethod
4550
def getRevision(self, prefs: Preferences, name: str, rev: str) -> bytes:
4651
"""Returns the contents of the specified file revision"""

src/diffuse/vcs/vcs_registry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def _get_svk_repo(path: str, prefs: Preferences) -> Optional[VcsInterface]:
186186
# find working copies by parsing the config file
187187
with open(svkconfig, 'r', encoding='utf-8') as f:
188188
ss: List[str] = utils.readlines(f)
189-
projs, sep = [], os.sep
189+
projs: List[str] = []
190+
sep = os.sep
190191
# find the separator character
191192
for s in ss:
192193
if s.startswith(' sep: ') and len(s) > 7:

0 commit comments

Comments
 (0)