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

improve setting global options to None #30763

Closed
mwageringel opened this issue Oct 13, 2020 · 12 comments
Closed

improve setting global options to None #30763

mwageringel opened this issue Oct 13, 2020 · 12 comments

Comments

@mwageringel
Copy link

The __call__ method of global options is used as getter and setter. This ticket improves this method to properly handle values of None.

For example:

sage: from sage.structure.global_options import GlobalOptions
sage: class config(GlobalOptions):
....:     size = dict(default=42,
....:                 description='integer or None',
....:                 checker=lambda val: val is None or val >= 0)
sage: config.size(None)  # this should set the option to `None`
42

(See #30755 for an actual example where None is used as a value.)

This can be used as a workaround instead:

sage: config.size = None
sage: config.size() is None
True

This ticket makes config.size(None) work as a setter. Additionally, a deprecation is added for the keyword-argument syntax config.size(value=None), as it is not usually used and this will simplify the implementation a little.

Component: misc

Author: Markus Wageringel

Branch/Commit: 4c08256

Reviewer: Vincent Delecroix

Issue created by migration from https://trac.sagemath.org/ticket/30763

@mwageringel mwageringel added this to the sage-9.3 milestone Oct 13, 2020
@mwageringel
Copy link
Author

Author: Markus Wageringel

@mwageringel
Copy link
Author

Commit: 4c08256

@mwageringel
Copy link
Author

New commits:

4c0825630763: allow setting global options to None

@mwageringel
Copy link
Author

Branch: u/gh-mwageringel/30763

@mkoeppe
Copy link
Contributor

mkoeppe commented Nov 30, 2020

comment:2

Wouldn't it be simpler to just use a unique object instead of None as the default argument? Then no change of the interface is necessary

@mwageringel
Copy link
Author

comment:3

Well, yes, but I think that it is common to use None as a default value/no preferred choice. For example, in Sage, this is the case for the preferences of the display manager (though, these are distinct from GlobalOptions).

Note that, in the example from the description, config.size() still keeps working as a getter, so the interface does not really change.

@mkoeppe
Copy link
Contributor

mkoeppe commented Mar 15, 2021

comment:4

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

@mkoeppe mkoeppe modified the milestones: sage-9.3, sage-9.4 Mar 15, 2021
@mkoeppe
Copy link
Contributor

mkoeppe commented Jul 19, 2021

comment:5

Setting a new milestone for this ticket based on a cursory review.

@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Jul 19, 2021
@mkoeppe
Copy link
Contributor

mkoeppe commented Dec 18, 2021

comment:6

Stalled in needs_review or needs_info; likely won't make it into Sage 9.5.

@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@videlec
Copy link
Contributor

videlec commented Dec 29, 2021

comment:7

The proposed change is reasonable and simplifies (actually will simplify in the future) the implementation of __call__.

@videlec
Copy link
Contributor

videlec commented Dec 29, 2021

Reviewer: Vincent Delecroix

@vbraun
Copy link
Member

vbraun commented Feb 16, 2022

Changed branch from u/gh-mwageringel/30763 to 4c08256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants