Skip to content

Commit

Permalink
sagemathgh-36811: fixed warning while calling OEISSequence.is_dead() …
Browse files Browse the repository at this point in the history
…function

    
Fixes sagemath#36795
fixed warning in OEISSequence.is_dead() function in OEISSequence

added a parameter warn=True in _field function
and changed self.is_dead(warn_only=True) to self.is_dead(warn_only=warn)
inside the _field function,
changed the self._field('K') to self._field('K', warn=False)
so the warning is not triggered
    
URL: sagemath#36811
Reported by: Aman Moon
Reviewer(s): Martin Rubey
  • Loading branch information
Release Manager committed Dec 24, 2023
2 parents 4de80ba + 8f9af0b commit 0d4d4f8
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/sage/databases/oeis.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def online_update(self):
except AttributeError:
pass

def _field(self, key):
def _field(self, key, warn=True):
r"""
Return the ``key`` field of the entry of ``self``.
Expand All @@ -741,7 +741,7 @@ def _field(self, key):
for line in self.raw_entry().splitlines():
fields[line[1]].append(line[11:])
self._fields = fields
self.is_dead(warn_only=True)
self.is_dead(warn_only=warn)
return self._fields[key]

def id(self, format='A'):
Expand Down Expand Up @@ -959,7 +959,7 @@ def author(self):
"""
return self._field('A')[0]

def keywords(self):
def keywords(self, warn=True):
r"""
Return the keywords associated to the sequence ``self``.
Expand All @@ -985,7 +985,7 @@ def keywords(self):
sage: s.keywords()
('nonn', 'hard')
"""
return tuple(self._field('K')[0].split(','))
return tuple(self._field('K', warn=warn)[0].split(','))

def natural_object(self):
r"""
Expand Down Expand Up @@ -1108,8 +1108,8 @@ def is_dead(self, warn_only=False):
EXAMPLES:
A warn_only test is triggered as soon as some information on the
sequence is queried::
A warning is triggered if any field of a dead sequence is accessed,
unless :meth:`is_dead` is called before::
sage: s = oeis(17)
sage: s # optional -- internet
Expand Down Expand Up @@ -1138,11 +1138,11 @@ def is_dead(self, warn_only=False):
True
"""
if warn_only:
if 'dead' in self.keywords():
if 'dead' in self.keywords(warn_only):
from warnings import warn
warn('This sequence is dead: "{}: {}"'.format(self.id(), self.name()), RuntimeWarning)
else:
return 'dead' in self.keywords()
return 'dead' in self.keywords(warn_only)

def is_finite(self):
r"""
Expand Down Expand Up @@ -2010,6 +2010,7 @@ def test_compile_sage_code(self):
True
"""
if self.is_dead():
self.is_dead(warn_only=True)
return True
filt = self.programs(language='sage')
if filt:
Expand Down

0 comments on commit 0d4d4f8

Please sign in to comment.