Skip to content

Generate cache type stubs to help edit user scripts#1338

Draft
tpoliaw wants to merge 39 commits intomainfrom
cache-stubs
Draft

Generate cache type stubs to help edit user scripts#1338
tpoliaw wants to merge 39 commits intomainfrom
cache-stubs

Conversation

@tpoliaw
Copy link
Contributor

@tpoliaw tpoliaw commented Jan 15, 2026

When editing scripts that make use of the dynamic plan/device access in
the new client, there is no type checking available by default (as the
available plans are unknown). This adds a subcommand to generate a
type-stubs package for the currently running server to help write scripts.

blueapi generate-stubs /tmp/blueapi-stubs
pip install --editable /tmp/blueapi-stubs

type checkers and LSPs will then be able to check scripts for correct plan
names/arguments/etc as well as providing completions while editing.

@tpoliaw tpoliaw changed the base branch from main to user-client January 15, 2026 22:53
@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.32%. Comparing base (f752763) to head (6faf01c).

Additional details and impacted files
@@               Coverage Diff               @@
##           user-client    #1338      +/-   ##
===============================================
+ Coverage        95.16%   95.32%   +0.15%     
===============================================
  Files               43       45       +2     
  Lines             3002     3099      +97     
===============================================
+ Hits              2857     2954      +97     
  Misses             145      145              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tpoliaw tpoliaw force-pushed the user-client branch 3 times, most recently from 2af7483 to cb9ed3e Compare February 11, 2026 10:55
Mainly to make supporting type stubs easier
When editing scripts that make use of the dynamic plan/device access in
the new client, there is no type checking available by default (as the
available plans are unknown. This adds a subcommand to generate a
type-stubs package for the currently running server to help write scripts.

    blueapi generate-stubs /tmp/blueapi-stubs
    pip install --editable /tmp/blueapi-stubs

type checkers and LSPs will then be able to check scripts for correct plan
names/arguments/etc as well as providing completions while editing.
Enable testing with StringIO
It was already included via fastapi but if we're using it directly we should
probably include it.
instance.model = model
instance._cache = cache
return instance

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __getattribute__(self, name: str) -> Any:
if name.startswith("_"):
return super().__getattribute__(name)
if name == "model":
return super().__getattribute__(name)
return self._cache[f"{self}.{name}"]

we added this to address device access auto completes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was to avoid str methods preventing sub-devices being accessed. I do not like how this is done - there might be some way of getting custom data types to serialize correctly.

def __repr__(self) -> str: ...


class DeviceRef(str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class DeviceRef(str):
class DeviceRef:

Base automatically changed from user-client to main February 18, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments