Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Commit

Permalink
start using typing for type hints
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
  • Loading branch information
nicolas33 committed Nov 6, 2015
1 parent 2699464 commit b23c1d6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ branches:
- master
- next

before_install:
- pip install --upgrade pip

# command to install dependencies
#install: "pip install -r requirements.txt"
install: "pip install -r requirements.txt"

#before_script:
#- cp -a ./tests "$TRAVIS_BUILD_DIR"
Expand Down
9 changes: 7 additions & 2 deletions imapfw/drivers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from typing import TypeVar


DriverClass = TypeVar('Driver based class')


class DriverInternalInterface(object):
pass
Expand Down Expand Up @@ -52,13 +57,13 @@ def getClassName(self) -> str:
def getRepositoryName(self) -> str:
return self.repositoryName

def init(self):
def init(self) -> None:
"""Override this method to make initialization in the rascal."""

pass


def loadDriver(cls_driver: object, repositoryName: str, conf: dict) -> Driver:
def loadDriver(cls_driver: DriverClass, repositoryName: str, conf: dict) -> Driver:

# Build the final end-driver.
if not issubclass(cls_driver, DriverInterface):
Expand Down
18 changes: 13 additions & 5 deletions imapfw/types/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from typing import TypeVar, Union

from imapfw import runtime
from imapfw.types.repository import loadRepository

from .folder import Folders

# Annotations.
from imapfw.types.repository import Repository


AccountClass = TypeVar('Account based class')


class AccountInternalInterface(object):
def fw_getLeft(self): raise NotImplementedError
Expand All @@ -44,23 +52,23 @@ class Account(AccountInterface, AccountInternalInterface):
left = None
right = None

def fw_getSide(self, side: str) -> 'complete repository':
def fw_getSide(self, side: str) -> Repository:
if side == 'left':
return self.fw_getLeft()
if side == 'right':
return self.fw_getRight()
assert side in ['left', 'right']

def fw_getLeft(self):
def fw_getLeft(self) -> Repository:
return loadRepository(self.left)

def fw_getRight(self):
def fw_getRight(self) -> Repository:
return loadRepository(self.right)

def getClassName(self) -> str:
return self.__class__.__name__

def init(self):
def init(self) -> None:
"""Override this method to make initialization in the rascal."""

pass
Expand All @@ -69,7 +77,7 @@ def syncFolders(self, folders: Folders) -> Folders:
return folders


def loadAccount(obj: 'account class or str name') -> 'initialized Account':
def loadAccount(obj: Union[AccountClass, str]) -> Account:

if isinstance(obj, str):
obj = runtime.rascal.get(obj, [Account, dict])
Expand Down
7 changes: 6 additions & 1 deletion imapfw/types/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from typing import TypeVar, Union

from imapfw.controllers.controller import loadController
from imapfw.drivers.driver import loadDriver


RepositoryClass = TypeVar('Repository based class')


class RepositoryInterface(object):

conf = None
Expand Down Expand Up @@ -90,7 +95,7 @@ def init(self):
pass


def loadRepository(obj: 'Repository class or dict') -> Repository:
def loadRepository(obj: Union[RepositoryClass, dict]) -> Repository:

try:
if issubclass(obj, RepositoryInterface):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typing; python_version < '3.5'

0 comments on commit b23c1d6

Please sign in to comment.