Skip to content

Commit

Permalink
test: Use direct type aliases to bypass name conflicts
Browse files Browse the repository at this point in the history
Use direct type aliases such as "Config_ = Config" rather then
defining a dedicated "ConfigType = Type[Config]", since the type alias
may be required when annotating instance variables.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
  • Loading branch information
mcb30 committed Feb 19, 2020
1 parent 17c5558 commit b43e19a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
16 changes: 8 additions & 8 deletions idiosync/base.py
Expand Up @@ -235,21 +235,21 @@ def __init__(self, **kwargs):
self.options = kwargs


ConfigType = Type[Config]
UserType = Type[User]
GroupType = Type[Group]
Config_ = Config
User_ = User
Group_ = Group


class Database:
"""A user database"""

Config: ClassVar[ConfigType]
Config: ClassVar[Type[Config_]]
"""Configuration class for this database"""

User: ClassVar[UserType]
User: ClassVar[Type[User_]]
"""User class for this database"""

Group: ClassVar[GroupType]
Group: ClassVar[Type[Group_]]
"""Group class for this database"""

def __init__(self, **kwargs):
Expand Down Expand Up @@ -318,13 +318,13 @@ def trace(self, fh=None, cookiefh=None, **kwargs):
cookiefh.flush()


StateType = Type[State]
State_ = State


class WritableDatabase(Database):
"""A writable user database"""

State: ClassVar[StateType]
State: ClassVar[Type[State_]]
"""State class for this database"""

def __init__(self, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions idiosync/cli.py
Expand Up @@ -44,13 +44,13 @@ def main(cls):
cls().execute()


ConfigType = Type[Config]
Config_ = Config


class ConfigCommand(Command):
"""An executable command utilising a configuration file"""

Config: ClassVar[ConfigType]
Config: ClassVar[Type[Config_]]

def __init__(self, argv=None):
super().__init__(argv)
Expand Down
8 changes: 4 additions & 4 deletions idiosync/config.py
Expand Up @@ -60,15 +60,15 @@ def database(self):
return plugins[self.plugin](**self.params)


DatabaseConfigType = Type[DatabaseConfig]
SynchronizerType = Type[Synchronizer]
DatabaseConfig_ = DatabaseConfig
Synchronizer_ = Synchronizer


class SynchronizerConfig(Config):
"""A database synchronizer configuration"""

DatabaseConfig: ClassVar[DatabaseConfigType] = DatabaseConfig
Synchronizer: ClassVar[SynchronizerType] = Synchronizer
DatabaseConfig: ClassVar[Type[DatabaseConfig_]] = DatabaseConfig
Synchronizer: ClassVar[Type[Synchronizer_]] = Synchronizer

def __init__(self, src, dst):
self.src = src
Expand Down
11 changes: 4 additions & 7 deletions idiosync/sync.py
Expand Up @@ -109,15 +109,15 @@ class GroupSynchronizer(EntrySynchronizer):
attrs = ['commonName', 'description']


UserSynchronizerType = Type[UserSynchronizer]
GroupSynchronizerType = Type[GroupSynchronizer]
UserSynchronizer_ = UserSynchronizer
GroupSynchronizer_ = GroupSynchronizer


class Synchronizer:
"""A user database synchronizer"""

UserSynchronizer: ClassVar[UserSynchronizerType] = UserSynchronizer
GroupSynchronizer: ClassVar[GroupSynchronizerType] = GroupSynchronizer
UserSynchronizer: ClassVar[Type[UserSynchronizer_]] = UserSynchronizer
GroupSynchronizer: ClassVar[Type[GroupSynchronizer_]] = GroupSynchronizer

def __init__(self, src, dst):
self.src = src
Expand Down Expand Up @@ -227,9 +227,6 @@ def sync(self, persist=True, strict=False, delete=False):
raise TypeError(src)


SynchronizerType = Type[Synchronizer]


def synchronize(src, dst, **kwargs):
"""Synchronize source database to destination database"""
Synchronizer(src, dst).sync(**kwargs)

0 comments on commit b43e19a

Please sign in to comment.