Skip to content

Commit

Permalink
[#393] NEW: support python 3.10
Browse files Browse the repository at this point in the history
etc.:
- refactor a bit condition.call method implementation
- refactor from BrowserCondition = Condition[Browser] to class BrowserCondition(Condition[Browser]) to fix potential error «Subscripted generics cannot be used with class and instance checks»
  • Loading branch information
yashaka committed May 29, 2022
1 parent 07e6842 commit 04b90b7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@
- should we make original config (not shared) mutable?
- TODO: support python 3.10 [#393](https://github.com/yashaka/selene/issues/393)

## 2.0.0b2 (to be released on 29.03.2022)
## 2.0.0b4 (to be released on xx.06.2022)
- TODO: trim text in have.exact_text

## 2.0.0b3 (to be released on 29.05.2022)
- added support of python 3.10.* [#393](https://github.com/yashaka/selene/issues/393)

## 2.0.0b2 (released on 29.03.2022)
- first steps on simplifying the current browser management,
yet making it more powerful
- now you can pass a lambda to `browser.config.driver = HERE`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Tests with Selene can be built either in a simple straightforward "selenide' sty

## Versions

* Latest recommended version to use is >= [2.0.0b1](https://pypi.org/project/selene/2.0.0b1/)
* Latest recommended version to use is >= [2.0.0b3](https://pypi.org/project/selene/2.0.0b3/)
* it's a completely new version of selene, with improved API and speed
* supports 3.7 <= python <= 3.9,
* bundled with Selenium = 4.1
Expand Down
15 changes: 10 additions & 5 deletions selene/core/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@

from __future__ import annotations

from typing import List, TypeVar, Callable
import sys
from typing import List, TypeVar, Generic
if sys.version_info >= (3, 10):
from collections.abc import Callable
else:
from typing import Callable

from selene.core.exceptions import ConditionNotMatchedError
from selene.core.wait import Predicate, Lambda
Expand All @@ -32,7 +37,7 @@
R = TypeVar('R')


class Condition(Callable[[E], None]):
class Condition(Generic[E], Callable[[E], None]):
@classmethod
def by_and(cls, *conditions):
def fn(entity):
Expand Down Expand Up @@ -123,7 +128,7 @@ def __init__(self, description: str, fn: Lambda[E, None]):
self._fn = fn

def call(self, entity: E) -> None:
self._fn(entity)
self.__call__(entity)

@property
def predicate(self) -> Lambda[E, bool]:
Expand All @@ -140,8 +145,8 @@ def fn(entity):
def not_(self) -> Condition[E]: # todo: better name?
return self.__class__.as_not(self)

def __call__(self, *args, **kwargs):
return self._fn(*args, **kwargs)
def __call__(self, entity: E) -> None:
return self._fn(entity)

def __str__(self):
# todo: consider changing has to have on the fly for CollectionConditions
Expand Down
7 changes: 2 additions & 5 deletions selene/core/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,5 @@ class CollectionCondition(Condition[Collection]):
pass


# class BrowserCondition(Condition[Browser]):
# pass

# TODO: isn't below better than above?
BrowserCondition = Condition[Browser]
class BrowserCondition(Condition[Browser]):
pass
4 changes: 4 additions & 0 deletions selene/core/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@

class Assertable(ABC):
@abstractmethod
# TODO: shouldn't we type self too?
# see #generic-methods-and-generic-self
# at https://mypy.readthedocs.io/en/stable/generics.html
# def should(self: E, condition: Condition[E]) -> E:
def should(self, condition: Condition[E]) -> E:
pass

Expand Down

0 comments on commit 04b90b7

Please sign in to comment.