Skip to content

[Bug]: Page.expect_event signature is missing generics #3047

@DetachHead

Description

@DetachHead

Version

1.58.0

Steps to reproduce

# pyright: reportUnknownMemberType=true

from playwright.sync_api import sync_playwright

with sync_playwright() as pw:
    page = pw.chromium.launch().new_page()
    with page.expect_event("requestfinished"):
        ...

this causes the following pyright error:

Type of "expect_event" is partially unknown
  Type of "expect_event" is "(event: str, predicate: ((...) -> Unknown) | None = None, *, timeout: float | None = None) -> EventContextManager[Unknown]"

the fix would be to add overloads for each event, eg:

@overload
def expect_event(
    self,
    event: Literal["requestfinished"],
    predicate: typing.Optional[typing.Callable[[Request], bool] = None,
    *,
    timeout: typing.Optional[float] = None,
) -> EventContextManager[Request]: ...

Expected behavior

no error

Actual behavior

Type of "expect_event" is partially unknown
  Type of "expect_event" is "(event: str, predicate: ((...) -> Unknown) | None = None, *, timeout: float | None = None) -> EventContextManager[Unknown]"

Additional context

No response

Environment

- Operating System: N/A
- CPU: N/A
- Browser: N/A
- Python Version: 3.14
- Other info:

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions