Skip to content

Commit 42af7c0

Browse files
Use the pyrefly strict preset (#1578)
* Make pyrefly error on unused ignore comments Pyrefly's unused-ignore rule is silent by default, so stale `# pyrefly: ignore` comments go unnoticed after upgrades. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Use the pyrefly strict preset The strict preset enables unused-ignore along with implicit-any, missing-override-decorator and other checks. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Keep vulture noqa comments on the decorator line Vulture reports decorated methods at the decorator's line, so the noqa comments must move up with the new @OverRide decorators. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Use the pyrefly all preset --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 33ac82d commit 42af7c0

6 files changed

Lines changed: 108 additions & 97 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ search_path = [
374374
"src",
375375
]
376376
errors.non-exhaustive-match = "error"
377+
preset = "all"
377378

378379
[tool.pyright]
379380
typeCheckingMode = "strict"

spelling_private_dict.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ macOS
1111
mypy
1212
noqa
1313
pragma
14+
pyrefly
1415
pyright
1516
reportDeprecated
17+
reportUnknownArgumentType
1618
reportUnknownMemberType
1719
vuforia
1820
vumark

src/vws_web_tools/__init__.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import re
77
import shlex
88
import uuid
9-
from collections.abc import Iterator, Sequence
9+
from collections.abc import Generator, Sequence
1010
from dataclasses import dataclass
1111
from pathlib import Path
12-
from typing import Any, TypedDict, TypeGuard
12+
from typing import TypedDict, TypeGuard
1313
from urllib.parse import quote, urlparse
1414

1515
import click
@@ -331,7 +331,7 @@ def create_license(
331331
),
332332
)
333333
confirm_button.click()
334-
sixty_second_wait.until(
334+
_ = sixty_second_wait.until(
335335
method=expected_conditions.url_changes(url=new_license_url),
336336
)
337337

@@ -359,12 +359,12 @@ def delete_license(
359359
),
360360
)
361361

362-
thirty_second_wait.until(
362+
_ = thirty_second_wait.until(
363363
method=expected_conditions.presence_of_element_located(
364364
locator=(By.ID, "table_search"),
365365
),
366366
)
367-
thirty_second_wait.until(
367+
_ = thirty_second_wait.until(
368368
method=expected_conditions.element_to_be_clickable(
369369
mark=(By.ID, "table_row_0_app_name"),
370370
),
@@ -398,7 +398,7 @@ def _click_license_row(
398398
),
399399
)
400400
row_texts = [row.text.strip() for row in rows]
401-
if not row_texts or not all(
401+
if len(row_texts) == 0 or not all(
402402
license_name in row_text for row_text in row_texts
403403
):
404404
return False
@@ -409,11 +409,11 @@ def _click_license_row(
409409
rows[row_texts.index(license_name)].click()
410410
return True
411411

412-
thirty_second_wait.until(
412+
_ = thirty_second_wait.until(
413413
method=lambda d: _click_license_row(driver=d),
414414
)
415415

416-
thirty_second_wait.until(
416+
_ = thirty_second_wait.until(
417417
method=expected_conditions.presence_of_element_located(
418418
locator=(By.ID, "license-header-name"),
419419
),
@@ -433,7 +433,7 @@ def _click_license_row(
433433
),
434434
)
435435
confirm_button.click()
436-
thirty_second_wait.until(
436+
_ = thirty_second_wait.until(
437437
method=expected_conditions.staleness_of(element=confirm_button),
438438
)
439439

@@ -464,13 +464,13 @@ def _open_add_database_dialog(
464464
)
465465

466466
add_database_button_id = "add-dialog-btn"
467-
thirty_second_wait.until(
467+
_ = thirty_second_wait.until(
468468
method=expected_conditions.presence_of_element_located(
469469
locator=(By.ID, add_database_button_id),
470470
),
471471
)
472472

473-
thirty_second_wait.until(
473+
_ = thirty_second_wait.until(
474474
method=expected_conditions.element_to_be_clickable(
475475
mark=(By.ID, add_database_button_id),
476476
),
@@ -492,7 +492,7 @@ def _open_add_database_dialog(
492492
):
493493
add_database_button_element.click()
494494
database_name_id = "database-name"
495-
thirty_second_wait.until(
495+
_ = thirty_second_wait.until(
496496
method=expected_conditions.presence_of_element_located(
497497
locator=(By.ID, database_name_id),
498498
),
@@ -518,7 +518,7 @@ def _submit_add_database_dialog(
518518
),
519519
)
520520
generate_button.click()
521-
wait.until(
521+
_ = wait.until(
522522
method=expected_conditions.staleness_of(element=generate_button),
523523
)
524524

@@ -687,7 +687,7 @@ def upload_vumark_template(
687687
StaleElementReferenceException,
688688
),
689689
)
690-
long_wait.until(
690+
_ = long_wait.until(
691691
method=expected_conditions.presence_of_element_located(
692692
locator=(By.XPATH, f"//*[{target_name_cell_predicate}]"),
693693
),
@@ -725,9 +725,9 @@ def _xpath_literal(
725725
apostrophe_literal = '"\'"'
726726
segments: list[str] = []
727727
for index, part in enumerate(iterable=value.split(sep="'")):
728-
if index:
728+
if index != 0:
729729
segments.append(apostrophe_literal)
730-
if part:
730+
if part != "":
731731
segments.append(f"'{part}'")
732732
joined_segments = ", ".join(segments)
733733
return f"concat({joined_segments})"
@@ -758,7 +758,7 @@ def _find_vumark_target_link(
758758
len(target_link_elements),
759759
target_name,
760760
)
761-
if not target_link_elements:
761+
if len(target_link_elements) == 0:
762762
message = (
763763
f"No link was found for the target named '{target_name}'. "
764764
"The target manager renders a target's name as plain text "
@@ -799,7 +799,7 @@ def _click_target_key_tab(driver: WebDriver) -> bool:
799799
target_key_tab.click()
800800
return True
801801

802-
wait.until(method=_click_target_key_tab)
802+
_ = wait.until(method=_click_target_key_tab)
803803

804804

805805
@_TIMEOUT_RETRY_DECORATOR
@@ -848,7 +848,7 @@ def _target_link_found(d: WebDriver) -> bool:
848848
),
849849
)
850850

851-
long_wait.until(
851+
_ = long_wait.until(
852852
method=_target_link_found,
853853
)
854854

@@ -889,7 +889,7 @@ def get_vumark_target_id(
889889
)
890890

891891
_open_target_key_tab(wait=short_wait)
892-
short_wait.until(
892+
_ = short_wait.until(
893893
method=expected_conditions.presence_of_element_located(
894894
locator=(By.ID, "table_search"),
895895
),
@@ -906,7 +906,7 @@ def get_vumark_target_id(
906906
# Wait for a link rather than for any element which matches, as the
907907
# target manager renders the target's name as plain text until the
908908
# target has finished processing, and only a link carries the ID.
909-
short_wait.until(
909+
_ = short_wait.until(
910910
method=expected_conditions.presence_of_element_located(
911911
locator=(By.XPATH, f"//a[{target_row_predicate}]"),
912912
),
@@ -919,7 +919,9 @@ def get_vumark_target_id(
919919

920920
url_path = urlparse(url=target_link).path
921921
target_id = url_path.rstrip("/").split(sep="/")[-1]
922-
if not _TARGET_ID_PATTERN.fullmatch(string=target_id): # pragma: no cover
922+
if ( # pragma: no cover
923+
_TARGET_ID_PATTERN.fullmatch(string=target_id) is None
924+
):
923925
message = (
924926
f"Expected the last path segment of the target link "
925927
f"'{target_link}' to be a target ID, but it was "
@@ -953,12 +955,12 @@ def navigate_to_database(
953955

954956
# The table search field needs ENTER to trigger filtering
955957
# in our Selenium runs.
956-
long_wait.until(
958+
_ = long_wait.until(
957959
method=expected_conditions.presence_of_element_located(
958960
locator=(By.ID, "table_search"),
959961
),
960962
)
961-
long_wait.until(
963+
_ = long_wait.until(
962964
method=expected_conditions.element_to_be_clickable(
963965
mark=(By.ID, "table_row_0_project_name"),
964966
),
@@ -991,7 +993,7 @@ def _click_database_row(
991993
),
992994
)
993995
row_texts = [row.text.strip() for row in rows]
994-
if not row_texts or not all(
996+
if len(row_texts) == 0 or not all(
995997
database_name in row_text for row_text in row_texts
996998
):
997999
return False
@@ -1002,7 +1004,7 @@ def _click_database_row(
10021004
rows[row_texts.index(database_name)].click()
10031005
return True
10041006

1005-
long_wait.until(method=lambda d: _click_database_row(driver=d))
1007+
_ = long_wait.until(method=lambda d: _click_database_row(driver=d))
10061008

10071009

10081010
@beartype
@@ -1068,7 +1070,7 @@ def navigate_to_license(
10681070
),
10691071
)
10701072

1071-
long_wait.until(
1073+
_ = long_wait.until(
10721074
method=expected_conditions.presence_of_element_located(
10731075
locator=(By.ID, "table_search"),
10741076
),
@@ -1100,7 +1102,7 @@ def _click_license_row(
11001102
element.click()
11011103
return True
11021104

1103-
long_wait.until(method=lambda d: _click_license_row(driver=d))
1105+
_ = long_wait.until(method=lambda d: _click_license_row(driver=d))
11041106

11051107

11061108
@_TIMEOUT_RETRY_DECORATOR
@@ -1147,7 +1149,7 @@ def _wait_for_access_keys(
11471149
key_ids: Sequence[str],
11481150
) -> None:
11491151
"""Wait for key sections to show an access key and a secret key."""
1150-
wait.until(
1152+
_ = wait.until(
11511153
method=lambda d: all(
11521154
len(
11531155
boxes := d.find_element(
@@ -1332,7 +1334,7 @@ def delete_model_target_web_api_client_credentials(
13321334
driver=driver,
13331335
)
13341336
encoded_client_id = quote(string=client_id, safe="")
1335-
_request(
1337+
_ = _request(
13361338
session=api_session.session,
13371339
method="DELETE",
13381340
url=(
@@ -1405,9 +1407,8 @@ def _requests_session_from_driver(
14051407
session.headers.update({"User-Agent": user_agent})
14061408

14071409
# https://github.com/SeleniumHQ/selenium/pull/17537
1408-
raw_cookies: Any = driver.get_cookies() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
1409-
cookies: object = raw_cookies
1410-
if not _is_json_array(cookies):
1410+
cookies: object = driver.get_cookies() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
1411+
if not _is_json_array(cookies): # pyright: ignore[reportUnknownArgumentType]
14111412
return session
14121413

14131414
# A cookie set for the current host has no ``domain`` attribute of
@@ -1429,9 +1430,9 @@ def _requests_session_from_driver(
14291430
cookie_kwargs = {
14301431
"path": path if isinstance(path, str) else "/",
14311432
}
1432-
if domain:
1433+
if domain is not None and domain != "":
14331434
cookie_kwargs["domain"] = domain
1434-
session.cookies.set(
1435+
_ = session.cookies.set(
14351436
name=name,
14361437
value=value,
14371438
**cookie_kwargs,
@@ -1463,7 +1464,7 @@ def _string_from_json(
14631464
for key in keys:
14641465
child = value.get(key)
14651466
if isinstance(child, str):
1466-
if child:
1467+
if child != "":
14671468
return child
14681469
# An object which has the key but with an empty value is
14691470
# the object we were looking for, and it is malformed.
@@ -1600,14 +1601,15 @@ def get_model_target_web_api_details(
16001601

16011602
# ``Generator[...]`` with defaulted type arguments is not valid at
16021603
# runtime on Python 3.12, which this package supports.
1603-
@contextlib.contextmanager # pyright: ignore[reportDeprecated]
1604+
@contextlib.contextmanager
16041605
@beartype
16051606
def model_target_web_api_details(
16061607
*,
16071608
driver: WebDriver,
16081609
scopes: Sequence[str] = MODEL_TARGET_WEB_API_STANDARD_SCOPES,
16091610
cad_data_url: str = MODEL_TARGET_WEB_API_CAD_DATA_URL,
1610-
) -> Iterator[ModelTargetWebAPIDict]:
1611+
# pylint: disable-next=unnecessary-default-type-args
1612+
) -> Generator[ModelTargetWebAPIDict, None, None]:
16111613
"""Yield Model Target Web API details, then delete the credential.
16121614
16131615
``get_model_target_web_api_details`` creates an OAuth2 client
@@ -1774,7 +1776,7 @@ def upload_vumark_template_to_database( # noqa: PLR0913
17741776
email_address=email_address,
17751777
password=password,
17761778
)
1777-
upload_vumark_template(
1779+
_ = upload_vumark_template(
17781780
driver=driver,
17791781
database_name=database_name,
17801782
svg_file_path=svg_file_path,

0 commit comments

Comments
 (0)