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

Return True instead of None to avoid cachefunc being useless #39174

Merged
merged 2 commits into from
Dec 22, 2024

Conversation

user202729
Copy link
Contributor

@user202729 user202729 commented Dec 20, 2024

Just a trivial fix.

(probably just the tip of the iceberg though.)

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@user202729 user202729 marked this pull request as ready for review December 20, 2024 01:57
Copy link

Documentation preview for this PR (built with commit 91cf51d; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@mantepse
Copy link
Collaborator

I don't understand the remark:

Note that :func:cached_method does not work with methods returning None, so True is returned instead.

In what sense, and why?

@user202729
Copy link
Contributor Author

user202729 commented Dec 20, 2024

@mantepse It's explained in the documentation

cdef class CachedMethodCallerNoArgs(CachedFunction):
    """
    Utility class that is used by :class:`CachedMethod` to bind a
    cached method to an instance, in the case of a method that does
    not accept any arguments except ``self``.

    .. NOTE::

        The return value ``None`` would not be cached. So, if you have
        a method that does not accept arguments and may return ``None``
        after a lengthy computation, then ``@cached_method`` should not
        be used.

In practice, what happens is the thing will just be recomputed each time.

(I have a pending PR that adds a debug option to find all cases where the thing returns None. Apparently a lot of Sage code does that — small percentage, but still a lot.)

Copy link
Collaborator

@mantepse mantepse left a comment

Choose a reason for hiding this comment

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

Looks good! Thank's for catching!

@vbraun vbraun merged commit 291e54b into sagemath:develop Dec 22, 2024
21 of 23 checks passed
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