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

fixed warning while calling OEISSequence.is_dead() function #36811

Merged
merged 8 commits into from
Dec 26, 2023
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 @@
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 @@
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 @@
"""
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 @@
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 @@

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 @@
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 @@
True
"""
if self.is_dead():
self.is_dead(warn_only=True)

Check warning on line 2013 in src/sage/databases/oeis.py

View check run for this annotation

Codecov / codecov/patch

src/sage/databases/oeis.py#L2013

Added line #L2013 was not covered by tests
return True
filt = self.programs(language='sage')
if filt:
Expand Down