I want to fully type my Python project. But I'm stuck with a constructor that can be called with different parameters.
I've tried to remove the type from the final constructor, I've tried to remove some constructor... but still, get the same issue.
class PageObject(ABC):
logger = logging.getLogger(__name__)
@overload
def __init__(self, driver: Driver) -> None:
...
@overload
def __init__(self, by: Tuple[By, str], driver: Driver) -> None:
...
@overload
def __init__(self, context: WebElement, driver: Driver) -> None:
...
@overload
def __init__(self, by: Tuple[By, str], parent: "PageObject") -> None:
...
@overload
def __init__(self, parent: "PageObject") -> None:
...
def __init__(
self,
by: Optional[Tuple[By, str]] = None,
context: Optional[WebElement] = None,
parent: Optional["PageObject"] = None,
driver: Optional[Driver] = None,
) -> None:
if by and context:
raise ValueError("You cannot provide a locator AND a context.")
# ...
When I run mypy I got the following errors:
base/page_object.py:36: error: Overloaded function implementation does not accept all possible arguments of signature 1
base/page_object.py:36: error: Overloaded function implementation does not accept all possible arguments of signature 2
base/page_object.py:36: error: Overloaded function implementation does not accept all possible arguments of signature 3
base/page_object.py:36: error: Overloaded function implementation does not accept all possible arguments of signature 4
base/page_object.py:36: error: Overloaded function implementation does not accept all possible arguments of signature 5