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

Deprecate Selector's compute_default_fn slot and compute_default() method #1012

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maximlt
Copy link
Member

@maximlt maximlt commented Jan 17, 2025

As suggested in #508 (comment).

@maximlt maximlt added this to the v2.3.0 milestone Jan 17, 2025
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.26%. Comparing base (8095bb3) to head (9f32e5e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1012      +/-   ##
==========================================
+ Coverage   87.25%   87.26%   +0.01%     
==========================================
  Files           9        9              
  Lines        4928     4932       +4     
==========================================
+ Hits         4300     4304       +4     
  Misses        628      628              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@maximlt
Copy link
Member Author

maximlt commented Feb 11, 2025

@philippjfr @jbednar do you agree with this deprecation?

Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

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

I agree with this deprecation (and in fact I think I suggested it a while back :-) ). I see you've removed documentation of the old way to do it, so I assume that the new way to do it has already been documented appropriately in a separate PR?

@maximlt
Copy link
Member Author

maximlt commented Feb 12, 2025

I agree with this deprecation (and in fact I think I suggested it a while back :-) ). I see you've removed documentation of the old way to do it, so I assume that the new way to do it has already been documented appropriately in a separate PR?

I'm working separately on default_factory but haven't opened a PR yet (you will know about it!). The main motivation for deprecating compute_default_fn/compute_defaut() is that it is imo a weird API and it appears to be unused (see more details in #508 (comment), with only 3 occurrences found on Github in topographica). As such I don't see a need to document how to reproduce what this feature was achieving. For the users who might need this feature, they can easily reproduce it as the code is trivial:

    def compute_default(self):
        """
        If this parameter's compute_default_fn is callable, call it
        and store the result in self.default.

        Also removes None from the list of objects (if the default is
        no longer None).
        """
        if self.default is None and callable(self.compute_default_fn):
            self.default = self.compute_default_fn()
            self._ensure_value_is_in_objects(self.default)

    def _ensure_value_is_in_objects(self, val):
        """
        Make sure that the provided value is present on the objects list.
        Subclasses can override if they support multiple items on a list,
        to check each item instead.
        """
        if val not in self.objects:
            self._objects.append(val)

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.

2 participants