Skip to content

Commit

Permalink
Add classmethod return type signatures
Browse files Browse the repository at this point in the history
Also add a couple git ones that got missed.
  • Loading branch information
LinuxMercedes committed Jan 8, 2019
1 parent bcf3a29 commit 454f27b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions assigner/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import git
import re
from typing import Optional
from typing import Optional, Type, TypeVar


class RepoError(Exception):
pass


T = TypeVar('T', bound='RepoBase')
class RepoBase:
"""Generic Repo base"""

Expand All @@ -23,7 +24,7 @@ def build_url(cls, config, namespace: str, name: str) -> str:
raise NotImplementedError

@classmethod
def from_url(cls, url: str, token: str):
def from_url(cls: Type[T], url: str, token: str) -> T:
raise NotImplementedError

@property
Expand Down Expand Up @@ -53,10 +54,10 @@ def ssh_url(self) -> str:
def already_exists(self) -> bool:
raise NotImplementedError

def get_head(self, branch: str):
def get_head(self, branch: str) -> git.refs.head.Head:
raise NotImplementedError

def checkout(self, branch: str):
def checkout(self, branch: str) -> git.refs.head.Head:
raise NotImplementedError

def pull(self, branch: str) -> None:
Expand Down Expand Up @@ -124,11 +125,12 @@ def lock(self, student_id: str) -> None:
raise NotImplementedError


T = TypeVar('T', bound='StudentRepoBase')
class StudentRepoBase(RepoBase):
"""Repository for a student's solution to a homework assignment"""

@classmethod
def new(cls, base_repo: str, semester: str, section: str, username: str):
def new(cls, base_repo: str, semester: str, section: str, username: str) -> T:
raise NotImplementedError

@classmethod
Expand All @@ -140,10 +142,11 @@ def push(self, base_repo, branch: str = "master") -> None:
raise NotImplementedError


T = TypeVar('T', bound='StudentRepoBase')
class TemplateRepoBase(RepoBase):
"""A repo from which StudentRepos are cloned from (Homework Repo)."""
@classmethod
def new(cls, name: str, namespace: str, config):
def new(cls, name: str, namespace: str, config) -> T:
raise NotImplementedError

def push_to(self, student_repo: StudentRepoBase, branch: str = "master") -> None:
Expand Down

0 comments on commit 454f27b

Please sign in to comment.