From 454f27b3d00c586d46566f3e5ef4d275d44ab684 Mon Sep 17 00:00:00 2001 From: linuxmercedes Date: Sun, 6 Jan 2019 14:38:55 -0600 Subject: [PATCH] Add classmethod return type signatures Also add a couple git ones that got missed. --- assigner/backends/base.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/assigner/backends/base.py b/assigner/backends/base.py index 2cdd026..249acd0 100644 --- a/assigner/backends/base.py +++ b/assigner/backends/base.py @@ -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""" @@ -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 @@ -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: @@ -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 @@ -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: