Remove import from outer package in messagetypes, use dotted imports

This commit is contained in:
Dmitri Bogomolov 2021-11-15 16:37:02 +02:00
parent 99abb6c880
commit 61d9db9e72
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
3 changed files with 18 additions and 17 deletions

View File

@ -1,18 +1,10 @@
import logging import logging
from importlib import import_module
from os import listdir, path
from pybitmessage import paths from importlib import import_module
logger = logging.getLogger('default') logger = logging.getLogger('default')
class MsgBase(object): # pylint: disable=too-few-public-methods
"""Base class for message types"""
def __init__(self):
self.data = {"": type(self).__name__.lower()}
def constructObject(data): def constructObject(data):
"""Constructing an object""" """Constructing an object"""
whitelist = ["message"] whitelist = ["message"]
@ -40,14 +32,19 @@ def constructObject(data):
return returnObj return returnObj
if paths.frozen is not None: try:
import message # noqa : F401 flake8: disable=unused-import from pybitmessage import paths
import vote # noqa : F401 flake8: disable=unused-import except ImportError:
paths = None
if paths and paths.frozen is not None:
from . import message, vote # noqa: F401 flake8: disable=unused-import
else: else:
for mod in listdir(path.dirname(__file__)): import os
for mod in os.listdir(os.path.dirname(__file__)):
if mod == "__init__.py": if mod == "__init__.py":
continue continue
splitted = path.splitext(mod) splitted = os.path.splitext(mod)
if splitted[1] != ".py": if splitted[1] != ".py":
continue continue
try: try:

View File

@ -1,10 +1,14 @@
import logging import logging
from pybitmessage.messagetypes import MsgBase
logger = logging.getLogger('default') logger = logging.getLogger('default')
class MsgBase(object): # pylint: disable=too-few-public-methods
"""Base class for message types"""
def __init__(self):
self.data = {"": type(self).__name__.lower()}
class Message(MsgBase): class Message(MsgBase):
"""Encapsulate a message""" """Encapsulate a message"""
# pylint: disable=attribute-defined-outside-init # pylint: disable=attribute-defined-outside-init

View File

@ -1,6 +1,6 @@
import logging import logging
from pybitmessage.messagetypes import MsgBase from .message import MsgBase
logger = logging.getLogger('default') logger = logging.getLogger('default')