Skip to content

Commit

Permalink
[yashaka#393] python 3.10
Browse files Browse the repository at this point in the history
- fix type hints for Callable objects.
  • Loading branch information
aleksandr-kotlyar committed Oct 30, 2021
1 parent e316f83 commit 8bb3cfe
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 134 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ jobs:
test:
name: Test selene
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version: [ '3.7', '3.10' ]
env:
DISPLAY: ":99"
steps:
Expand All @@ -22,10 +26,10 @@ jobs:
poetry.lock
tests.yml
- name: Set up Python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: '3.7'
python-version: ${{ matrix.python-version }}
if: env.GIT_DIFF

# can be packaged as Docker-image
Expand Down
6 changes: 3 additions & 3 deletions selene/core/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
from selene.core.entity import Browser, Element, Collection


class ElementCondition(Condition[Element]):
class ElementCondition(Condition[[Element], None]):
pass


class CollectionCondition(Condition[Collection]):
class CollectionCondition(Condition[[Collection], None]):
pass


class BrowserCondition(Condition[Browser]):
class BrowserCondition(Condition[[Browser], None]):
pass
18 changes: 9 additions & 9 deletions selene/core/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def fn(element: Element):
# we need this method here in order to make autocompletion work...
# unfortunately the "base class" version is not enough
def should(
self, condition: Condition[Element], timeout: int = None
self, condition: Condition[[Element], None], timeout: int = None
) -> Element:
if timeout:
warnings.warn(
Expand Down Expand Up @@ -1014,7 +1014,7 @@ def to(self, stop: int) -> Collection:
return self[:stop]

def filtered_by(
self, condition: Union[Condition[Element], Callable[[E], None]]
self, condition: Union[Condition[[Element], None], Callable[[E], None]]
) -> Collection:
condition = (
condition
Expand All @@ -1037,7 +1037,7 @@ def filtered_by(
def filtered_by_their(
self,
selector_or_callable: Union[str, tuple, Callable[[Element], Element]],
condition: Condition[Element],
condition: Condition[[Element], None],
) -> Collection:
"""
:param selector_or_callable:
Expand Down Expand Up @@ -1100,7 +1100,7 @@ def find_in(parent: Element):
return self.filtered_by(lambda it: condition(find_in(it)))

def element_by(
self, condition: Union[Condition[Element], Callable[[E], None]]
self, condition: Union[Condition[[Element], None], Callable[[E], None]]
) -> Element:
# todo: In the implementation below...
# We use condition in context of "matching", i.e. as a predicate...
Expand Down Expand Up @@ -1162,7 +1162,7 @@ def find() -> WebElement:
def element_by_its(
self,
selector_or_callable: Union[str, tuple, Callable[[Element], Element]],
condition: Condition[Element],
condition: Condition[[Element], None],
) -> Element:
"""
:param selector_or_callable:
Expand Down Expand Up @@ -1318,7 +1318,7 @@ def collected(

def should(
self,
condition: Union[Condition[Collection], Condition[Element]],
condition: Union[Condition[[Collection], None], Condition[[Element], None]],
timeout: int = None,
) -> Collection:
if isinstance(condition, ElementCondition):
Expand Down Expand Up @@ -1361,21 +1361,21 @@ def caching(self) -> Collection:
)
return self.cached

def all_by(self, condition: Condition[Element]) -> Collection:
def all_by(self, condition: Condition[[Element], None]) -> Collection:
warnings.warn(
"deprecated; use `filtered_by` instead: browser.all('.foo').filtered_by(be.enabled)",
DeprecationWarning,
)
return self.filtered_by(condition)

def filter_by(self, condition: Condition[Element]) -> Collection:
def filter_by(self, condition: Condition[[Element], None]) -> Collection:
warnings.warn(
"deprecated; use `filtered_by` instead: browser.all('.foo').filtered_by(be.enabled)",
DeprecationWarning,
)
return self.filtered_by(condition)

def find_by(self, condition: Condition[Element]) -> Element:
def find_by(self, condition: Condition[[Element], None]) -> Element:
warnings.warn(
"deprecated; use `element_by` instead: browser.all('.foo').element_by(be.enabled)",
DeprecationWarning,
Expand Down
Loading

0 comments on commit 8bb3cfe

Please sign in to comment.