fix(handlers): do not evaluate handler annotations in inspect.signature on Python 3.14 - #3204
Conversation
…re on Python 3.14 Since PEP 649 (Python 3.14), annotations are lazily evaluated and inspect.signature() resolves them eagerly by default. Event listeners and locator handlers annotated with names that only exist under `if TYPE_CHECKING:` therefore raised NameError when the signature was inspected, even though only the parameter list is needed. Ask for unresolved forward references instead. Fixes: microsoft/playwright#42857
|
The fix itself looks good. The tests fail the lint job, though: mypy and pyright reject the |
There was a problem hiding this comment.
Since both call sites are in shared _impl code, the sync mirrors don't add coverage. Let's drop the two tests/sync/ additions and keep just the async console and locator-handler tests.
…ions Replace the Unresolvable placeholder with the real handler types imported under `if TYPE_CHECKING:` and aliased, e.g. ConsoleMessage as TypeCheckingOnlyConsoleMessage. The alias stays undefined at runtime (still exercising PEP 649 lazy annotations) while mypy and pyright accept the handler signatures.
|
Done — replaced the placeholder with TYPE_CHECKING-only aliases of the real types ( |
Summary
inspect.signature()evaluates the lazily-computed annotations (PEP 649/749) by default, so event listeners and locator handlers annotated with names that only exist underif TYPE_CHECKING:raisedNameErrorwhen Playwright inspected the handler signature — even though only the parameter list is used.signature()compat helper that passesannotation_format=Format.FORWARDREFon Python 3.14+ and is a plaininspect.signature()on older versions, and use it at the two call sites (wrap_handler,LocatorHandler.__call__).Fixes microsoft/playwright#42857