Skip to content

Handle predicates without __name__ in waitForEvent timeouts - #1034

Merged
xpconanfan merged 2 commits into
google:masterfrom
kwy404:fix-wait-for-event-predicate-name
Sep 27, 2026
Merged

xpconanfan merged 2 commits into
google:masterfrom
kwy404:fix-wait-for-event-predicate-name

Conversation

@kwy404

@kwy404 kwy404 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

When waitForEvent times out, it builds the error message from predicate.__name__. Callables such as functools.partial objects have no __name__, so instead of CallbackHandlerTimeoutError the caller got an AttributeError. This falls back to the callable's type name (for example partial) in CallbackHandlerBase. The added test with a partial predicate fails before the change and passes after it.

@xpconanfan

Copy link
Copy Markdown
Collaborator

Using repr(predicate) includes memory addresses and bound argument reprs (e.g., <my_module.MyPredicate object at 0x7f...> or functools.partial(<function foo at 0x7f...>, ...)), which makes timeout error messages noisy and harder to match in assertions. Can we fall back to the callable's type name instead?

    predicate_name = getattr(predicate, '__name__', type(predicate).__name__)

(Also, we are removing the deprecated mobly/controllers/android_device_lib/callback_handler.py in a separate PR, so you can drop the changes to callback_handler.py and callback_handler_test.py from this PR.)

@kwy404
kwy404 force-pushed the fix-wait-for-event-predicate-name branch from 9e9c9db to 86eaa10 Compare September 26, 2026 23:05
@kwy404

kwy404 commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, good point. Updated to fall back to type(predicate).__name__, and the test now checks that the message names the partial predicate. I also dropped the callback_handler.py change, so the PR only touches CallbackHandlerBase and its test.

@xpconanfan
xpconanfan self-requested a review September 26, 2026 23:09
@xpconanfan xpconanfan added the bug label Sep 26, 2026
@xpconanfan xpconanfan added this to the Mobly Release 1.14 milestone Sep 26, 2026
@xpconanfan
xpconanfan merged commit c42aa59 into google:master Sep 27, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants