Skip to content

[Feature] Pyright strict mode compatibility #1532

@jcheng5

Description

@jcheng5

Hi! I'm trying to use playwright with my codebase, which uses pyright in strict mode. I'm finding that assertions in the sync API make pyright unhappy, because NoneType turns into Unknown:

# pyright: strict

from playwright.sync_api import Page, expect


def test_app(page: Page):
    page.goto("http://127.0.0.1:8000/")
    plot = page.locator("#plot")
    expect(plot).to_have_class("text-center")
$ pyright
No configuration file found.
No pyproject.toml file found.
stubPath /Users/jcheng/Development/jcheng5/nonetype-test/typings is not a valid directory.
Assuming Python platform Darwin
Searching for source files
Found 1 source file
pyright 1.1.268
/Users/jcheng/Development/jcheng5/nonetype-test/test_playwright.py
  /Users/jcheng/Development/jcheng5/nonetype-test/test_playwright.py:9:5 - error: Type of "to_have_class" is partially unknown
    Type of "to_have_class" is "(expected: List[Pattern[str] | str] | Pattern[str] | str, *, timeout: float | None = None) -> Unknown" (reportUnknownMemberType)
1 error, 0 warnings, 0 informations
Completed in 0.634sec

If I replace all the NoneType annotations in playwright/sync_api/_generated.py with None, the error goes away.

(I just want to add, this is the only problem I've run into with playwright so far--in every other respect it's been a pleasure to use!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions