forked from ScreenPyHQ/screenpy_selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enabling ruff FBT (flake8-boolean-trap) and addressing ScreenPyHQ#44
- Loading branch information
1 parent
8f1bf79
commit 95647cd
Showing
9 changed files
with
141 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""module to hold shared objects.""" | ||
from __future__ import annotations | ||
|
||
import warnings | ||
from functools import wraps | ||
from typing import TYPE_CHECKING, Callable, ParamSpec, TypeVar | ||
|
||
if TYPE_CHECKING: | ||
P = ParamSpec("P") | ||
T = TypeVar("T") | ||
Function = Callable[P, T] | ||
|
||
|
||
def pos_args_deprecated(*keywords: str) -> Function: | ||
"""Warn users which positional arguments should be called via keyword.""" | ||
|
||
def deprecated(func: Function) -> Function: | ||
argnames = func.__code__.co_varnames[: func.__code__.co_argcount] | ||
i = min([argnames.index(kw) for kw in keywords]) | ||
kw_argnames = argnames[i:] | ||
|
||
@wraps(func) | ||
def wrapper(*args: P.args, **kwargs: P.kwargs) -> Function: | ||
# call the function first, to make sure the signature matches | ||
ret_value = func(*args, **kwargs) | ||
|
||
args_that_should_be_kw = args[i:] | ||
if args_that_should_be_kw: | ||
posargnames = ", ".join(kw_argnames) | ||
|
||
msg = ( | ||
f"Warning: positional arguments `{posargnames}` for " | ||
f"`{func.__qualname__}` are deprecated. " | ||
f"Please use keyword arguments instead." | ||
) | ||
warnings.warn(msg, DeprecationWarning, stacklevel=2) | ||
|
||
return ret_value | ||
|
||
return wrapper | ||
|
||
return deprecated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters