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

Resolve traitlets type warnings, lint, remove six #1015

Merged
merged 3 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
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
42 changes: 21 additions & 21 deletions atest/diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
from functools import partial

from robot.libraries.BuiltIn import BuiltIn
from robot.utils import timestr_to_secs
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
from SeleniumLibrary import SeleniumLibrary

from robot.utils import timestr_to_secs
DIAGNOSTIC_CLASS = "cm-lintRange"

DIAGNOSTIC_CLASS = 'cm-lintRange'

def page_contains_diagnostic(driver: WebDriver, selector, negate=False):
elements = driver.find_elements(By.CSS_SELECTOR, f'.{DIAGNOSTIC_CLASS}')
elements = driver.find_elements(By.CSS_SELECTOR, f".{DIAGNOSTIC_CLASS}")
if not elements:
return True if negate else False
driver.execute_script("""
driver.execute_script(
"""
arguments[0].map(el => {
let diagnostic = el.cmView.mark.spec.diagnostic;
el.title = diagnostic.message + " (" + diagnostic.source + ")";
});
""", elements)
""",
elements,
)
try:
driver.find_element(By.CSS_SELECTOR, f'.{DIAGNOSTIC_CLASS}{selector}')
driver.find_element(By.CSS_SELECTOR, f".{DIAGNOSTIC_CLASS}{selector}")
except NoSuchElementException:
return True if negate else False
return False if negate else True


def wait_until_page_contains_diagnostic(selector, timeout='5s'):
def wait_until_page_contains_diagnostic(selector, timeout="5s"):
sl: SeleniumLibrary = BuiltIn().get_library_instance("SeleniumLibrary")
wait = WebDriverWait(sl.driver, timestr_to_secs(timeout))
try:
return wait.until(
partial(page_contains_diagnostic, selector=selector)
)
return wait.until(partial(page_contains_diagnostic, selector=selector))
except TimeoutException:
elements = sl.driver.find_elements(By.CSS_SELECTOR, f'.{DIAGNOSTIC_CLASS}')
elements = sl.driver.find_elements(By.CSS_SELECTOR, f".{DIAGNOSTIC_CLASS}")
if elements:
titles = (
'\n - '
+ '\n - '.join([el.get_attribute('title') for el in elements])
titles = "\n - " + "\n - ".join(
[el.get_attribute("title") for el in elements]
)
hint = f'Visible diagnostics are: {titles}'
hint = f"Visible diagnostics are: {titles}"
else:
hint = 'No diagnostics were visible.'
hint = "No diagnostics were visible."
raise TimeoutException(
f'Diagnostic with selector {selector} not found in {timeout}.'
f'\n{hint}'
f"Diagnostic with selector {selector} not found in {timeout}." f"\n{hint}"
)


def wait_until_page_does_not_contain_diagnostic(selector, timeout='5s'):
def wait_until_page_does_not_contain_diagnostic(selector, timeout="5s"):
sl: SeleniumLibrary = BuiltIn().get_library_instance("SeleniumLibrary")
wait = WebDriverWait(sl.driver, timestr_to_secs(timeout))
return wait.until(
partial(page_contains_diagnostic, selector=selector, negate=True),
f'Diagnostic with selector {selector} still present after {timeout}'
f"Diagnostic with selector {selector} still present after {timeout}",
)
19 changes: 10 additions & 9 deletions atest/mouse_over_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def mouse_over_token_with_control(token_locator, x_wiggle=0):

action.key_action.key_down(Keys.CONTROL)

action.pointer_action.move_to_location(location['x'], location['y'])
action.pointer_action.move_to_location(location["x"], location["y"])
wiggle(action, x_wiggle)
action.key_action.key_up(Keys.CONTROL)

Expand All @@ -28,14 +28,14 @@ def mouse_over_token_and_wiggle(token_locator, x_wiggle=5):
sl: SeleniumLibrary = BuiltIn().get_library_instance("SeleniumLibrary")
action = ActionBuilder(sl.driver)
location = _find_text_in_line(token_locator)
action.pointer_action.move_to_location(location['x'], location['y'])
action.pointer_action.move_to_location(location["x"], location["y"])
wiggle(action, x_wiggle)
return action.perform()


def _find_text_in_line(token_locator: str):
which, text = token_locator.split(':', maxsplit=1)
assert which == 'lastToken'
which, text = token_locator.split(":", maxsplit=1)
assert which == "lastToken"
sl: SeleniumLibrary = BuiltIn().get_library_instance("SeleniumLibrary")
sl.driver.execute_script(
"""
Expand Down Expand Up @@ -83,9 +83,10 @@ def _find_text_in_line(token_locator: str):
y: (rect.top + rect.bottom) / 2
}
""",
text
text,
)


def _emit_over_text_in_line(token_locator: str, event: str):
sl: SeleniumLibrary = BuiltIn().get_library_instance("SeleniumLibrary")
location = _find_text_in_line(token_locator)
Expand All @@ -101,21 +102,21 @@ def _emit_over_text_in_line(token_locator: str, event: str):
location.parentElement.dispatchEvent(e);
""",
location,
event
event,
)


def mouse_over_token(token_locator: str):
sl: SeleniumLibrary = BuiltIn().get_library_instance("SeleniumLibrary")
action = ActionBuilder(sl.driver)
location = _find_text_in_line(token_locator)
action.pointer_action.move_to_location(location['x'], location['y'])
action.pointer_action.move_to_location(location["x"], location["y"])
return action.perform()


def click_token(token_locator: str):
return _emit_over_text_in_line(token_locator, event='click')
return _emit_over_text_in_line(token_locator, event="click")


def open_context_menu_over_token(token_locator: str):
return _emit_over_text_in_line(token_locator, event='contextmenu')
return _emit_over_text_in_line(token_locator, event="contextmenu")
20 changes: 13 additions & 7 deletions python_packages/jupyter_lsp/jupyter_lsp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class LanguageServerManager(LanguageServerManagerAPI):

autodetect: bool = Bool( # type:ignore[assignment]
True, help=_("try to find known language servers in sys.prefix (and elsewhere)")
).tag(
config=True
)
).tag(config=True)

sessions: Dict[Tuple[Text], LanguageServerSession] = Dict_( # type:ignore[assignment]
sessions: Dict[
Tuple[Text], LanguageServerSession
] = Dict_( # type:ignore[assignment]
trait=Instance(LanguageServerSession),
default_value={},
help="sessions keyed by language server name",
Expand All @@ -86,9 +86,15 @@ class LanguageServerManager(LanguageServerManagerAPI):
help="""Whether the manager has been initialized""", default_value=False
)

all_listeners = List_(trait=LoadableCallable).tag(config=True)
server_listeners = List_(trait=LoadableCallable).tag(config=True)
client_listeners = List_(trait=LoadableCallable).tag(config=True)
all_listeners = List_( # type:ignore[var-annotated]
trait=LoadableCallable # type:ignore[arg-type]
).tag(config=True)
server_listeners = List_( # type:ignore[var-annotated]
trait=LoadableCallable # type:ignore[arg-type]
).tag(config=True)
client_listeners = List_( # type:ignore[var-annotated]
trait=LoadableCallable # type:ignore[arg-type]
).tag(config=True)

@default("language_servers")
def _default_language_servers(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def test_normalize_posix_path_home_subdir(
],
)
def test_normalize_windows_path_case(root_dir, expected_root_uri): # pragma: no cover

try:
normalized = normalized_uri(root_dir)
except FileNotFoundError as err:
Expand Down
4 changes: 3 additions & 1 deletion python_packages/jupyter_lsp/jupyter_lsp/tests/test_stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def spawn_writer(
)
)
return subprocess.Popen(
[sys.executable, "-u", str(commands_file)], stdout=subprocess.PIPE, bufsize=0
[sys.executable, "-u", str(commands_file)],
stdout=subprocess.PIPE,
bufsize=0,
)


Expand Down
3 changes: 1 addition & 2 deletions python_packages/jupyter_lsp/jupyter_lsp/trait_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import six
import traitlets


Expand Down Expand Up @@ -34,7 +33,7 @@ def validate(self, obj, value):
except Exception:
self.error(obj, value)

if six.callable(value):
if callable(value):
return value
else:
self.error(obj, value)
13 changes: 9 additions & 4 deletions python_packages/jupyter_lsp/jupyter_lsp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
except ImportError: # pragma: no cover
from jupyter_server.transutils import _

from traitlets import Any as Any_
from traitlets import Instance
from traitlets import List as List_
from traitlets import Unicode, default
Expand Down Expand Up @@ -200,12 +201,16 @@ class LanguageServerManagerAPI(LoggingConfigurable, HasListeners):

nodejs = Unicode(help=_("path to nodejs executable")).tag(config=True)

node_roots = List_([], help=_("absolute paths in which to seek node_modules")).tag(
config=True
)
node_roots = List_(
trait=Any_(),
default_value=[],
help=_("absolute paths in which to seek node_modules"),
).tag(config=True)

extra_node_roots = List_(
[], help=_("additional absolute paths to seek node_modules first")
trait=Any_(),
default_value=[],
help=_("additional absolute paths to seek node_modules first"),
).tag(config=True)

def find_node_module(self, *path_frag):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class ShadowFilesystemError(ValueError):


def setup_shadow_filesystem(virtual_documents_uri: str):

if not virtual_documents_uri.startswith("file:/"):
raise ShadowFilesystemError( # pragma: no cover
'Virtual documents URI has to start with "file:/", got '
Expand Down
1 change: 0 additions & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ pyls-isort
pyls-mypy
pytest-cov
ruamel.yaml
types-six
1 change: 0 additions & 1 deletion requirements/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ dependencies:
- pytest-tornasync
- robotframework-robocop
- robotframework-tidy
- types-six
Loading