Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add underscores to hide some imports #978

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions shiny/express/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

from ..session import Inputs, Outputs, Session
# Import these with underscore names so they won't show in autocomplete from the Python
# console.
from ..session import Inputs as _Inputs, Outputs as _Outputs, Session as _Session
from ..session import _utils as _session_utils
from . import app, ui
from . import ui
from ._is_express import is_express_app
from ._output import output_args, suspend_display
from ._run import wrap_express_app
Expand All @@ -16,15 +18,14 @@
"output_args",
"suspend_display",
"wrap_express_app",
"app",
"ui",
"display_body",
)

# Add types to help type checkers
input: Inputs
output: Outputs
session: Session
input: _Inputs
output: _Outputs
session: _Session


# Note that users should use `from shiny.express import input` instead of `from shiny
Expand All @@ -50,8 +51,8 @@ def __init__(self):

from .._namespaces import Root

self.input = Inputs({})
self.output = Outputs(cast(Session, self), Root, {}, {})
self.input = _Inputs({})
self.output = _Outputs(cast(_Session, self), Root, {}, {})

# This is needed so that Outputs don't throw an error.
def _is_hidden(self, name: str) -> bool:
Expand All @@ -61,15 +62,15 @@ def _is_hidden(self, name: str) -> bool:
_current_mock_session: _MockSession | None = None


def _get_current_session_or_mock() -> Session:
def _get_current_session_or_mock() -> _Session:
from typing import cast

session = _session_utils.get_current_session()
if session is None:
global _current_mock_session
if _current_mock_session is None:
_current_mock_session = _MockSession()
return cast(Session, _current_mock_session)
return cast(_Session, _current_mock_session)

else:
return session
Loading