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

Commit

Permalink
Trac #28582: some cleaning for is_ring
Browse files Browse the repository at this point in the history
as a first step towards deprecation

URL: https://trac.sagemath.org/28582
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Oct 12, 2019
2 parents 6369d2b + 6694a51 commit 58fd34e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/doc/en/thematic_tutorials/coercion_and_categories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ This base class provides a lot more methods than a general parent::
'is_integrally_closed',
'is_noetherian',
'is_prime_field',
'is_ring',
'is_subring',
'krull_dimension',
'ngens',
Expand Down
1 change: 0 additions & 1 deletion src/sage/categories/rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ def is_ring(self):
sage: Parent(QQ,category=Rings()).is_ring()
True
"""
return True

Expand Down
5 changes: 3 additions & 2 deletions src/sage/matroids/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
from sage.graphs.all import Graph
from sage.structure.element import is_Matrix
from sage.rings.all import ZZ, QQ
from sage.categories.all import Fields, Rings
from sage.rings.finite_rings.finite_field_base import FiniteField
import sage.matroids.matroid
import sage.matroids.basis_exchange_matroid
Expand Down Expand Up @@ -694,11 +695,11 @@ def Matroid(groundset=None, data=None, **kwds):
base_ring = None
if 'field' in kwds:
base_ring = kwds.pop('field')
if check and not base_ring.is_field():
if check and not base_ring in Fields:
raise TypeError("{} is not a field".format(base_ring))
elif 'ring' in kwds:
base_ring = kwds.pop('ring')
if check and not base_ring.is_ring():
if check and not base_ring in Rings:
raise TypeError("{} is not a ring".format(base_ring))

# "key" is the kind of data we got
Expand Down
12 changes: 5 additions & 7 deletions src/sage/rings/polynomial/infinite_polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@

import six
from sage.rings.ring import CommutativeRing
from sage.categories.rings import Rings
from sage.structure.all import SageObject, parent
from sage.structure.factory import UniqueFactory
from sage.misc.cachefunc import cached_method
Expand Down Expand Up @@ -684,17 +685,14 @@ def __init__(self, R, names, order):
names = ['x']
for n in names:
if not (isinstance(n, six.string_types) and n.isalnum() and (not n[0].isdigit())):
raise ValueError("generator names must be alpha-numeric strings not starting with a digit, but %s isn't"%n)
if len(names)!=len(set(names)):
raise ValueError("generator names must be alpha-numeric strings not starting with a digit, but %s isn't" % n)
if len(names) != len(set(names)):
raise ValueError("generator names must be pairwise different")
self._names = tuple(names)
if not isinstance(order, six.string_types):
raise TypeError("The monomial order must be given as a string")
try:
if not (hasattr(R,'is_ring') and R.is_ring() and hasattr(R,'is_commutative') and R.is_commutative()):
raise TypeError
except Exception:
raise TypeError("The given 'base ring' (= %s) must be a commutative ring"%(R))
if not R in Rings().Commutative():
raise TypeError("The given 'base ring' (= %s) must be a commutative ring" % R)

# now, the input is accepted
if hasattr(R,'_underlying_ring'):
Expand Down
17 changes: 2 additions & 15 deletions src/sage/rings/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ cdef class Ring(ParentWithGens):
sage: QQ.cardinality()
+Infinity
"""
def __init__(self, base, names=None, normalize=True, category = None):
def __init__(self, base, names=None, normalize=True, category=None):
"""
Initialize ``self``.
Expand Down Expand Up @@ -997,17 +997,6 @@ cdef class Ring(ParentWithGens):
else:
return False

def is_ring(self):
"""
Return ``True`` since ``self`` is a ring.
EXAMPLES::
sage: QQ.is_ring()
True
"""
return True

def is_noetherian(self):
"""
Return ``True`` if this ring is Noetherian.
Expand Down Expand Up @@ -2549,6 +2538,4 @@ def is_Ring(x):
sage: is_Ring(MS)
True
"""
# TODO: use the idiom `x in _Rings` as soon as all rings will be
# in the category Rings()
return isinstance(x, Ring) or x in _Rings
return x in _Rings

0 comments on commit 58fd34e

Please sign in to comment.