Skip to content

feat: Improve BlueapiClient to add plan parameter type hints#1469

Open
oliwenmandiamond wants to merge 19 commits into
mainfrom
Improve-BlueapiClient-plan-repr-to-add-parameter-types
Open

feat: Improve BlueapiClient to add plan parameter type hints#1469
oliwenmandiamond wants to merge 19 commits into
mainfrom
Improve-BlueapiClient-plan-repr-to-add-parameter-types

Conversation

@oliwenmandiamond

@oliwenmandiamond oliwenmandiamond commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #1505

Improves the help text for a plan to add the type hints and correct default values.

Before change:

>>> bc.plans.grid_analyserscan
grid_analyserscan(analyser, sequence, detectors, args, snake_axes=None, md=None)

>>> bc.plans.count
count(detectors, num=None, delay=None, metadata=None)

With this change

>>> bc.plans.grid_analyserscan
grid_analyserscan(
    analyser: ElectronAnalyserDetector,
    sequence: AbstractBaseSequence,
    detectors: list[Readable],
    args: Any,
    snake_axes: list[Any] | bool | None = None,
    md: dict | None = None
)

>>> bc.plans.count
count(
    detectors: list[Readable],
    num: int = 1,
    delay: float = 0,
    metadata: dict | None = None
)

@oliwenmandiamond oliwenmandiamond changed the title Imrpove BlueapiClient to add plan parameter type hints Improve BlueapiClient to add plan parameter type hints Apr 1, 2026
@codecov

codecov Bot commented Apr 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.72%. Comparing base (6d08154) to head (ac57232).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1469      +/-   ##
==========================================
+ Coverage   95.69%   95.72%   +0.03%     
==========================================
  Files          43       43              
  Lines        3226     3249      +23     
==========================================
+ Hits         3087     3110      +23     
  Misses        139      139              

☔ View full report in Codecov by Harness.
📢 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.

@oliwenmandiamond oliwenmandiamond changed the title Improve BlueapiClient to add plan parameter type hints feat: Improve BlueapiClient to add plan parameter type hints Apr 7, 2026
@oliwenmandiamond oliwenmandiamond marked this pull request as ready for review April 7, 2026 12:49
@oliwenmandiamond oliwenmandiamond requested a review from a team as a code owner April 7, 2026 12:49

@Alexj9837 Alexj9837 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good, made two comments and maybe add a test for the added value

"boolean": "bool",
"number": "float",
"object": "dict",
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would adding something here to deal with null / none

args.append(arg)

single_line = f"{self.name}({', '.join(args)})"
max_length = 100

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not a huge fan of magic numbers, also will these change? could we set the vars to _REPR_MAX_LENGTH and _REPR_MAX_ARGS_INLINE

@tpoliaw tpoliaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this. I agree that the current repr isn't great but trying to perfectly replicate the function signature is going to lead to edge cases where things don't behave, for instance this gives detectors: list[Readable] for an argument that expects a list of strings (or DeviceRefs). (Possibly fixed by #1121?)

I think this is coming back to a python function not being a perfect fit for an API endpoint. For count, we want group to be optional but we don't want the default to be in the signature (as it makes the schema invalid). I think it would be better if the repr for plans stopped trying to be a signature and became something like Plan("count", (movable, value, group, wait)) and the type/default information was in the description (available via help(bc.plans.count)) as it is already.

If the type stubs PR is merged it could go some of the way towards improving usability. For the 'optional but no default' cases we could have an Unspecified object or similar.

@EmsArnold, you've used the client in a repl a fair bit as well - any thoughts on usability vs correctness?


@property
def properties(self) -> set[str]:
def properties(self) -> dict[str, Any]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This still returns a set, no? To be strictly correct, it should probably be dict_keys or collections.abc.Set.

Alternatively make it actually return the whole properties dict

props = self.model.parameter_schema.get("properties", {})
required = set(self.required)

tab = " "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tab = <not a tab> is questionable

Suggested change
tab = " "
indent = " "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we want to be careful that we're not making an invalid schema. With these changes the schema contains several fields such as

"group": {
    "title": "Group",
    "type": "string",
    "default": null
},

which in turn causes your repr to contain parameters such as metadata: dict = None which is not correctly typed.

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.

BlueapiClient doesn't report the correct default values or display types for plans

3 participants