Repository navigation
fix(handlers): support non-attribute-writable callables in wrap_handler - #3341
Open
Alok Pandey (alok-108) wants to merge 1 commit into
Open
Alok Pandey (alok-108) wants to merge 1 commit into
Alok Pandey (alok-108) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Alok Pandey (alok-108)
force-pushed
the
fix/wrap-handler-non-writable-callables
branch
from
November 13, 2026 08:43
c5622ea to
0576b49
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3340
Problem
ImplToApiMapping.wrap_handler()cached wrappers by mutating_pw_impl_instance_*attributes ontohandlerorhandler.__self__viasetattr(). This raisedAttributeErrorwhen registering:list.append,print,len,set.__contains__,re.Pattern.match)method-wrapperobjects (str.__eq__)__slots__/@dataclass(slots=True)bound methods and callable instances@dataclass(frozen=True)bound methods and callable instancesSolution
ImplToApiMappinginstance in aweakref.WeakValueDictionaryinstead of setting_pw_impl_instance_*attributes on user objects.inspect.ismethod) and built-in/C bound methods (BuiltinFunctionType/MethodWrapperTypewith__self__) by receiver identity (id(__self__)) and underlying function/qualname metadata so repeated attribute lookups (messages.append,allowed.__contains__,collector.handle) return the identical wrapper forremove_listener()/unroute(), while keeping distinct instances isolated and preventing reference-cycle leaks.id(handler)for standalone functions, lambdas, callable instances (including unhashable slotted/frozen callables), and mocks (MagicMock).tests/sync/python/test_handlers.pyandtests/async/python/test_handlers.py.Verification
SKIP=pyright pre-commit run --files playwright/_impl/_impl_to_api_mapping.py tests/sync/python/test_handlers.py tests/async/python/test_handlers.py: all checked hooks passed (black,mypy,flake8,isort,Check License Header, AST/whitespace checks;pyrightrun separately below)npx --yes pyright@1.1.403 playwright/_impl/_impl_to_api_mapping.py tests/sync/python/test_handlers.py tests/async/python/test_handlers.py: 0 errors, 0 warnings, 0 informationsmypy --platform linux playwright: Success: no issues found in 105 source filespython scripts/check_test_registry.py: passedPW_CHECK_PROTOCOL=1 pytest tests/sync/python/ tests/sync/page/test_page_route.py tests/sync/page/test_page_event_console.py tests/sync/page/test_page_expose_function.py --browser=chromium: 136 passed, 4 skipped (3 WindowsSIGALRM, 1 WebKit-only), 1 xfailedPW_CHECK_PROTOCOL=1 pytest tests/async/python/test_handlers.py tests/async/python/test_listeners.py tests/async/python/test_console.py tests/async/python/test_issues.py tests/async/python/test_asyncio.py tests/async/page/test_page_route.py tests/async/page/test_page_event_console.py tests/async/page/test_page_expose_function.py --browser=chromium: 109 passed, 2 skipped (1 Python 3.14 PEP 649, 1 WebKit-only), 1 xfailedPW_CHECK_PROTOCOL=1 pytest tests/common/ --browser=chromium: 2 passed, 2 skipped (WindowsSIGINT)