Skip to content

Commit f8c4548

Browse files
authored
chore: improve expect.set_options timeout reset handling (#1981)
1 parent f1c11fb commit f8c4548

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

playwright/async_api/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
web automation that is ever-green, capable, reliable and fast.
1919
"""
2020

21-
from typing import Optional, Union, overload
21+
from typing import Any, Optional, Union, overload
2222

2323
import playwright._impl._api_structures
2424
import playwright._impl._api_types
@@ -88,10 +88,12 @@ def async_playwright() -> PlaywrightContextManager:
8888

8989

9090
class Expect:
91+
_unset: Any = object()
92+
9193
def __init__(self) -> None:
9294
self._timeout: Optional[float] = None
9395

94-
def set_options(self, timeout: float = None) -> None:
96+
def set_options(self, timeout: Optional[float] = _unset) -> None:
9597
"""
9698
This method sets global `expect()` options.
9799
@@ -101,7 +103,7 @@ def set_options(self, timeout: float = None) -> None:
101103
Returns:
102104
None
103105
"""
104-
if timeout is not None:
106+
if timeout is not self._unset:
105107
self._timeout = timeout
106108

107109
@overload

playwright/sync_api/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
web automation that is ever-green, capable, reliable and fast.
1919
"""
2020

21-
from typing import Optional, Union, overload
21+
from typing import Any, Optional, Union, overload
2222

2323
import playwright._impl._api_structures
2424
import playwright._impl._api_types
@@ -88,10 +88,12 @@ def sync_playwright() -> PlaywrightContextManager:
8888

8989

9090
class Expect:
91+
_unset: Any = object()
92+
9193
def __init__(self) -> None:
9294
self._timeout: Optional[float] = None
9395

94-
def set_options(self, timeout: float = None) -> None:
96+
def set_options(self, timeout: Optional[float] = _unset) -> None:
9597
"""
9698
This method sets global `expect()` options.
9799
@@ -101,7 +103,7 @@ def set_options(self, timeout: float = None) -> None:
101103
Returns:
102104
None
103105
"""
104-
if timeout is not None:
106+
if timeout is not self._unset:
105107
self._timeout = timeout
106108

107109
@overload

0 commit comments

Comments
 (0)