-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow List[str]
in DockerContainerListFilters['filters']
and format_dict_for_cli()
#590
Closed
LooLzzz
wants to merge
1
commit into
gabrieldemarmiesse:master
from
LooLzzz:allow-list-of-str-in-docker-container-list-filters
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem I have with this is it special-cases
label
, when actually it's presumably valid to specify any of the filter types more than once? It seems like conceptually what we want is to allow specifying the same key twice, but that's not possible with normal dicts in python of course.Any thoughts @gabrieldemarmiesse on how to resolve this? One option would be to accept a list of 2-tuples instead of a dict, i.e. something like
docker.container.list(filters: Sequence[DockerContainerListFilters])
whereDockerContainerListFilters = tuple[Literal["id"], str] | tuple[Literal["name"], str] | ...
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to be backward compatible (and also because it's easy to write), we can apply the
Union[str, List[str]]
to all values in the TypedDict. So what's done in this PR, but for all elements. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I don't like about that is it's not truly mirroring the CLI (you don't specify
--filter label=foo,bar
), so it feels like sacrificing the quality of the API for minor backwards compatibility (could easily enough continue to support the old form until v1.0 if we wanted). Perhaps not all fields would make sense to be specified more than once, is that something we'd need to think about in your suggested approach?A couple of other notes on this API:
name
field, should that bereference
? (https://docs.docker.com/reference/cli/docker/image/ls/#filter, https://docs.podman.io/en/stable/markdown/podman-images.1.html#filter-f-filter)--filter label!=foo
, which the current API does not support[EDIT: realised I was looking at the image list APIs rather than container list, oops]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be worth a redesign from scratch possibly... As we're pre-1.0 I believe we can afford it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe chained calls would suite this API better?
Many ORMs are using this style of API
The actual evaluation is only performed when some magic method is called,
like
__repr__
/__str__
/__list__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lazy evaluation approach has downsides that make me hesitant:
I still think we should go for:
(Note that the CLI is a bit confusing here in that label filters are ANDed together whereas status filters are ORed together).