Skip to content

Commit ac5cd71

Browse files
committed
Use stack(0) in more places, to avoid requesting expensive stack context information
1 parent 9ab4db2 commit ac5cd71

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

playwright/_impl/_network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ async def _race_with_page_close(self, future: Coroutine) -> None:
530530
setattr(
531531
fut,
532532
"__pw_stack__",
533-
getattr(asyncio.current_task(self._loop), "__pw_stack__", inspect.stack()),
533+
getattr(asyncio.current_task(self._loop), "__pw_stack__", inspect.stack(0)),
534534
)
535535
target_closed_future = self.request._target_closed_future()
536536
await asyncio.wait(

playwright/_impl/_path_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
import inspect
1616
from pathlib import Path
17+
from types import FrameType
18+
from typing import cast
1719

1820

1921
def get_file_dirname() -> Path:
2022
"""Returns the callee (`__file__`) directory name"""
21-
frame = inspect.stack()[1]
22-
module = inspect.getmodule(frame[0])
23+
frame = cast(FrameType, inspect.currentframe()).f_back
24+
module = inspect.getmodule(frame)
2325
assert module
2426
assert module.__file__
2527
return Path(module.__file__).parent.absolute()

playwright/_impl/_sync_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _sync(
105105

106106
g_self = greenlet.getcurrent()
107107
task: asyncio.tasks.Task[Any] = self._loop.create_task(coro)
108-
setattr(task, "__pw_stack__", inspect.stack())
108+
setattr(task, "__pw_stack__", inspect.stack(0))
109109
setattr(task, "__pw_stack_trace__", traceback.extract_stack())
110110

111111
task.add_done_callback(lambda _: g_self.switch())

0 commit comments

Comments
 (0)