From 4236760f802703629e45c1084fc29468e384bf60 Mon Sep 17 00:00:00 2001 From: Jim Stark Date: Wed, 3 Sep 2014 11:03:00 +0200 Subject: [PATCH] 12824: Delete some deprecated is_* functions --- src/sage/categories/functor.pyx | 14 ++-- src/sage/categories/morphism.pyx | 3 - src/sage/combinat/kazhdan_lusztig.py | 2 +- src/sage/combinat/sf/sfa.py | 2 +- src/sage/crypto/boolean_function.pyx | 4 +- src/sage/crypto/stream.py | 2 +- src/sage/geometry/toric_lattice.py | 5 +- src/sage/geometry/toric_lattice_element.pyx | 31 +------- src/sage/groups/perm_gps/permgroup.py | 2 +- .../groups/perm_gps/permgroup_element.pyx | 4 +- src/sage/gsl/dft.py | 4 +- src/sage/interfaces/expect.py | 3 - src/sage/interfaces/interface.py | 3 - src/sage/interfaces/kash.py | 3 - src/sage/interfaces/macaulay2.py | 2 +- src/sage/matrix/action.pyx | 6 +- src/sage/matrix/constructor.py | 2 +- src/sage/matrix/matrix_integer_dense.pyx | 4 +- src/sage/misc/functional.py | 4 +- src/sage/misc/sage_input.py | 4 +- src/sage/modular/abvar/constructor.py | 4 +- src/sage/modular/arithgroup/all.py | 2 +- .../modular/arithgroup/arithgroup_generic.py | 16 ----- src/sage/modular/cusps.py | 6 +- src/sage/modular/cusps_nf.py | 6 +- src/sage/modular/dims.py | 10 +-- src/sage/modular/dirichlet.py | 14 ---- src/sage/modular/hecke/algebra.py | 4 +- src/sage/modular/hecke/ambient_module.py | 18 ----- src/sage/modular/hecke/homspace.py | 14 ---- src/sage/modular/hecke/module.py | 2 +- src/sage/modular/hecke/submodule.py | 13 ---- src/sage/modular/modform/element.py | 4 +- .../modular/modform/hecke_operator_on_qexp.py | 4 +- src/sage/modular/modsym/boundary.py | 2 +- src/sage/modular/modsym/element.py | 13 ---- src/sage/modular/modsym/manin_symbols.py | 19 ----- src/sage/modular/modsym/space.py | 18 +---- src/sage/modules/fg_pid/fgp_morphism.py | 2 +- src/sage/modules/free_module.py | 2 +- src/sage/modules/free_module_element.pyx | 11 --- src/sage/modules/module_element.py | 2 +- src/sage/modules/vector_space_homspace.py | 38 ---------- src/sage/modules/vector_space_morphism.py | 24 ------- .../monoids/free_abelian_monoid_element.py | 15 ---- src/sage/monoids/free_monoid_element.py | 3 - src/sage/monoids/string_monoid_element.py | 5 -- src/sage/plot/plot.py | 2 - src/sage/probability/random_variable.py | 6 -- src/sage/quadratic_forms/constructions.py | 2 +- src/sage/quadratic_forms/quadratic_form.py | 2 +- src/sage/rings/commutative_algebra_element.py | 2 +- src/sage/rings/finite_rings/constructor.py | 2 +- .../rings/finite_rings/element_givaro.pyx | 6 +- .../rings/finite_rings/element_ntl_gf2e.pyx | 10 ++- .../finite_rings/finite_field_ext_pari.py | 4 +- .../finite_rings/finite_field_ntl_gf2e.py | 4 +- src/sage/rings/ideal_monoid.py | 2 +- src/sage/rings/laurent_series_ring.py | 8 +-- src/sage/rings/multi_power_series_ring.py | 2 +- .../rings/multi_power_series_ring_element.py | 6 +- src/sage/rings/number_field/number_field.py | 18 ++--- .../number_field/number_field_ideal_rel.py | 34 --------- .../rings/number_field/number_field_rel.py | 6 +- src/sage/rings/number_field/order.py | 6 +- src/sage/rings/padics/factory.py | 2 +- src/sage/rings/polynomial/groebner_fan.py | 2 +- .../polynomial/laurent_polynomial_ring.py | 6 +- .../multi_polynomial_libsingular.pyx | 10 +-- .../rings/polynomial/multi_polynomial_ring.py | 8 +-- .../polynomial_padic_capped_relative_dense.py | 2 +- .../padics/polynomial_padic_flat.py | 2 +- src/sage/rings/polynomial/plural.pyx | 4 +- .../rings/polynomial/polynomial_element.pyx | 17 ++--- .../polynomial_integer_dense_ntl.pyx | 4 +- src/sage/rings/polynomial/polynomial_ring.py | 2 +- .../polynomial/polynomial_ring_constructor.py | 8 +-- src/sage/rings/power_series_mpoly.pyx | 1 - src/sage/rings/power_series_poly.pyx | 3 +- src/sage/rings/qqbar.py | 70 ++----------------- src/sage/rings/quotient_ring.py | 4 +- src/sage/rings/residue_field.pyx | 14 ++-- src/sage/rings/ring_element.py | 2 +- .../elliptic_curves/ell_curve_isogeny.py | 2 +- src/sage/schemes/generic/ambient_space.py | 2 +- src/sage/schemes/generic/morphism.py | 2 +- src/sage/schemes/generic/scheme.py | 10 +-- .../hyperelliptic_curves/jacobian_homset.py | 6 +- .../plane_conics/con_rational_field.py | 8 +-- src/sage/schemes/plane_curves/constructor.py | 2 +- src/sage/structure/element.pyx | 31 ++------ 91 files changed, 169 insertions(+), 552 deletions(-) diff --git a/src/sage/categories/functor.pyx b/src/sage/categories/functor.pyx index eedbab82ffe..f3c478a2602 100644 --- a/src/sage/categories/functor.pyx +++ b/src/sage/categories/functor.pyx @@ -94,15 +94,15 @@ cdef class Functor(SageObject): Category of rings sage: F.codomain() Category of commutative additive groups - sage: from sage.categories.functor import is_Functor - sage: is_Functor(F) + sage: from sage.categories.functor import Functor + sage: isinstance(F, Functor) True sage: I = IdentityFunctor(abgrps) sage: I The identity functor on Category of commutative additive groups sage: I.domain() Category of commutative additive groups - sage: is_Functor(I) + sage: isinstance(I, Functor) True Note that by default, an instance of the class Functor is coercion @@ -174,9 +174,9 @@ cdef class Functor(SageObject): Finite Field of size 2 """ - if not category.is_Category(domain): + if not isinstance(domain, category.Category): raise TypeError, "domain (=%s) must be a category"%domain - if not category.is_Category(codomain): + if not isinstance(codomain, category.Category): raise TypeError, "codomain (=%s) must be a category"%codomain self.__domain = domain self.__codomain = codomain @@ -365,8 +365,8 @@ cdef class Functor(SageObject): TypeError: Functor from Category of rings to Category of rings is ill-defined, since it sends x (=Rational Field) to something that is not in Category of rings. """ - from sage.categories.morphism import is_Morphism - if is_Morphism(x): + from sage.categories.morphism import Morphism + if isinstance(x, Morphism): return self._apply_functor_to_morphism(x) y = self._apply_functor(self._coerce_into_domain(x)) if not ((y in self.__codomain) or (y in self.__codomain.hom_category())): diff --git a/src/sage/categories/morphism.pyx b/src/sage/categories/morphism.pyx index 8de9b87b28f..d8903195054 100644 --- a/src/sage/categories/morphism.pyx +++ b/src/sage/categories/morphism.pyx @@ -45,9 +45,6 @@ def make_morphism(_class, parent, _dict, _slots): mor.__dict__ = _dict return mor -def is_Morphism(x): - return isinstance(x, Morphism) - cdef class Morphism(Map): def _repr_(self): diff --git a/src/sage/combinat/kazhdan_lusztig.py b/src/sage/combinat/kazhdan_lusztig.py index 5a7dc5e62df..109f0f80aa1 100644 --- a/src/sage/combinat/kazhdan_lusztig.py +++ b/src/sage/combinat/kazhdan_lusztig.py @@ -84,7 +84,7 @@ def __init__(self, W, q, trace=False): self._trace = trace self._one = W.one() self._base_ring = q.parent() - if is_Polynomial(q): + if isinstance(q, Polynomial): self._base_ring_type = "polynomial" elif isinstance(q, LaurentPolynomial_generic): self._base_ring_type = "laurent" diff --git a/src/sage/combinat/sf/sfa.py b/src/sage/combinat/sf/sfa.py index a830c89cb6a..702bedd471a 100644 --- a/src/sage/combinat/sf/sfa.py +++ b/src/sage/combinat/sf/sfa.py @@ -4684,7 +4684,7 @@ def _nonnegative_coefficients(x): sage: _nonnegative_coefficients(x^2-4) False """ - if is_Polynomial(x) or is_MPolynomial(x): + if isinstance(x, Polynomial) or is_MPolynomial(x): return all([ c >= 0 for c in x.coeffs() ]) else: return x >= 0 diff --git a/src/sage/crypto/boolean_function.pyx b/src/sage/crypto/boolean_function.pyx index 41f43833db6..dd81efa01b9 100644 --- a/src/sage/crypto/boolean_function.pyx +++ b/src/sage/crypto/boolean_function.pyx @@ -34,7 +34,7 @@ from sage.rings.finite_rings.constructor import GF from sage.rings.polynomial.pbori import BooleanPolynomial from sage.rings.finite_rings.constructor import is_FiniteField from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro -from sage.rings.polynomial.polynomial_element import is_Polynomial +from sage.rings.polynomial.polynomial_element import Polynomial include "sage/misc/bitset.pxi" from cpython.string cimport * @@ -322,7 +322,7 @@ cdef class BooleanFunction(SageObject): bitset_init(self._truth_table,(1< - sage: sage.modules.vector_space_homspace.is_VectorSpaceHomspace(H) - True - - sage: K = Hom(QQ^3, ZZ^2) - sage: type(K) - - sage: sage.modules.vector_space_homspace.is_VectorSpaceHomspace(K) - False - - sage: L = Hom(ZZ^3, QQ^2) - sage: type(L) - - sage: sage.modules.vector_space_homspace.is_VectorSpaceHomspace(L) - False - - sage: sage.modules.vector_space_homspace.is_VectorSpaceHomspace('junk') - False - """ - return isinstance(x, VectorSpaceHomspace) - class VectorSpaceHomspace(sage.modules.free_module_homspace.FreeModuleHomspace): def __call__(self, A, check=True): diff --git a/src/sage/modules/vector_space_morphism.py b/src/sage/modules/vector_space_morphism.py index 63f43024377..467f64eae5e 100644 --- a/src/sage/modules/vector_space_morphism.py +++ b/src/sage/modules/vector_space_morphism.py @@ -769,30 +769,6 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'): # __init__ will check matrix sizes versus domain/codomain dimensions return H(arg2) -def is_VectorSpaceMorphism(x): - r""" - Returns ``True`` if ``x`` is a vector space morphism (a linear transformation). - - INPUT: - - ``x`` - anything - - OUTPUT: - - ``True`` only if ``x`` is an instance of a vector space morphism, - which are also known as linear transformations. - - EXAMPLES:: - - sage: V = QQ^2; f = V.hom([V.1,-2*V.0]) - sage: sage.modules.vector_space_morphism.is_VectorSpaceMorphism(f) - True - sage: sage.modules.vector_space_morphism.is_VectorSpaceMorphism('junk') - False - """ - return isinstance(x, VectorSpaceMorphism) - - class VectorSpaceMorphism(free_module_morphism.FreeModuleMorphism): def __init__(self, homspace, A): diff --git a/src/sage/monoids/free_abelian_monoid_element.py b/src/sage/monoids/free_abelian_monoid_element.py index c63ea6638a3..c545db69abb 100644 --- a/src/sage/monoids/free_abelian_monoid_element.py +++ b/src/sage/monoids/free_abelian_monoid_element.py @@ -44,21 +44,6 @@ from sage.rings.integer import Integer from sage.structure.element import MonoidElement -def is_FreeAbelianMonoidElement(x): - r""" - Queries whether ``x`` is an object of type ``FreeAbelianMonoidElement``. - - INPUT: - - - ``x`` -- an object. - - OUTPUT: - - - ``True`` if ``x`` is an object of type ``FreeAbelianMonoidElement``; - ``False`` otherwise. - """ - return isinstance(x, FreeAbelianMonoidElement) - class FreeAbelianMonoidElement(MonoidElement): def __init__(self, F, x): """ diff --git a/src/sage/monoids/free_monoid_element.py b/src/sage/monoids/free_monoid_element.py index 7fecaf8f0d6..5c041be1ea6 100644 --- a/src/sage/monoids/free_monoid_element.py +++ b/src/sage/monoids/free_monoid_element.py @@ -27,9 +27,6 @@ from sage.rings.integer import Integer from sage.structure.element import MonoidElement -def is_FreeMonoidElement(x): - return isinstance(x, FreeMonoidElement) - class FreeMonoidElement(MonoidElement): """ Element of a free monoid. diff --git a/src/sage/monoids/string_monoid_element.py b/src/sage/monoids/string_monoid_element.py index f0734da2348..0157021e1b6 100644 --- a/src/sage/monoids/string_monoid_element.py +++ b/src/sage/monoids/string_monoid_element.py @@ -29,11 +29,6 @@ from free_monoid_element import FreeMonoidElement import string_monoid -def is_StringMonoidElement(x): - r""" - """ - return isinstance(x, StringMonoidElement) - def is_AlphabeticStringMonoidElement(x): r""" """ diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index c5ebf24684b..1ecc7286c15 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -78,8 +78,6 @@ - :func:`Graphics` -- :func:`is_Graphics` - - :func:`~sage.plot.colors.hue` diff --git a/src/sage/probability/random_variable.py b/src/sage/probability/random_variable.py index 4a670e9d2f5..7fb64d7051f 100644 --- a/src/sage/probability/random_variable.py +++ b/src/sage/probability/random_variable.py @@ -27,15 +27,9 @@ def is_ProbabilitySpace(S): return isinstance(S, ProbabilitySpace_generic) -def is_DiscreteProbabilitySpace(S): - return isinstance(S, DiscreteProbabilitySpace) - def is_RandomVariable(X): return isinstance(X, RandomVariable_generic) -def is_DiscreteRandomVariable(X): - return isinstance(X, DiscreteRandomVariable) - ################################################################################ ################################################################################ diff --git a/src/sage/quadratic_forms/constructions.py b/src/sage/quadratic_forms/constructions.py index 90c7946003f..30393a524ae 100644 --- a/src/sage/quadratic_forms/constructions.py +++ b/src/sage/quadratic_forms/constructions.py @@ -6,7 +6,7 @@ ## from sage.rings.all import ZZ -from sage.rings.polynomial.polynomial_element import is_Polynomial +from sage.rings.polynomial.polynomial_element import Polynomial from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.quadratic_forms.quadratic_form import QuadraticForm diff --git a/src/sage/quadratic_forms/quadratic_form.py b/src/sage/quadratic_forms/quadratic_form.py index 4e3b1545556..83cc4474a87 100644 --- a/src/sage/quadratic_forms/quadratic_form.py +++ b/src/sage/quadratic_forms/quadratic_form.py @@ -32,7 +32,7 @@ from sage.rings.ring import Ring from sage.misc.functional import ideal, denominator, is_even, is_field from sage.rings.arith import GCD, LCM -from sage.rings.principal_ideal_domain import is_PrincipalIdealDomain +from sage.rings.principal_ideal_domain import PrincipalIdealDomain from sage.rings.ring import is_Ring from sage.matrix.matrix import is_Matrix from sage.structure.sage_object import SageObject diff --git a/src/sage/rings/commutative_algebra_element.py b/src/sage/rings/commutative_algebra_element.py index 3d5252a521a..d3c9254ce1e 100644 --- a/src/sage/rings/commutative_algebra_element.py +++ b/src/sage/rings/commutative_algebra_element.py @@ -17,4 +17,4 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from sage.structure.element import CommutativeAlgebraElement, is_CommutativeAlgebraElement +from sage.structure.element import CommutativeAlgebraElement diff --git a/src/sage/rings/finite_rings/constructor.py b/src/sage/rings/finite_rings/constructor.py index 6690c02ea2b..e83ce0100a5 100644 --- a/src/sage/rings/finite_rings/constructor.py +++ b/src/sage/rings/finite_rings/constructor.py @@ -486,7 +486,7 @@ def create_object(self, version, key, check_irreducible=True, elem_cache=None, # constructors with check options (like above). from sage.structure.proof.all import WithProof with WithProof('arithmetic', proof): - if check_irreducible and polynomial_element.is_Polynomial(modulus): + if check_irreducible and isinstance(modulus, polynomial_element.Polynomial): if modulus.parent().base_ring().characteristic() == 0: modulus = modulus.change_ring(FiniteField(p)) if not modulus.is_irreducible(): diff --git a/src/sage/rings/finite_rings/element_givaro.pyx b/src/sage/rings/finite_rings/element_givaro.pyx index 4ceee9d4b16..df5ac3147d9 100644 --- a/src/sage/rings/finite_rings/element_givaro.pyx +++ b/src/sage/rings/finite_rings/element_givaro.pyx @@ -85,7 +85,6 @@ from sage.structure.parent_gens cimport ParentWithGens cdef object is_IntegerMod cdef object Integer cdef object Rational -cdef object is_Polynomial cdef object ConwayPolynomials cdef object conway_polynomial cdef object MPolynomial @@ -99,7 +98,6 @@ cdef void late_import(): global is_IntegerMod, \ Integer, \ Rational, \ - is_Polynomial, \ ConwayPolynomials, \ conway_polynomial, \ MPolynomial, \ @@ -264,7 +262,7 @@ cdef class Cache_givaro(SageObject): else: modulus.append(0) - if is_Polynomial(modulus): + if isinstance(modulus, Polynomial): modulus = modulus.list() if PY_TYPE_CHECK(modulus, list) or PY_TYPE_CHECK(modulus, tuple): @@ -470,7 +468,7 @@ cdef class Cache_givaro(SageObject): # reduce FiniteField_ext_pariElements to pari e = e._pari_() - elif sage.interfaces.gap.is_GapElement(e): + elif isinstance(e, sage.interfaces.gap.GapElement): from sage.interfaces.gap import gfq_gap_to_sage return gfq_gap_to_sage(e, self.parent) diff --git a/src/sage/rings/finite_rings/element_ntl_gf2e.pyx b/src/sage/rings/finite_rings/element_ntl_gf2e.pyx index 0f6f9a6524e..fe76dd4c82a 100644 --- a/src/sage/rings/finite_rings/element_ntl_gf2e.pyx +++ b/src/sage/rings/finite_rings/element_ntl_gf2e.pyx @@ -45,7 +45,7 @@ from sage.rings.finite_rings.finite_field_base cimport FiniteField from sage.libs.pari.all import pari from sage.libs.pari.gen import gen -from sage.interfaces.gap import is_GapElement +from sage.interfaces.gap import GapElement from sage.misc.randstate import current_randstate @@ -59,7 +59,6 @@ cdef object is_IntegerMod cdef object IntegerModRing_generic cdef object Integer cdef object Rational -cdef object is_Polynomial cdef object ConwayPolynomials cdef object conway_polynomial cdef object MPolynomial @@ -78,7 +77,6 @@ cdef int late_import() except -1: IntegerModRing_generic, \ Integer, \ Rational, \ - is_Polynomial, \ ConwayPolynomials, \ conway_polynomial, \ MPolynomial, \ @@ -359,7 +357,7 @@ cdef class Cache_ntl_gf2e(SageObject): # reduce FiniteField_ext_pariElements to pari e = e._pari_() - elif is_GapElement(e): + elif isinstance(e, GapElement): from sage.interfaces.gap import gfq_gap_to_sage return gfq_gap_to_sage(e, self._parent) else: @@ -1023,8 +1021,8 @@ cdef class FiniteField_ntl_gf2eElement(FinitePolyExtElement): sage: e.polynomial() a^15 + a^13 + a^11 + a^10 + a^9 + a^8 + a^7 + a^6 + a^4 + a + 1 - sage: from sage.rings.polynomial.polynomial_element import is_Polynomial - sage: is_Polynomial(e.polynomial()) + sage: from sage.rings.polynomial.polynomial_element import Polynomial + sage: isinstance(e.polynomial(), Polynomial) True sage: e.polynomial('x') diff --git a/src/sage/rings/finite_rings/finite_field_ext_pari.py b/src/sage/rings/finite_rings/finite_field_ext_pari.py index b7ad5b95c0b..98881fc70f4 100644 --- a/src/sage/rings/finite_rings/finite_field_ext_pari.py +++ b/src/sage/rings/finite_rings/finite_field_ext_pari.py @@ -233,7 +233,7 @@ def __init__(self, q, name, modulus=None): elif isinstance(modulus, (list, tuple)): modulus = GF(self.__char)['x'](modulus) - elif sage.rings.polynomial.polynomial_element.is_Polynomial(modulus): + elif isinstance(modulus, sage.rings.polynomial.polynomial_element.Polynomial): if modulus.parent() is not base_ring: modulus = modulus.change_ring(base_ring) else: @@ -522,7 +522,7 @@ def _element_constructor_(self, x): else: raise TypeError("no coercion defined") - elif sage.interfaces.gap.is_GapElement(x): + elif isinstance(x, sage.interfaces.gap.GapElement): from sage.interfaces.gap import gfq_gap_to_sage try: return gfq_gap_to_sage(x, self) diff --git a/src/sage/rings/finite_rings/finite_field_ntl_gf2e.py b/src/sage/rings/finite_rings/finite_field_ntl_gf2e.py index b7640fc2c13..fb063f0607a 100644 --- a/src/sage/rings/finite_rings/finite_field_ntl_gf2e.py +++ b/src/sage/rings/finite_rings/finite_field_ntl_gf2e.py @@ -21,7 +21,7 @@ def late_import(): """ if "GF2" in globals(): return - global ResidueField_generic, is_FiniteField, exists_conway_polynomial, conway_polynomial, Cache_ntl_gf2e, GF, GF2, is_Polynomial + global ResidueField_generic, is_FiniteField, exists_conway_polynomial, conway_polynomial, Cache_ntl_gf2e, GF, GF2, Polynomial import sage.rings.residue_field ResidueField_generic = sage.rings.residue_field.ResidueField_generic @@ -40,7 +40,7 @@ def late_import(): GF2 = GF(2) import sage.rings.polynomial.polynomial_element - is_Polynomial = sage.rings.polynomial.polynomial_element.is_Polynomial + Polynomial = sage.rings.polynomial.polynomial_element.Polynomial class FiniteField_ntl_gf2e(FiniteField): """ diff --git a/src/sage/rings/ideal_monoid.py b/src/sage/rings/ideal_monoid.py index b1d9a85a86e..638f0d616fd 100644 --- a/src/sage/rings/ideal_monoid.py +++ b/src/sage/rings/ideal_monoid.py @@ -2,7 +2,7 @@ Monoid of ideals in a commutative ring """ -from commutative_ring import is_CommutativeRing +from commutative_ring import CommutativeRing #from sage.structure.parent_base import ParentWithBase from sage.structure.parent import Parent import sage.rings.integer_ring diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index b333b204d60..b912f7c467f 100644 --- a/src/sage/rings/laurent_series_ring.py +++ b/src/sage/rings/laurent_series_ring.py @@ -322,8 +322,8 @@ def _element_constructor_(self, x, n=0): sage: L(pari('O(x^-10)')) O(q^-10) """ - from sage.rings.fraction_field_element import is_FractionFieldElement - from sage.rings.polynomial.polynomial_element import is_Polynomial + from sage.rings.fraction_field_element import FractionFieldElement + from sage.rings.polynomial.polynomial_element import Polynomial from sage.rings.polynomial.multi_polynomial_element import is_MPolynomial from sage.structure.element import parent @@ -354,9 +354,9 @@ def _element_constructor_(self, x, n=0): return (x << n).add_bigoh(bigoh) else: # General case, pretend to be a polynomial return self(self.polynomial_ring()(x)) << n - elif is_FractionFieldElement(x) and \ + elif isinstance(x, FractionFieldElement) and \ (x.base_ring() is self.base_ring() or x.base_ring() == self.base_ring()) and \ - (is_Polynomial(x.numerator()) or is_MPolynomial(x.numerator())): + (isinstance(x.numerator(), Polynomial) or is_MPolynomial(x.numerator())): x = self(x.numerator())/self(x.denominator()) return (x << n) return self.element_class(self, x, n) diff --git a/src/sage/rings/multi_power_series_ring.py b/src/sage/rings/multi_power_series_ring.py index 360ea52ebb9..9c8ab473019 100644 --- a/src/sage/rings/multi_power_series_ring.py +++ b/src/sage/rings/multi_power_series_ring.py @@ -682,7 +682,7 @@ def _is_valid_homomorphism_(self, codomain, im_gens): except NotImplementedError: B = all(v.valuation() > 0 for v in im_gens) return B - if is_CommutativeRing(codomain): + if isinstance(codomain, CommutativeRing): return all(v.is_nilpotent() for v in im_gens) diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 565ac5d49f4..747f7d9d90d 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -173,17 +173,17 @@ def is_MPowerSeries(f): TESTS:: - sage: from sage.rings.power_series_ring_element import is_PowerSeries + sage: from sage.rings.power_series_ring_element import PowerSeries sage: from sage.rings.multi_power_series_ring_element import is_MPowerSeries sage: M = PowerSeriesRing(ZZ,4,'v'); - sage: is_PowerSeries(M.random_element(10)) + sage: isinstance(M.random_element(10), PowerSeries) True sage: is_MPowerSeries(M.random_element(10)) True sage: T. = PowerSeriesRing(RR) sage: is_MPowerSeries(1 - v + v^2 +O(v^3)) False - sage: is_PowerSeries(1 - v + v^2 +O(v^3)) + sage: isinstance(1 - v + v^2 +O(v^3), PowerSeries) True """ diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index 53ba3c5e17b..824e41d87a5 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -114,7 +114,7 @@ from class_group import ClassGroup from class_group import SClassGroup -from sage.structure.element import is_Element +from sage.structure.element import Element from sage.structure.sequence import Sequence import sage.structure.parent_gens @@ -1401,7 +1401,7 @@ def _element_constructor_(self, x): return self._element_class(self, x) x = L(x) return self._coerce_from_other_number_field(x) - elif sage.interfaces.gap.is_GapElement(x): + elif isinstance(x, sage.interfaces.gap.GapElement): s = repr(x) if self.variable_name() in s: return self._coerce_from_str(s) @@ -1440,7 +1440,7 @@ def _coerce_from_str(self, x): # provide string coercion, as # for finite fields w = sage.misc.all.sage_eval(x,locals=self.gens_dict()) - if not (is_Element(w) and w.parent() is self): + if not (isinstance(w, Element) and w.parent() is self): return self(w) else: return w @@ -5568,7 +5568,7 @@ def uniformizer(self, P, others="positive"): with exponent of -1 and invert the result in the "negative" case. """ - if not is_NumberFieldIdeal(P): + if not isinstance(P, NumberFieldIdeal): P = self.ideal(P) P = P.pari_prime() if others == "positive": @@ -6408,7 +6408,7 @@ def _coerce_from_str(self, x): -1/3*theta25 - 1 """ w = sage.misc.all.sage_eval(x,locals=self.gens_dict()) - if not (is_Element(w) and w.parent() is self): + if not (isinstance(w, Element) and w.parent() is self): return self(w) else: return w @@ -7717,8 +7717,8 @@ def relativize(self, alpha, names, structure=None): names = sage.structure.parent_gens.normalize_names(2, names) - from sage.categories.map import is_Map - if is_Map(alpha): + from sage.categories.map import Map + if isinstance(alpha, Map): # alpha better be a morphism with codomain self if alpha.codomain() != self: raise ValueError("Co-domain of morphism must be self") @@ -8110,7 +8110,7 @@ def hilbert_symbol(self, a, b, P = None): if P(a) > 0 or P(b) > 0: return 1 return -1 - if not is_NumberFieldIdeal(P): + if not isinstance(P, NumberFieldIdeal): P = self.ideal(P) if not P.number_field() == self: raise ValueError("P (=%s) should be an ideal of self (=%s) in hilbert_symbol, not of %s" % (P, self, P.number_field())) @@ -8814,7 +8814,7 @@ def _element_constructor_(self, x): return self._coerce_from_other_cyclotomic_field(x) else: return NumberField_absolute._element_constructor_(self, x) - elif sage.interfaces.gap.is_GapElement(x): + elif isinstance(x, sage.interfaces.gap.GapElement): return self._coerce_from_gap(x) elif isinstance(x,UniversalCyclotomicField.Element): return self._coerce_from_universal_cyclotomic_field(x) diff --git a/src/sage/rings/number_field/number_field_ideal_rel.py b/src/sage/rings/number_field/number_field_ideal_rel.py index 6f50855c7db..e338c72ced1 100644 --- a/src/sage/rings/number_field/number_field_ideal_rel.py +++ b/src/sage/rings/number_field/number_field_ideal_rel.py @@ -827,37 +827,3 @@ def valuation(self, p): if p.ring() != self.number_field(): raise ValueError("p (= %s) must be an ideal in %s"%self.number_field()) return self.absolute_ideal().valuation(p.absolute_ideal()) - -def is_NumberFieldFractionalIdeal_rel(x): - """ - Return True if x is a fractional ideal of a relative number field. - - EXAMPLES:: - - sage: from sage.rings.number_field.number_field_ideal_rel import is_NumberFieldFractionalIdeal_rel - sage: from sage.rings.number_field.number_field_ideal import is_NumberFieldFractionalIdeal - sage: is_NumberFieldFractionalIdeal_rel(2/3) - False - sage: is_NumberFieldFractionalIdeal_rel(ideal(5)) - False - sage: k. = NumberField(x^2 + 2) - sage: I = k.ideal([a + 1]); I - Fractional ideal (a + 1) - sage: is_NumberFieldFractionalIdeal_rel(I) - False - sage: R. = QQ[] - sage: K. = NumberField(x^2+6) - sage: L. = K.extension(K['x'].gen()^4 + a) - sage: I = L.ideal(b); I - Fractional ideal (6, b) - sage: is_NumberFieldFractionalIdeal_rel(I) - True - sage: N = I.relative_norm(); N - Fractional ideal (-a) - sage: is_NumberFieldFractionalIdeal_rel(N) - False - sage: is_NumberFieldFractionalIdeal(N) - True - """ - return isinstance(x, NumberFieldFractionalIdeal_rel) - diff --git a/src/sage/rings/number_field/number_field_rel.py b/src/sage/rings/number_field/number_field_rel.py index 05d6846a042..45f7bae2153 100644 --- a/src/sage/rings/number_field/number_field_rel.py +++ b/src/sage/rings/number_field/number_field_rel.py @@ -82,7 +82,7 @@ import sage.libs.ntl.all as ntl import sage.rings.arith -from sage.categories.map import is_Map +from sage.categories.map import Map from sage.structure.sequence import Sequence import sage.structure.parent_gens @@ -2430,7 +2430,7 @@ def relativize(self, alpha, names): K = self.absolute_field('a') from_K, to_K = K.structure() - if is_Map(alpha): + if isinstance(alpha, Map): # alpha is an embedding of a subfield into self; compose to get an # embedding of a subfield into the absolute field beta = to_K * alpha @@ -2474,7 +2474,7 @@ def uniformizer(self, P, others = "positive"): sage: (P, 1) in K.factor(u) True """ - if not is_NumberFieldIdeal(P): + if not isinstance(P, NumberFieldIdeal): P = self.ideal(P) if not P.is_maximal(): raise ValueError("P (=%s) must be a nonzero prime."%P) diff --git a/src/sage/rings/number_field/order.py b/src/sage/rings/number_field/order.py index 43d2e252ab0..11e91174ba0 100644 --- a/src/sage/rings/number_field/order.py +++ b/src/sage/rings/number_field/order.py @@ -39,7 +39,7 @@ from sage.rings.ring import IntegralDomain from sage.structure.sequence import Sequence from sage.rings.integer_ring import ZZ -from sage.structure.element import is_Element +from sage.structure.element import Element from number_field_element import OrderElement_absolute, OrderElement_relative @@ -1061,9 +1061,9 @@ def _element_constructor_(self, x): sage: k(m(6*z)) 6*z """ - if is_Element(x) and x.parent() is self: + if isinstance(x, Element) and x.parent() is self: return x - if not is_Element(x) or x.parent() is not self._K: + if not isinstance(x, Element) or x.parent() is not self._K: x = self._K(x) V, _, embedding = self._K.vector_space() if not embedding(x) in self._module_rep: diff --git a/src/sage/rings/padics/factory.py b/src/sage/rings/padics/factory.py index bf6edc5f89f..9477a7f2a13 100644 --- a/src/sage/rings/padics/factory.py +++ b/src/sage/rings/padics/factory.py @@ -2204,7 +2204,7 @@ def create_key_and_extra_args(self, base, premodulus, prec = None, print_mode = if len(premodulus.variables()) != 1: raise ValueError("symbolic expression must be in only one variable") modulus = premodulus.polynomial(base) - elif is_Polynomial(premodulus): + elif isinstance(premodulus, Polynomial): if premodulus.parent().ngens() != 1: raise ValueError("must use univariate polynomial") modulus = premodulus.change_ring(base) diff --git a/src/sage/rings/polynomial/groebner_fan.py b/src/sage/rings/polynomial/groebner_fan.py index aa6f4431cfc..1af5614213a 100644 --- a/src/sage/rings/polynomial/groebner_fan.py +++ b/src/sage/rings/polynomial/groebner_fan.py @@ -67,7 +67,7 @@ from sage.structure.sage_object import SageObject from sage.interfaces.gfan import gfan -from multi_polynomial_ideal import is_MPolynomialIdeal +from multi_polynomial_ideal import MPolynomialIdeal from polynomial_ring_constructor import PolynomialRing from sage.rings.rational_field import QQ from sage.rings.integer import Integer diff --git a/src/sage/rings/polynomial/laurent_polynomial_ring.py b/src/sage/rings/polynomial/laurent_polynomial_ring.py index e7e6faf52ac..94e97af17e4 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ring.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ring.py @@ -40,7 +40,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** from sage.structure.parent_gens import normalize_names -from sage.structure.element import is_Element +from sage.structure.element import Element from sage.rings.ring import is_Ring from sage.rings.integer import Integer from sage.rings.polynomial.polynomial_ring_constructor import _single_variate as _single_variate_poly @@ -220,9 +220,9 @@ def LaurentPolynomialRing(base_ring, arg1=None, arg2=None, sparse = False, order sage: (w0 + 2*w8 + w13)^2 w0^2 + 4*w0*w8 + 4*w8^2 + 2*w0*w13 + 4*w8*w13 + w13^2 """ - if is_Element(arg1) and not isinstance(arg1, (int, long, Integer)): + if isinstance(arg1, Element) and not isinstance(arg1, (int, long, Integer)): arg1 = repr(arg1) - if is_Element(arg2) and not isinstance(arg2, (int, long, Integer)): + if isinstance(arg2, Element) and not isinstance(arg2, (int, long, Integer)): arg2 = repr(arg2) if isinstance(arg1, (int, long, Integer)): diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index 3b6cbdbe84c..b3d6a2dee77 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -236,8 +236,8 @@ from sage.structure.factorization import Factorization from sage.structure.sequence import Sequence from sage.interfaces.all import macaulay2 -from sage.interfaces.singular import singular as singular_default, is_SingularElement, SingularElement -from sage.interfaces.macaulay2 import macaulay2 as macaulay2_default, is_Macaulay2Element +from sage.interfaces.singular import singular as singular_default, SingularElement +from sage.interfaces.macaulay2 import macaulay2 as macaulay2_default, Macaulay2Element from sage.misc.misc import mul from sage.misc.sage_eval import sage_eval @@ -965,7 +965,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_generic): except AttributeError: pass - if is_Macaulay2Element(element): + if isinstance(element, Macaulay2Element): return self(element.external_string()) try: @@ -1074,10 +1074,10 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_generic): if gens.ring() is self: return gens gens = gens.gens() - if is_SingularElement(gens): + if isinstance(gens, SingularElement): gens = list(gens) coerce = True - elif is_Macaulay2Element(gens): + elif isinstance(gens, Macaulay2Element): gens = list(gens) coerce = True if not isinstance(gens, (list, tuple)): diff --git a/src/sage/rings/polynomial/multi_polynomial_ring.py b/src/sage/rings/polynomial/multi_polynomial_ring.py index 6027cffdf83..fd706cbe88f 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring.py +++ b/src/sage/rings/polynomial/multi_polynomial_ring.py @@ -450,7 +450,7 @@ def __call__(self, x, check=True): else: raise TypeError("unable to coerce since the denominator is not 1") - elif is_SingularElement(x) and self._has_singular: + elif isinstance(x, SingularElement) and self._has_singular: self._singular_().set_ring() try: return x.sage_poly(self) @@ -467,7 +467,7 @@ def __call__(self, x, check=True): except NameError as e: raise TypeError("unable to convert string") - elif is_Macaulay2Element(x): + elif isinstance(x, Macaulay2Element): try: s = x.sage_polystring() if len(s) == 0: @@ -517,10 +517,10 @@ def ideal(self, *gens, **kwds): if not self._has_singular: # pass through MPolynomialRing_generic.ideal(self,gens,**kwds) - if is_SingularElement(gens): + if isinstance(gens, SingularElement): gens = list(gens) do_coerce = True - if is_Macaulay2Element(gens): + if isinstance(gens, Macaulay2Element): gens = list(gens) do_coerce = True elif not isinstance(gens, (list, tuple)): diff --git a/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py b/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py index 4c708131686..3a060b00c5b 100644 --- a/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py +++ b/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py @@ -669,7 +669,7 @@ def rshift_coeffs(self, shift, no_list = False): return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly // fdiv, 0, [0 if a <= shift else a - shift for a in self._relprecs], False, None, None), construct = True) #def __floordiv__(self, right): - # if is_Polynomial(right) and right.is_constant() and right[0] in self.base_ring(): + # if isinstance(right, Polynomial) and right.is_constant() and right[0] in self.base_ring(): # d = self.base_ring()(right[0]) # elif (right in self.base_ring()): # d = self.base_ring()(right) diff --git a/src/sage/rings/polynomial/padics/polynomial_padic_flat.py b/src/sage/rings/polynomial/padics/polynomial_padic_flat.py index a016118f06e..e9dfce0d8fb 100644 --- a/src/sage/rings/polynomial/padics/polynomial_padic_flat.py +++ b/src/sage/rings/polynomial/padics/polynomial_padic_flat.py @@ -32,7 +32,7 @@ def __init__(self, parent, x=None, check=True, is_gen=False, construct=False, ab Polynomial_generic_dense.__init__(self, parent, x, check, is_gen, construct) return R = parent.base_ring() - if sage.rings.fraction_field_element.is_FractionFieldElement(x): + if isinstance(x, sage.rings.fraction_field_element.FractionFieldElement): if x.denominator() != 1: raise TypeError("denominator must be 1") else: diff --git a/src/sage/rings/polynomial/plural.pyx b/src/sage/rings/polynomial/plural.pyx index 9c6e11cb394..9fbd94312cb 100644 --- a/src/sage/rings/polynomial/plural.pyx +++ b/src/sage/rings/polynomial/plural.pyx @@ -817,10 +817,10 @@ cdef class NCPolynomialRing_plural(Ring): coerce = kwds.get('coerce', True) if len(gens) == 1: gens = gens[0] - #if is_SingularElement(gens): + #if isinstance(gens, SingularElement): # gens = list(gens) # coerce = True - #elif is_Macaulay2Element(gens): + #elif isinstance(gens, Macaulay2Element): # gens = list(gens) # coerce = True if not isinstance(gens, (list, tuple)): diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 2f313ad19ac..13ab06c1b63 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -71,6 +71,7 @@ CC = ComplexField() from sage.rings.real_double import is_RealDoubleField, RDF from sage.rings.complex_double import is_ComplexDoubleField, CDF from sage.rings.real_mpfi import is_RealIntervalField +from sage.rings.qqbar import AlgebraicField, AlgebraicField_common from sage.structure.element import RingElement, generic_power, parent from sage.structure.element cimport Element, RingElement, ModuleElement, MonoidElement @@ -81,7 +82,7 @@ from sage.rings.integer cimport smallInteger from sage.rings.fraction_field import is_FractionField from sage.rings.padics.generic_nodes import is_pAdicRing, is_pAdicField -from sage.rings.integral_domain import is_IntegralDomain +from sage.rings.integral_domain import IntegralDomain from sage.structure.parent_gens cimport ParentWithGens from sage.misc.derivative import multi_derivative @@ -163,8 +164,8 @@ cdef void late_import(): import sage.rings.qqbar is_AlgebraicRealField = sage.rings.qqbar.is_AlgebraicRealField - is_AlgebraicField = sage.rings.qqbar.is_AlgebraicField - is_AlgebraicField_common = sage.rings.qqbar.is_AlgebraicField_common + AlgebraicField = sage.rings.qqbar.AlgebraicField + AlgebraicField_common = sage.rings.qqbar.AlgebraicField_common import sage.rings.number_field.number_field NumberField_quadratic = sage.rings.number_field.number_field.NumberField_quadratic import sage.rings.complex_interval_field @@ -5761,7 +5762,7 @@ cdef class Polynomial(CommutativeAlgebraElement): else: return [rt for (rt, mult) in rts_mult] - if L != K or is_AlgebraicField_common(L): + if L != K or isinstance(L, AlgebraicField_common): # So far, the only "special" implementations are for real # and complex root isolation and for p-adic factorization if (is_IntegerRing(K) or is_RationalField(K) @@ -5795,14 +5796,14 @@ cdef class Polynomial(CommutativeAlgebraElement): return [rt for (rt, mult) in rts] if (is_IntegerRing(K) or is_RationalField(K) - or is_AlgebraicField_common(K) or input_gaussian) and \ - (is_ComplexIntervalField(L) or is_AlgebraicField_common(L)): + or isinstance(K, AlgebraicField_common) or input_gaussian) and \ + (is_ComplexIntervalField(L) or isinstance(L, AlgebraicField_common)): from sage.rings.polynomial.complex_roots import complex_roots if is_ComplexIntervalField(L): rts = complex_roots(self, min_prec=L.prec()) - elif is_AlgebraicField(L): + elif isinstance(L, AlgebraicField): rts = complex_roots(self, retval='algebraic') else: rts = complex_roots(self, retval='algebraic_real') @@ -7046,7 +7047,7 @@ cdef class Polynomial_generic_dense(Polynomial): self.__coeffs = x return - if sage.rings.fraction_field_element.is_FractionFieldElement(x): + if isinstance(x, sage.rings.fraction_field_element.FractionFieldElement): if x.denominator() != 1: raise TypeError("denominator must be 1") else: diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx index 9adf7d91220..bbf0385f835 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx @@ -40,7 +40,7 @@ from sage.rings.integer_ring import IntegerRing from sage.rings.integer_ring cimport IntegerRing_class ZZ_sage = IntegerRing() -from sage.rings.polynomial.polynomial_element import is_Polynomial +from sage.rings.polynomial.polynomial_element import Polynomial from sage.libs.ntl.ntl_ZZX cimport ntl_ZZX @@ -703,7 +703,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): sage: g // f x - 6 """ - if is_Polynomial(right) and right.is_constant() and right[0] in ZZ: + if isinstance(right, Polynomial) and right.is_constant() and right[0] in ZZ: d = ZZ(right[0]) return self.parent()([c // d for c in self.list()], construct=True) elif (right in self.parent().base_ring()): diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index bb700442dd2..76f71fd0789 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -2390,7 +2390,7 @@ def polygen(ring_or_element, name="x"): get a tuple of indeterminates, exactly as if you called polygens. """ - if ring_element.is_RingElement(ring_or_element): + if isinstance(ring_or_element, ring_element.RingElement): base_ring = ring_or_element.parent() elif ring.is_Ring(ring_or_element): base_ring = ring_or_element diff --git a/src/sage/rings/polynomial/polynomial_ring_constructor.py b/src/sage/rings/polynomial/polynomial_ring_constructor.py index 5e77eea953c..9dc88e64940 100644 --- a/src/sage/rings/polynomial/polynomial_ring_constructor.py +++ b/src/sage/rings/polynomial/polynomial_ring_constructor.py @@ -33,7 +33,7 @@ from sage.structure.parent_gens import normalize_names -from sage.structure.element import is_Element +from sage.structure.element import Element import sage.rings.ring as ring import sage.rings.padics.padic_base_leaves as padic_base_leaves @@ -432,9 +432,9 @@ def PolynomialRing(base_ring, arg1=None, arg2=None, elif not name is None: arg1 = name - if is_Element(arg1) and not isinstance(arg1, (int, long, Integer)): + if isinstance(arg1, Element) and not isinstance(arg1, (int, long, Integer)): arg1 = repr(arg1) - if is_Element(arg2) and not isinstance(arg2, (int, long, Integer)): + if isinstance(arg2, Element) and not isinstance(arg2, (int, long, Integer)): arg2 = repr(arg2) if not m.ring.is_Ring(base_ring): @@ -574,7 +574,7 @@ def _multi_variate(base_ring, names, n, sparse, order, implementation): return R from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomialRing_libsingular - if m.integral_domain.is_IntegralDomain(base_ring): + if isinstance(base_ring, m.integral_domain.IntegralDomain): if n < 1: R = m.MPolynomialRing_polydict_domain(base_ring, n, names, order) else: diff --git a/src/sage/rings/power_series_mpoly.pyx b/src/sage/rings/power_series_mpoly.pyx index 08cd0e78524..0e1a07dc17c 100644 --- a/src/sage/rings/power_series_mpoly.pyx +++ b/src/sage/rings/power_series_mpoly.pyx @@ -7,7 +7,6 @@ from sage.structure.element cimport Element, ModuleElement, RingElement from infinity import infinity, is_Infinite import arith from sage.libs.all import PariError -from power_series_ring_element import is_PowerSeries import rational_field from polynomial.multi_polynomial_ring_generic import is_MPolynomialRing import power_series_poly diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index 818e2eae299..561da12151e 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -13,7 +13,6 @@ from sage.structure.element cimport Element, ModuleElement, RingElement from infinity import infinity, is_Infinite import arith from sage.libs.all import PariError -from power_series_ring_element import is_PowerSeries import rational_field cdef class PowerSeries_poly(PowerSeries): @@ -700,7 +699,7 @@ cdef class PowerSeries_poly(PowerSeries): try: return PowerSeries.__div__(self, denom) except (PariError, ZeroDivisionError) as e: # PariError to general? - if is_PowerSeries(denom) and denom.degree() == 0 and denom[0] in self._parent.base_ring(): + if isinstance(denom, PowerSeries) and denom.degree() == 0 and denom[0] in self._parent.base_ring(): denom = denom[0] elif not denom in self._parent.base_ring(): raise ZeroDivisionError, e diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index f7c72f13b87..eb7b6e0eaf7 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -957,7 +957,7 @@ def polynomial_root(self, poly, interval, multiplicity=1): sage: r = AA.polynomial_root(p, RIF(1, 2)); r^3 2.000000000000000? """ - if not is_RealIntervalFieldElement(interval): + if not isinstance(interval, RealIntervalFieldElement): raise ValueError("interval argument of .polynomial_root on algebraic real field must be real") return AlgebraicReal(ANRoot(poly, interval, multiplicity)) @@ -1446,33 +1446,9 @@ def _factor_univariate_polynomial(self, f): from sage.structure.factorization import Factorization return Factorization([(f.parent()([-r,1]),e) for r,e in f.roots()], unit=f.leading_coefficient()) -def is_AlgebraicField(F): - r""" - Check whether ``F`` is an :class:`~AlgebraicField` instance. - - EXAMPLE:: - - sage: from sage.rings.qqbar import is_AlgebraicField - sage: [is_AlgebraicField(x) for x in [AA, QQbar, None, 0, "spam"]] - [False, True, False, False, False] - """ - return isinstance(F, AlgebraicField) - # Create the globally unique AlgebraicField object. QQbar = AlgebraicField() -def is_AlgebraicField_common(F): - r""" - Check whether ``F`` is an :class:`~AlgebraicField_common` instance. - - EXAMPLE:: - - sage: from sage.rings.qqbar import is_AlgebraicField_common - sage: [is_AlgebraicField_common(x) for x in [AA, QQbar, None, 0, "spam"]] - [True, True, False, False, False] - """ - return isinstance(F, AlgebraicField_common) - def prec_seq(): r""" Return a generator object which iterates over an infinite increasing @@ -1755,7 +1731,7 @@ def conjugate_expand(v): sage: conjugate_expand(RIF(1, 2)).str(style='brackets') '[1.0000000000000000 .. 2.0000000000000000]' """ - if is_RealIntervalFieldElement(v): + if isinstance(v, RealIntervalFieldElement): return v im = v.imag() if not im.contains_zero(): @@ -1787,7 +1763,7 @@ def conjugate_shrink(v): sage: conjugate_shrink(CIF(RIF(1, 2), RIF(-1, 2))).str(style='brackets') '[1.0000000000000000 .. 2.0000000000000000]' """ - if is_RealIntervalFieldElement(v): + if isinstance(v, RealIntervalFieldElement): return v im = v.imag() if im.contains_zero(): @@ -3617,9 +3593,9 @@ def _set_descr(self, new_descr): """ self._descr = new_descr new_val = self._descr._interval_fast(self.parent().default_interval_prec()) - if is_RealIntervalFieldElement(new_val) and is_ComplexIntervalFieldElement(self._value): + if isinstance(new_val, RealIntervalFieldElement) and is_ComplexIntervalFieldElement(self._value): self._value = self._value.real().intersection(new_val) - elif is_RealIntervalFieldElement(self._value) and is_ComplexIntervalFieldElement(new_val): + elif isinstance(self._value, RealIntervalFieldElement) and is_ComplexIntervalFieldElement(new_val): self._value = self._value.intersection(new_val.real()) else: self._value = self._value.intersection(new_val) @@ -5844,38 +5820,6 @@ def scale(self): """ return self._scale -def is_AlgebraicReal(x): - r""" - Test if ``x`` is an instance of :class:`~AlgebraicReal`. For internal use. - - EXAMPLE:: - - sage: from sage.rings.qqbar import is_AlgebraicReal - sage: is_AlgebraicReal(AA(sqrt(2))) - True - sage: is_AlgebraicReal(QQbar(sqrt(2))) - False - sage: is_AlgebraicReal("spam") - False - """ - return isinstance(x, AlgebraicReal) - -def is_AlgebraicNumber(x): - r""" - Test if ``x`` is an instance of :class:`~AlgebraicNumber`. For internal use. - - EXAMPLE:: - - sage: from sage.rings.qqbar import is_AlgebraicNumber - sage: is_AlgebraicNumber(AA(sqrt(2))) - False - sage: is_AlgebraicNumber(QQbar(sqrt(2))) - True - sage: is_AlgebraicNumber("spam") - False - """ - return isinstance(x, AlgebraicNumber) - QQbarPoly = PolynomialRing(QQbar, 'x') AAPoly = PolynomialRing(AA, 'x') @@ -5916,10 +5860,10 @@ def __init__(self, poly): sage: type(P) # indirect doctest """ - if not is_Polynomial(poly): + if not isinstance(poly, Polynomial): raise ValueError("Trying to create AlgebraicPolynomialTracker on non-Polynomial") if isinstance(poly.base_ring(), AlgebraicField_common): - complex = is_AlgebraicField(poly.base_ring()) + complex = isinstance(poly.base_ring(), AlgebraicField) else: try: poly = poly.change_ring(AA) diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index 915ed18d8d4..63cf6a1d23c 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -935,7 +935,7 @@ def ideal(self, *gens, **kwds): (not hasattr(self.__R, '_has_singular') or not self.__R._has_singular): # pass through return commutative_ring.CommutativeRing.ideal(self, gens, **kwds) - if is_SingularElement(gens): + if isinstance(gens, SingularElement): gens = list(gens) coerce = True elif not isinstance(gens, (list, tuple)): @@ -983,7 +983,7 @@ def _element_constructor_(self, x, coerce=True): if x.parent() is self: return x x = x.lift() - if is_SingularElement(x): + if isinstance(x, SingularElement): #self._singular_().set_ring() x = self.element_class(self, x.sage_poly(self.cover_ring())) return x diff --git a/src/sage/rings/residue_field.pyx b/src/sage/rings/residue_field.pyx index 6209fd989bb..8d495a04629 100644 --- a/src/sage/rings/residue_field.pyx +++ b/src/sage/rings/residue_field.pyx @@ -147,11 +147,11 @@ include "sage/ext/stdsage.pxi" from sage.rings.field import Field from sage.rings.integer import Integer from sage.rings.rational import Rational -from sage.rings.number_field.number_field_element import is_NumberFieldElement +from sage.rings.number_field.number_field_element import NumberFieldElement from sage.categories.homset import Hom from sage.categories.basic import Fields, Rings from sage.rings.all import ZZ, QQ, Integers -from sage.rings.number_field.number_field_ideal import is_NumberFieldIdeal +from sage.rings.number_field.number_field_ideal import NumberFieldIdeal import weakref from sage.rings.finite_rings.constructor import zech_log_bound, FiniteField as GF from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro @@ -168,7 +168,7 @@ from sage.rings.fraction_field import is_FractionField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.polynomial.polynomial_ring import is_PolynomialRing -from sage.rings.polynomial.polynomial_element import is_Polynomial +from sage.rings.polynomial.polynomial_element import Polynomial from sage.structure.factory import UniqueFactory @@ -291,12 +291,12 @@ class ResidueFieldFactory(UniqueFactory): if not is_Ideal(p): if isinstance(p, (int, Integer, Rational)): p = ZZ.ideal(p) - elif is_NumberFieldElement(p): + elif isinstance(p, NumberFieldElement): if p.parent().is_field(): p = p.parent().ring_of_integers().ideal(p) else: p = p.parent().ideal(p) - elif is_Polynomial(p): + elif isinstance(p, Polynomial): p = p.parent().ideal(p) #elif isinstance(p.parent(), FractionField_1poly_field): # p = p.parent().ring_of_integers().ideal(p) @@ -311,7 +311,7 @@ class ResidueFieldFactory(UniqueFactory): if not p.ring().base_ring().is_prime_field(): # neither of these will work over non-prime fields quite yet. We should use relative finite field extensions. raise NotImplementedError - elif not (is_NumberFieldIdeal(p) or p.ring() is ZZ): + elif not (isinstance(p, NumberFieldIdeal) or p.ring() is ZZ): raise NotImplementedError if isinstance(names, tuple): if len(names) > 0: @@ -358,7 +358,7 @@ class ResidueFieldFactory(UniqueFactory): raise ValueError, "unrecognized finite field type" # Should generalize to allowing residue fields of relative extensions to be extensions of finite fields. - if is_NumberFieldIdeal(p): + if isinstance(p, NumberFieldIdeal): characteristic = p.smallest_integer() else: # ideal of a function field characteristic = pring.base_ring().characteristic() diff --git a/src/sage/rings/ring_element.py b/src/sage/rings/ring_element.py index 0e042c86d36..fbd55cd881b 100644 --- a/src/sage/rings/ring_element.py +++ b/src/sage/rings/ring_element.py @@ -17,4 +17,4 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from sage.structure.element import RingElement, is_RingElement +from sage.structure.element import RingElement diff --git a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py index 3cd44853199..197c255a390 100644 --- a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py +++ b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py @@ -148,7 +148,7 @@ def isogeny_determine_algorithm(E, kernel): kernel = [kernel] kernel_is_list = True - if (is_Polynomial(kernel) or ( kernel_is_list) and (kernel[0] in E.base_ring()) ): + if (isinstance(kernel, Polynomial) or ( kernel_is_list) and (kernel[0] in E.base_ring()) ): algorithm = "kohel" elif (kernel_is_list) and (kernel[0] in E): # note that if kernel[0] is on an extension of E this diff --git a/src/sage/schemes/generic/ambient_space.py b/src/sage/schemes/generic/ambient_space.py index 72cfdaa000d..6c365bf7dda 100644 --- a/src/sage/schemes/generic/ambient_space.py +++ b/src/sage/schemes/generic/ambient_space.py @@ -252,7 +252,7 @@ def base_extend(self, R): ValueError: no natural map from the base ring (=Rational Field) to R (=Finite Field of size 5)! """ - if is_CommutativeRing(R): + if isinstance(R, CommutativeRing): if self.base_ring() == R: return self if not R.has_coerce_map_from(self.base_ring()): diff --git a/src/sage/schemes/generic/morphism.py b/src/sage/schemes/generic/morphism.py index 8f6a1707e3e..1931b52c288 100644 --- a/src/sage/schemes/generic/morphism.py +++ b/src/sage/schemes/generic/morphism.py @@ -762,7 +762,7 @@ def __init__(self, parent, phi, check=True): """ SchemeMorphism.__init__(self, parent) if check: - if not is_RingHomomorphism(phi): + if not isinstance(phi, RingHomomorphism): raise TypeError("phi (=%s) must be a ring homomorphism" % phi) if phi.domain() != parent.codomain().coordinate_ring(): raise TypeError("phi (=%s) must have domain %s" diff --git a/src/sage/schemes/generic/scheme.py b/src/sage/schemes/generic/scheme.py index d38b3de934c..a23d96bffe8 100644 --- a/src/sage/schemes/generic/scheme.py +++ b/src/sage/schemes/generic/scheme.py @@ -109,13 +109,13 @@ def __init__(self, X=None, category=None): self._base_scheme = SpecZ except ImportError: # we are currently constructing SpecZ self._base_ring = ZZ - elif is_Scheme(X): + elif isinstance(X, Scheme): self._base_scheme = X elif is_SchemeMorphism(X): self._base_morphism = X - elif is_CommutativeRing(X): + elif isinstance(X, CommutativeRing): self._base_ring = X - elif is_RingHomomorphism(X): + elif isinstance(X, RingHomomorphism): self._base_ring = X.codomain() else: raise ValueError('The base must be define by a scheme, ' @@ -155,7 +155,7 @@ def __cmp__(left, right): sage: X is Y False """ - if not is_Scheme(right): + if not isinstance(right, Scheme): return -1 return left._cmp_(right) @@ -634,7 +634,7 @@ def hom(self, x, Y=None, check=True): Defn: Structure map """ if Y is None: - if is_Scheme(x): + if isinstance(x, Scheme): return self.Hom(x).natural_map() else: raise TypeError("unable to determine codomain") diff --git a/src/sage/schemes/hyperelliptic_curves/jacobian_homset.py b/src/sage/schemes/hyperelliptic_curves/jacobian_homset.py index cd8007fce24..31b0002e097 100644 --- a/src/sage/schemes/hyperelliptic_curves/jacobian_homset.py +++ b/src/sage/schemes/hyperelliptic_curves/jacobian_homset.py @@ -132,15 +132,15 @@ def __call__(self, P): P1 = R(P1) P2 = R(P2) return JacobianMorphism_divisor_class_field(self, tuple([P1,P2])) - if is_Integer(P1) and is_Polynomial(P2): + if is_Integer(P1) and isinstance(P2, Polynomial): R = PolynomialRing(self.value_ring(), 'x') P1 = R(P1) return JacobianMorphism_divisor_class_field(self, tuple([P1,P2])) - if is_Integer(P2) and is_Polynomial(P1): + if is_Integer(P2) and isinstance(P1, Polynomial): R = PolynomialRing(self.value_ring(), 'x') P2 = R(P2) return JacobianMorphism_divisor_class_field(self, tuple([P1,P2])) - if is_Polynomial(P1) and is_Polynomial(P2): + if isinstance(P1, Polynomial) and isinstance(P2, Polynomial): return JacobianMorphism_divisor_class_field(self, tuple(P)) if is_SchemeMorphism(P1) and is_SchemeMorphism(P2): return self(P1) - self(P2) diff --git a/src/sage/schemes/plane_conics/con_rational_field.py b/src/sage/schemes/plane_conics/con_rational_field.py index afea75689d0..a846c9516a9 100644 --- a/src/sage/schemes/plane_conics/con_rational_field.py +++ b/src/sage/schemes/plane_conics/con_rational_field.py @@ -37,7 +37,7 @@ from con_number_field import ProjectiveConic_number_field -from sage.structure.element import is_InfinityElement +from sage.structure.element import InfinityElement from sage.rings.arith import (lcm, hilbert_symbol) @@ -191,7 +191,7 @@ def has_rational_point(self, point = False, obstruction = False, algorithm = algorithm, \ read_cache = read_cache) if point or obstruction: - if is_RingHomomorphism(ret[1]): + if isinstance(ret[1], RingHomomorphism): ret[1] = -1 return ret @@ -226,9 +226,9 @@ def is_locally_solvable(self, p): return True a = -abc[0]/abc[2] b = -abc[1]/abc[2] - if is_RealField(p) or is_InfinityElement(p): + if is_RealField(p) or isinstance(p, InfinityElement): p = -1 - elif is_RingHomomorphism(p): + elif isinstance(p, RingHomomorphism): if p.domain() is QQ and is_RealField(p.codomain()): p = -1 else: diff --git a/src/sage/schemes/plane_curves/constructor.py b/src/sage/schemes/plane_curves/constructor.py index 884fc87403f..80f2a2fc18f 100644 --- a/src/sage/schemes/plane_curves/constructor.py +++ b/src/sage/schemes/plane_curves/constructor.py @@ -165,7 +165,7 @@ def Curve(F): ... ValueError: defining polynomial of curve must be nonzero """ - if is_AlgebraicScheme(F): + if isinstance(F, AlgebraicScheme): return Curve(F.defining_polynomials()) if isinstance(F, (list, tuple)): diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index 2511476155c..d9aa40e3590 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -191,6 +191,7 @@ from sage.categories.category import Category from sage.structure.parent cimport Parent from sage.structure.misc import is_extension_type, getattr_from_other_class from sage.misc.lazy_format import LazyFormat +from sage.rings.ring import IntegralDomain # Create a dummy attribute error, using some kind of lazy error message, # so that neither the error itself not the message need to be created @@ -612,8 +613,8 @@ cdef class Element(sage_object.SageObject): parent=self._parent # We should better not test for ParentWIthGens, # as this is essentially deprecated. - #from sage.structure.parent_gens import is_ParentWithGens - #if not is_ParentWithGens(parent): + #from sage.structure.parent_gens import ParentWithGens + #if not isinstance(parent, ParentWithGens): # return self # Better: Duck typing! try: @@ -1384,12 +1385,6 @@ cdef class ModuleElement(Element): # Monoid ######################################################################## -def is_MonoidElement(x): - """ - Return True if x is of type MonoidElement. - """ - return IS_INSTANCE(x, MonoidElement) - cdef class MonoidElement(Element): """ Generic element of a monoid. @@ -1450,12 +1445,6 @@ cdef class MonoidElement(Element): def __nonzero__(self): return True -def is_AdditiveGroupElement(x): - """ - Return True if x is of type AdditiveGroupElement. - """ - return IS_INSTANCE(x, AdditiveGroupElement) - cdef class AdditiveGroupElement(ModuleElement): """ Generic element of an additive group. @@ -1482,12 +1471,6 @@ cdef class AdditiveGroupElement(ModuleElement): """ return None -def is_MultiplicativeGroupElement(x): - """ - Return True if x is of type MultiplicativeGroupElement. - """ - return IS_INSTANCE(x, MultiplicativeGroupElement) - cdef class MultiplicativeGroupElement(MonoidElement): """ Generic element of a multiplicative group. @@ -1520,12 +1503,6 @@ cdef class MultiplicativeGroupElement(MonoidElement): return 1/self -def is_RingElement(x): - """ - Return True if x is of type RingElement. - """ - return IS_INSTANCE(x, RingElement) - cdef class RingElement(ModuleElement): ################################################## def is_one(self): @@ -2255,7 +2232,7 @@ cdef class CommutativeRingElement(RingElement): return [ sq_rt, -sq_rt ] return sq_rt #from now on we know that self is not a square - if not is_IntegralDomain(P): + if not isinstance(P, IntegralDomain): raise NotImplementedError('sqrt() of non squares is only implemented for integral domains, not for %s' % P) if not extend: #all square roots of a non-square should be an empty list