Repository navigation
Add service.call() and service.has_service() to the IDE stubs (#788) - #952
Open
craigbarratt wants to merge 1 commit into
Open
craigbarratt wants to merge 1 commit into
craigbarratt wants to merge 1 commit into
Conversation
The service stub was only the @service decorator function, so IDEs flagged service.call() and service.has_service(). It is now an object that works as the decorator, bare or with arguments, and also has typed call() and has_service() methods. The decorator keeps the decorated function's type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #788.
In
pyscript_builtins.py,servicewas only the@servicedecorator function, so IDEs and type checkers flaggedservice.call()andservice.has_service(), which pyscript provides at runtime.serviceis now an instance of a small_serviceclass:__call__has two overloads, for bare@serviceand for@service("DOMAIN.SERVICE", supports_response=...). Both keep the decorated function's type, so calls to it are still checked.call(domain, name, /, *, blocking=False, return_response=False, **kwargs)andhas_service(domain, name)matchFunction.service_callandservice_has_service.serviceis a real object, not only an annotation, sofrom stubs.pyscript_builtins import servicestill works if the file is imported by plain Python.Checked with mypy on a sample script using the stub: both decorator forms, a call to the decorated function,
service.call()with and withoutreturn_response, andservice.has_service()pass.service.call("light"), a decorated function called with the wrong type, andsupports_response="bad"are reported.Tests: a new test in
tests/test_stubs.pychecks that the stub'sserviceis callable and hascallandhas_service; it fails on master. All 308 tests pass, and ruff, pylint and mypy are clean.🤖 Generated with Claude Code