Skip to content

Fix handling of default parameters in plans#185

Merged
tpoliaw merged 3 commits intoDiamondLightSource:mainfrom
tpoliaw:default_args
May 12, 2023
Merged

Fix handling of default parameters in plans#185
tpoliaw merged 3 commits intoDiamondLightSource:mainfrom
tpoliaw:default_args

Conversation

@tpoliaw
Copy link
Copy Markdown
Contributor

@tpoliaw tpoliaw commented May 12, 2023

Passing None as the default for a field sets the default to None and
is different to there being no default.

If a default value is given, it is now returned via a default_factory.
This is required to prevent pydantic errors when the default is an ophyd
device.

@tpoliaw tpoliaw requested a review from DiamondJoseph May 12, 2023 09:22
@DiamondJoseph
Copy link
Copy Markdown
Contributor

Closes #182

Copy link
Copy Markdown
Contributor

@callumforrester callumforrester left a comment

Choose a reason for hiding this comment

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

Makes sense, not sure why CI is unhappy. Could we also have a test for this use case?

@tpoliaw
Copy link
Copy Markdown
Contributor Author

tpoliaw commented May 12, 2023

not sure why CI is unhappy

Because lambda x: x != lambda x: x

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2023

Codecov Report

Merging #185 (a1cc6db) into main (f3fe4b1) will increase coverage by 0.03%.
The diff coverage is 92.30%.

@@            Coverage Diff             @@
##             main     #185      +/-   ##
==========================================
+ Coverage   87.53%   87.56%   +0.03%     
==========================================
  Files          41       41              
  Lines        1091     1102      +11     
==========================================
+ Hits          955      965      +10     
- Misses        136      137       +1     
Impacted Files Coverage Δ
src/blueapi/core/context.py 94.94% <92.30%> (-0.51%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

tpoliaw added 3 commits May 12, 2023 11:50
Passing `None` as the default for a field sets the default to None and
is different to there being no default.

If a default value is given, it is now returned via a default_factory.
This is required to prevent pydantic errors when the default is an ophyd
device.
Changing the plan parameter spec to use FieldInfo instead of returning
default values meant that comparisons in tests did not behave as
required. This adds a Callable wrapper class that allows the internal
value to be inspected/compared.
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.

3 participants