Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bdrx312
Copy link
Contributor

@bdrx312 bdrx312 commented Oct 4, 2025

Also add some more type hints and change some format calls to f strings. Fix state retry tests with invalid assumptions of duration and comment.

What does this PR do?

Adds the ability to specify arguments to a state as a dictionary instead of having to specify a list of individual key: value pairs

What issues does this PR fix or reference?

Fixes #68367

Previous Behavior

Could only specify arguments to a state like this

id1:
  cmd.run:
    - name: echo testing
    - umask: '0'

New Behavior

Can specify arguments to a state like this

id1:
  cmd.run:
    name: echo testing
    umask: '0'

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

No

@bdrx312 bdrx312 requested a review from a team as a code owner October 4, 2025 02:50
@bdrx312 bdrx312 force-pushed the support_state_args_dict branch from b2a27d9 to a8b7362 Compare October 4, 2025 18:09
@barneysowood barneysowood added the test:full Run the full test suite label Oct 5, 2025
Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

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

I still think we should update the docs to show the new dict method in addition to the list method.

@bdrx312
Copy link
Contributor Author

bdrx312 commented Oct 31, 2025

I still think we should update the docs to show the new dict method in addition to the list method.

Alright I'll look at updating docs when I get some time.

Copy link
Contributor

@lkubb lkubb left a comment

Choose a reason for hiding this comment

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

Thanks for creating this! Just some minor comments.

salt/state.py Outdated
K = TypeVar("K")
V = TypeVar("V")
Pair = tuple[K, V]
HighDataStateArgsDef = Union[Mapping[K, V], Iterable[Union[Mapping[K, V], 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
HighDataStateArgsDef = Union[Mapping[K, V], Iterable[Union[Mapping[K, V], str]]]
HighDataStateArgsDef = Mapping[K, V] | Iterable[Mapping[K, V] | str]

Minor suggestion: AFAIK 3008.0 is Python 3.10+ only, so you can use the | type operator. Unsure why pyupgrade does not catch this.

salt/state.py Outdated
self.states[
"{}.{}".format(low["state"], low["fun"])
] # pylint: disable=W0106
self.states[f"{low['state']}.{low['fun']}"] # pylint: disable=W0106
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: (inherited from the old code) This should have been # pylint: disable=expression-not-assigned (for clarity), but might need # pylint: disable=pointless-statement now. Maybe you can try removing the disable and see if it's necessary at all.

Also add some more type hints and change some format calls to f strings.
Fix state retry tests with invalid assumptions of duration and comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants