Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
30763: allow setting global options to None
Browse files Browse the repository at this point in the history
  • Loading branch information
mwageringel committed Oct 13, 2020
1 parent 8eec238 commit 4c08256
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions src/sage/structure/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def __bool__(self):
# for the less sensibly named python 2 family
__nonzero__ = __bool__

def __call__(self, value=None):
def __call__(self, *args, **kwds):
r"""
Get or set value of the option ``self``.
Expand All @@ -646,11 +646,53 @@ def __call__(self, value=None):
sage: Partitions.options.display() # indirect doctest
'exp_low'
sage: Partitions.options._reset()
TESTS:
Check that values can be set to ``None`` (:trac:`30763`)::
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()
42
sage: config.size(None)
sage: config.size() is None
True
sage: config._reset()
Check the deprecation::
sage: config.size(value=None)
doctest:...: DeprecationWarning: keyword argument "value" should be replaced by positional argument
See https://trac.sagemath.org/30763 for details.
sage: config.size() is None
True
sage: config.size(1, 2)
Traceback (most recent call last):
...
TypeError: option takes at most one argument "value"
sage: config.size(unknown=3)
Traceback (most recent call last):
...
TypeError: option takes at most one argument "value"
sage: config.size(4, value=5)
Traceback (most recent call last):
...
TypeError: option takes at most one argument "value"
"""
if value is None:
if not args and not kwds:
return self._options[self._name]
else:
self._options[self._name] = value
if 'value' in kwds:
from sage.misc.superseded import deprecation
deprecation(30763, 'keyword argument "value" should be replaced '
'by positional argument')
args += (kwds.pop('value'),)
if len(args) > 1 or kwds:
raise TypeError('option takes at most one argument "value"')
self._options[self._name] = args[0]

def __eq__(self, other):
r"""
Expand Down

0 comments on commit 4c08256

Please sign in to comment.