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

Ruff q-z #46

Merged
merged 5 commits into from
Feb 7, 2024
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
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exclude = (?x)(
| docs/
)

[mypy-screenpy.*]
[mypy-screenpy_selenium.*]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

disallow_untyped_defs = True

[mypy-tests.*]
Expand Down
26 changes: 14 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ select = [
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
# "Q", # flake8-quotes
# "RET", # flake8-return
# "RSE", # flake8-raise
# "RUF", # ruff specific
# "SIM", # flake8-simplify
# "T10", # flake8-debugger
# "T20", # flake8-print
# "TCH", # flake8-type-checking
# "TRY", # tryceratops
# "UP", # python upgrade
"Q", # flake8-quotes
"RET", # flake8-return
"RSE", # flake8-raise
"RUF", # ruff specific
"SIM", # flake8-simplify
"T10", # flake8-debugger
"T20", # flake8-print
"TCH", # flake8-type-checking
"TRY", # tryceratops
"UP", # python upgrade
"W", # pycodestyle warning
# "YTT", # flake8-2020
"YTT", # flake8-2020

# we would like these someday, but not yet
# "FURB", # refurb
Expand All @@ -165,13 +165,15 @@ ignore = [
extend-safe-fixes = [
"EM101",
"EM102",
# "TCH001", "TCH002", "TCH003", "TCH004",
"TCH001", "TCH002", "TCH003", "TCH004",
# "SIM108"
# maybe?
# "F841",
"C419",
"D200", "D205", "D415",
"PT003", "PT006", "PT018",
"RET504",
"UP007",
]

[tool.ruff.lint.per-file-ignores]
Expand Down
18 changes: 10 additions & 8 deletions screenpy_selenium/abilities/browse_the_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from __future__ import annotations

import os
from typing import Type, TypeVar
from typing import TYPE_CHECKING, TypeVar

from selenium.webdriver import Chrome, Firefox, Remote, Safari
from selenium.webdriver.remote.webdriver import WebDriver

from ..exceptions import BrowsingError

if TYPE_CHECKING:
from selenium.webdriver.remote.webdriver import WebDriver

DEFAULT_APPIUM_HUB_URL = "http://localhost:4723/wd/hub"


Expand All @@ -33,22 +35,22 @@ class BrowseTheWeb:
browser: WebDriver

@classmethod
def using_chrome(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
def using_chrome(cls: type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
"""Create and use a default Chrome Selenium webdriver instance."""
return cls.using(browser=Chrome())

@classmethod
def using_firefox(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
def using_firefox(cls: type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
"""Create and use a default Firefox Selenium webdriver instance."""
return cls.using(browser=Firefox())

@classmethod
def using_safari(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
def using_safari(cls: type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
"""Create and use a default Safari Selenium webdriver instance."""
return cls.using(browser=Safari())

@classmethod
def using_ios(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
def using_ios(cls: type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
"""
Create and use a default Remote driver instance.

Expand Down Expand Up @@ -81,7 +83,7 @@ def using_ios(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
return cls.using(browser=Remote(hub_url, IOS_CAPABILITIES))

@classmethod
def using_android(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
def using_android(cls: type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
"""
Create and use a default Remote driver instance.

Expand Down Expand Up @@ -114,7 +116,7 @@ def using_android(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
return cls.using(browser=Remote(hub_url, ANDROID_CAPABILITIES))

@classmethod
def using(cls: Type[SelfBrowseTheWeb], browser: WebDriver) -> SelfBrowseTheWeb:
def using(cls: type[SelfBrowseTheWeb], browser: WebDriver) -> SelfBrowseTheWeb:
"""Provide an already-set-up WebDriver to use to browse the web."""
return cls(browser=browser)

Expand Down
6 changes: 5 additions & 1 deletion screenpy_selenium/actions/accept_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

from __future__ import annotations

from screenpy.actor import Actor
from typing import TYPE_CHECKING

from screenpy.pacing import aside, beat

from ..abilities import BrowseTheWeb

if TYPE_CHECKING:
from screenpy.actor import Actor


class AcceptAlert:
"""Accept an alert!
Expand Down
6 changes: 5 additions & 1 deletion screenpy_selenium/actions/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

from __future__ import annotations

from screenpy.actor import Actor
from typing import TYPE_CHECKING

from screenpy.exceptions import UnableToAct
from screenpy.pacing import beat
from selenium.webdriver.common.action_chains import ActionChains

from ..abilities import BrowseTheWeb
from ..protocols import Chainable

if TYPE_CHECKING:
from screenpy.actor import Actor


class Chain:
"""Group a series of chainable Actions together.
Expand Down
14 changes: 8 additions & 6 deletions screenpy_selenium/actions/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

from __future__ import annotations

from typing import Type, TypeVar
from typing import TYPE_CHECKING, TypeVar

from screenpy.actor import Actor
from screenpy.exceptions import DeliveryError
from screenpy.pacing import beat
from selenium.common.exceptions import WebDriverException

from ..target import Target
if TYPE_CHECKING:
from screenpy.actor import Actor

from ..target import Target

SelfClear = TypeVar("SelfClear", bound="Clear")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually move these TypeVar declarations into the TYPE_CHECKING block, too, if you want. Then you can also import the TypeVar in there.

I don't have strong opinions on it, but i do like that all the type checking stuff is contained within that block that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm about to yank all of those typevars out after the ruff changes.


Expand All @@ -26,7 +28,7 @@ class Clear:
"""

@classmethod
def the_text_from_the(cls: Type[SelfClear], target: Target) -> SelfClear:
def the_text_from_the(cls: type[SelfClear], target: Target) -> SelfClear:
"""
Specify the Target from which to clear the text.

Expand All @@ -37,13 +39,13 @@ def the_text_from_the(cls: Type[SelfClear], target: Target) -> SelfClear:
return cls(target=target)

@classmethod
def the_text_from(cls: Type[SelfClear], target: Target) -> SelfClear:
def the_text_from(cls: type[SelfClear], target: Target) -> SelfClear:
"""Alias for :meth:`~screenpy_selenium.actions.Clear.the_text_from_the`."""
return cls.the_text_from_the(target=target)

@classmethod
def the_text_from_the_first_of_the(
cls: Type[SelfClear], target: Target
cls: type[SelfClear], target: Target
) -> SelfClear:
"""Alias for :meth:`~screenpy_selenium.actions.Clear.the_text_from_the`."""
return cls.the_text_from_the(target=target)
Expand Down
18 changes: 10 additions & 8 deletions screenpy_selenium/actions/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

from __future__ import annotations

from typing import Optional, Type, TypeVar
from typing import TYPE_CHECKING, TypeVar

from screenpy.actor import Actor
from screenpy.exceptions import DeliveryError, UnableToAct
from screenpy.pacing import beat
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.action_chains import ActionChains

from ..target import Target
if TYPE_CHECKING:
from screenpy.actor import Actor
from selenium.webdriver.common.action_chains import ActionChains

from ..target import Target

SelfClick = TypeVar("SelfClick", bound="Click")

Expand All @@ -31,7 +33,7 @@ class Click:
"""

@classmethod
def on_the(cls: Type[SelfClick], target: Target) -> SelfClick:
def on_the(cls: type[SelfClick], target: Target) -> SelfClick:
"""
Target the element to click on.

Expand All @@ -42,12 +44,12 @@ def on_the(cls: Type[SelfClick], target: Target) -> SelfClick:
return cls(target=target)

@classmethod
def on(cls: Type[SelfClick], target: Target) -> SelfClick:
def on(cls: type[SelfClick], target: Target) -> SelfClick:
"""Alias for :meth:`~screenpy_selenium.actions.Click.on_the`."""
return cls.on_the(target=target)

@classmethod
def on_the_first_of_the(cls: Type[SelfClick], target: Target) -> SelfClick:
def on_the_first_of_the(cls: type[SelfClick], target: Target) -> SelfClick:
"""Alias for :meth:`~screenpy_selenium.actions.Click.on_the`."""
return cls.on_the(target=target)

Expand Down Expand Up @@ -88,6 +90,6 @@ def add_to_chain(

the_chain.click(on_element=the_element)

def __init__(self: SelfClick, target: Optional[Target] = None) -> None:
def __init__(self: SelfClick, target: Target | None = None) -> None:
self.target = target
self.description = f" on the {target}" if target is not None else ""
6 changes: 5 additions & 1 deletion screenpy_selenium/actions/dismiss_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

from __future__ import annotations

from screenpy.actor import Actor
from typing import TYPE_CHECKING

from screenpy.pacing import aside, beat

from ..abilities import BrowseTheWeb

if TYPE_CHECKING:
from screenpy.actor import Actor


class DismissAlert:
"""Dismiss an alert.
Expand Down
19 changes: 11 additions & 8 deletions screenpy_selenium/actions/double_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

from __future__ import annotations

from typing import Optional, Type, TypeVar
from typing import TYPE_CHECKING, TypeVar

from screenpy.actor import Actor
from screenpy.pacing import beat
from selenium.webdriver.common.action_chains import ActionChains

from ..abilities import BrowseTheWeb
from ..target import Target

if TYPE_CHECKING:
from screenpy.actor import Actor

from ..target import Target

SelfDoubleClick = TypeVar("SelfDoubleClick", bound="DoubleClick")

Expand All @@ -27,10 +30,10 @@ class DoubleClick:
the_actor.attempts_to(Chain(DoubleClick()))
"""

target: Optional[Target]
target: Target | None

@classmethod
def on_the(cls: Type[SelfDoubleClick], target: Target) -> SelfDoubleClick:
def on_the(cls: type[SelfDoubleClick], target: Target) -> SelfDoubleClick:
"""
Target the element to double-click on.

Expand All @@ -41,13 +44,13 @@ def on_the(cls: Type[SelfDoubleClick], target: Target) -> SelfDoubleClick:
return cls(target=target)

@classmethod
def on(cls: Type[SelfDoubleClick], target: Target) -> SelfDoubleClick:
def on(cls: type[SelfDoubleClick], target: Target) -> SelfDoubleClick:
"""Alias for :meth:`~screenpy_selenium.actions.DoubleClick.on_the`."""
return cls.on_the(target=target)

@classmethod
def on_the_first_of_the(
cls: Type[SelfDoubleClick], target: Target
cls: type[SelfDoubleClick], target: Target
) -> SelfDoubleClick:
"""Alias for :meth:`~screenpy_selenium.actions.DoubleClick.on_the`."""
return cls.on_the(target=target)
Expand Down Expand Up @@ -82,6 +85,6 @@ def add_to_chain(
"""Add the DoubleClick Action to a Chain of Actions."""
self._add_action_to_chain(the_actor, the_chain)

def __init__(self: SelfDoubleClick, target: Optional[Target] = None) -> None:
def __init__(self: SelfDoubleClick, target: Target | None = None) -> None:
self.target = target
self.description = f" on the {target}" if target is not None else ""
23 changes: 13 additions & 10 deletions screenpy_selenium/actions/enter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
from __future__ import annotations

from functools import partial
from typing import List, Optional, Type, TypeVar
from typing import TYPE_CHECKING, TypeVar

from screenpy import Actor
from screenpy.exceptions import DeliveryError, UnableToAct
from screenpy.pacing import aside, beat
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.action_chains import ActionChains

from ..speech_tools import KEY_NAMES
from ..target import Target

if TYPE_CHECKING:
from screenpy import Actor
from selenium.webdriver.common.action_chains import ActionChains

from ..target import Target

SelfEnter = TypeVar("SelfEnter", bound="Enter")

Expand All @@ -30,13 +33,13 @@ class Enter:
)
"""

target: Optional[Target]
following_keys: List[str]
target: Target | None
following_keys: list[str]
text: str
text_to_log: str

@classmethod
def the_text(cls: Type[SelfEnter], text: str) -> SelfEnter:
def the_text(cls: type[SelfEnter], text: str) -> SelfEnter:
"""Provide the text to enter into the field.

Aliases:
Expand All @@ -45,12 +48,12 @@ def the_text(cls: Type[SelfEnter], text: str) -> SelfEnter:
return cls(text=text)

@classmethod
def the_keys(cls: Type[SelfEnter], text: str) -> SelfEnter:
def the_keys(cls: type[SelfEnter], text: str) -> SelfEnter:
"""Alias for :meth:`~screenpy_selenium.actions.Enter.the_text`."""
return cls.the_text(text=text)

@classmethod
def the_secret(cls: Type[SelfEnter], text: str) -> SelfEnter:
def the_secret(cls: type[SelfEnter], text: str) -> SelfEnter:
"""
Provide the text to enter into the field, but mask it in logging.

Expand All @@ -62,7 +65,7 @@ def the_secret(cls: Type[SelfEnter], text: str) -> SelfEnter:
return cls(text=text, mask=True)

@classmethod
def the_password(cls: Type[SelfEnter], text: str) -> SelfEnter:
def the_password(cls: type[SelfEnter], text: str) -> SelfEnter:
"""Alias for :meth:`~screenpy_selenium.actions.Enter.the_secret`."""
return cls.the_secret(text=text)

Expand Down
Loading
Loading