Skip to content
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

Optionally disable sortand and deduplication of wildcards #89

Merged
merged 1 commit into from
May 28, 2023

Conversation

adieyal
Copy link
Owner

@adieyal adieyal commented May 27, 2023

To maintain backwards compatibility, by default wildcards are sorted and deduplicated but this functionality can be disabled.

@adieyal adieyal requested a review from akx May 27, 2023 11:28
@adieyal
Copy link
Owner Author

adieyal commented May 27, 2023

This is a pretty simple change. I would prefer to provide these settings in the constructor rather than setter methods, but until we can be confident that the extension will update the dynamicprompts library, I am hesitant to change method signatures. Thoughts?

@codecov-commenter
Copy link

codecov-commenter commented May 27, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (bd83ee7) 97.66% compared to head (e24c1ad) 97.67%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #89   +/-   ##
=======================================
  Coverage   97.66%   97.67%           
=======================================
  Files          70       70           
  Lines        2864     2876   +12     
=======================================
+ Hits         2797     2809   +12     
  Misses         67       67           
Impacted Files Coverage Δ
src/dynamicprompts/wildcards/wildcard_manager.py 97.43% <100.00%> (+0.21%) ⬆️
tests/wildcard/test_wildcardmanager.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@adieyal adieyal force-pushed the feature/disable-sorting-and-deduplication branch from 822804c to 3783f58 Compare May 27, 2023 12:07
Comment on lines 48 to 58
def set_sort_wildcards(self, value: bool):
"""
Set whether wildcard values should be sorted.
"""
self._sort_wildcards = value

def set_dedup_wildcards(self, value: bool):
"""
Set whether wildcard values should be deduplicated.
"""
self._dedup_wildcards = value
Copy link
Collaborator

Choose a reason for hiding this comment

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

def set_... doesn't smell very Pythonic. Maybe these should just be kwargs on WildcardManager's constructor, and the properties don't need to be _private either?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I should have marked this as draft, I don't really want to use setters - ideally I would prefer to use kwargs on the constructor but I'm nervous of another fiasco like we had earlier this week.

Re properties not being private, isn't that point behind setters and getters?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean, not **kwargs, but just

def __init__(
        self,
        path: Path | str | None = None,
        wildcard_wrap=default_parser_config.wildcard_wrap,
        *,
        root_map: RootMap | None = None,
        sort_wildcards: bool = True,
        deduplicate_wildcards: bool = True,
    ) -> None:

Since they're after the kwarg-only star, there's no chance of a downstream user accidentally passing them wrong, and the defaults would remain the current ones.

As for setters, sure, but then you'd do

@property
def sort_wildcards(self) -> bool:
    return self._sort_wildcards

@sort_wildcards.setter
def sort_wildcards(self, value) -> None:
    self._sort_wildcards = bool(value)
  • but better yet just not mark these as private since they are okay to fiddle with at runtime (unlike _path and _cache etc., for which the class holds some internal assumptions (e.g. _path and _tree and _root_map are tied together).

src/dynamicprompts/wildcards/wildcard_manager.py Outdated Show resolved Hide resolved
Comment on lines 48 to 58
def set_sort_wildcards(self, value: bool):
"""
Set whether wildcard values should be sorted.
"""
self._sort_wildcards = value

def set_dedup_wildcards(self, value: bool):
"""
Set whether wildcard values should be deduplicated.
"""
self._dedup_wildcards = value
Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean, not **kwargs, but just

def __init__(
        self,
        path: Path | str | None = None,
        wildcard_wrap=default_parser_config.wildcard_wrap,
        *,
        root_map: RootMap | None = None,
        sort_wildcards: bool = True,
        deduplicate_wildcards: bool = True,
    ) -> None:

Since they're after the kwarg-only star, there's no chance of a downstream user accidentally passing them wrong, and the defaults would remain the current ones.

As for setters, sure, but then you'd do

@property
def sort_wildcards(self) -> bool:
    return self._sort_wildcards

@sort_wildcards.setter
def sort_wildcards(self, value) -> None:
    self._sort_wildcards = bool(value)
  • but better yet just not mark these as private since they are okay to fiddle with at runtime (unlike _path and _cache etc., for which the class holds some internal assumptions (e.g. _path and _tree and _root_map are tied together).

@adieyal adieyal force-pushed the feature/disable-sorting-and-deduplication branch from eeba0ec to e24c1ad Compare May 28, 2023 13:20
@adieyal
Copy link
Owner Author

adieyal commented May 28, 2023

Re - kwarg *

Suppose we push this release. Then modify the extension to allow for toggling deduplication and sorting. If someone updates their extension but their dynamicprompts doesn't update, then the code will break since the signature doesn't accept these new parameters.

I think we should wait to update the extension until adieyal/sd-dynamic-prompts#449 is merged before updating the extension.

@akx akx merged commit 7789abe into main May 28, 2023
@akx akx deleted the feature/disable-sorting-and-deduplication branch May 28, 2023 14:13
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