Skip to content

Commit edd04f2

Browse files
committed
document the differences in method signatures between impl and api
1 parent ecd0d43 commit edd04f2

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

CONTRIBUTING.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,63 @@ pre-commit run --all-files
4949

5050
For more details look at the [CI configuration](./blob/master/.github/workflows/ci.yml).
5151

52-
### Regenerating APIs
52+
### APIs
53+
54+
#### Regenerating
5355

5456
```bash
5557
./scripts/update_api.sh
5658
pre-commit run --all-files
5759
```
5860

61+
#### Differences between `_impl` and exposed API method signatures
62+
63+
- optional arguments are automatically converted to keyword arguments, unless the method has overloads. for example:
64+
```py
65+
def wait_for_selector(self, selector: str, timeout: float = None, state: str = None): ...
66+
```
67+
becomes
68+
```py
69+
def wait_for_selector(self, selector: str, *, timeout: float = None, state: str = None): ...
70+
```
71+
72+
- overloads must be defined using `@api_overload` in order for the generate scripts to be able to see them at runtime.
73+
```py
74+
from playwright._impl._overload import api_overload
75+
76+
@api_overload
77+
async def wait_for_selector(
78+
self,
79+
selector: str,
80+
*,
81+
timeout: float = None,
82+
state: Literal["attached", "visible"] = None,
83+
strict: bool = None,
84+
) -> ElementHandle:
85+
pass
86+
87+
@api_overload # type: ignore[no-redef]
88+
async def wait_for_selector(
89+
self,
90+
selector: str,
91+
*,
92+
timeout: float = None,
93+
state: Literal["detached", "hidden"],
94+
strict: bool = None,
95+
) -> None:
96+
pass
97+
98+
async def wait_for_selector( # type: ignore[no-redef]
99+
self,
100+
selector: str,
101+
*,
102+
timeout: float = None,
103+
state: Literal["attached", "detached", "hidden", "visible"] = None,
104+
strict: bool = None,
105+
) -> Optional[ElementHandle]:
106+
...
107+
```
108+
59109
## Contributor License Agreement
60110

61111
This project welcomes contributions and suggestions. Most contributions require you to agree to a

0 commit comments

Comments
 (0)