account mypy fix

This commit is contained in:
Diogo Sousa
2023-07-31 22:25:35 +01:00
parent 719e753605
commit 60da84fe99

View File

@@ -18,8 +18,11 @@ class OpenBBError(Exception):
class Account:
def __init__(self, app: "Container"):
self._app = app
def __init__(self, container: "Container"):
self._container = container
self._openbb_directory = (
container._command_runner_session.command_runner.system_settings.openbb_directory
)
def create_hub_service(
self,
@@ -28,9 +31,7 @@ class Account:
sdk_token: Optional[str] = None,
) -> HubService:
if email is None and password is None and sdk_token is None:
session_file = Path(
self._app.system.openbb_directory, ".sdk_hub_session.json"
)
session_file = Path(self._openbb_directory, ".sdk_hub_session.json")
if not session_file.exists():
raise OpenBBError("Session not found.")
@@ -72,19 +73,19 @@ class Account:
hs = self.create_hub_service(email, password, sdk_token)
incoming = hs.pull()
updated = UserService.update_default(incoming)
self._app._command_runner_session = CommandRunnerSession(user_settings=updated)
self._container._command_runner_session = CommandRunnerSession(
user_settings=updated
)
if remember_me:
Path(self._app.system.openbb_directory).mkdir(parents=False, exist_ok=True)
session_file = Path(
self._app.system.openbb_directory, ".sdk_hub_session.json"
)
Path(self._openbb_directory).mkdir(parents=False, exist_ok=True)
session_file = Path(self._openbb_directory, ".sdk_hub_session.json")
with open(session_file, "w") as f:
if not hs.session:
raise OpenBBError("Not connected to hub.")
json.dump(hs.session.dict(), f, indent=4)
return self._app._command_runner_session.user_settings
return self._container._command_runner_session.user_settings
def save(self) -> UserSettings:
"""Save user settings.
@@ -95,16 +96,16 @@ class Account:
User settings: profile, credentials, preferences
"""
hub_session = (
self._app._command_runner_session.user_settings.profile.hub_session
self._container._command_runner_session.user_settings.profile.hub_session
)
if not hub_session:
UserService.write_default_user_settings(
self._app._command_runner_session.user_settings
self._container._command_runner_session.user_settings
)
else:
hs = HubService(hub_session)
hs.push(self._app._command_runner_session.user_settings)
return self._app._command_runner_session.user_settings
hs.push(self._container._command_runner_session.user_settings)
return self._container._command_runner_session.user_settings
def refresh(self) -> UserSettings:
"""Refresh user settings.
@@ -115,19 +116,19 @@ class Account:
User settings: profile, credentials, preferences
"""
hub_session = (
self._app._command_runner_session.user_settings.profile.hub_session
self._container._command_runner_session.user_settings.profile.hub_session
)
if not hub_session:
self._app._command_runner_session = CommandRunnerSession()
self._container._command_runner_session = CommandRunnerSession()
else:
hs = HubService(hub_session)
incoming = hs.pull()
updated = UserService.update_default(incoming)
updated.id = self._app._command_runner_session.user_settings.id
self._app._command_runner_session = CommandRunnerSession(
updated.id = self._container._command_runner_session.user_settings.id
self._container._command_runner_session = CommandRunnerSession(
user_settings=updated
)
return self._app._command_runner_session.user_settings
return self._container._command_runner_session.user_settings
def logout(self) -> UserSettings:
"""Logout from hub.
@@ -138,7 +139,7 @@ class Account:
User settings: profile, credentials, preferences
"""
hub_session = (
self._app._command_runner_session.user_settings.profile.hub_session
self._container._command_runner_session.user_settings.profile.hub_session
)
if not hub_session:
raise OpenBBError("Not connected to hub.")
@@ -146,9 +147,9 @@ class Account:
hs = HubService(hub_session)
hs.disconnect()
session_file = Path(self._app.system.openbb_directory, ".sdk_hub_session.json")
session_file = Path(self._openbb_directory, ".sdk_hub_session.json")
if session_file.exists():
session_file.unlink()
self._app._command_runner_session = CommandRunnerSession()
return self._app._command_runner_session.user_settings
self._container._command_runner_session = CommandRunnerSession()
return self._container._command_runner_session.user_settings