From a9c114c0264113945ec178a2f37feb1961fcb41f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 May 2024 21:58:48 -0700 Subject: [PATCH 1/6] src/sage/categories/category.py: Deprecate is_Category --- src/sage/categories/category.py | 2 ++ src/sage/categories/functor.pyx | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sage/categories/category.py b/src/sage/categories/category.py index ce316e50138..f6d7552de58 100644 --- a/src/sage/categories/category.py +++ b/src/sage/categories/category.py @@ -2575,6 +2575,8 @@ def is_Category(x): sage: sage.categories.category.is_Category(ZZ) False """ + from sage.misc.superseded import deprecation + deprecation(37922, "the function is_Category is deprecated; use 'isinstance(..., Category)' instead") return isinstance(x, Category) diff --git a/src/sage/categories/functor.pyx b/src/sage/categories/functor.pyx index 889de1d7e7d..34678169ac5 100644 --- a/src/sage/categories/functor.pyx +++ b/src/sage/categories/functor.pyx @@ -179,9 +179,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 From bb424cf5e84206626395fa5f13369b11817235e3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 May 2024 22:05:38 -0700 Subject: [PATCH 2/6] src/sage/categories/homset.py: Deprecate is_Homset, is_Endset --- src/sage/categories/homset.py | 5 +++++ src/sage/modules/matrix_morphism.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sage/categories/homset.py b/src/sage/categories/homset.py index 29f4c7df69a..a3149248c5b 100644 --- a/src/sage/categories/homset.py +++ b/src/sage/categories/homset.py @@ -1304,8 +1304,11 @@ def is_Homset(x): sage: is_Homset(f.parent()) True """ + from sage.misc.superseded import deprecation + deprecation(37922, "the function is_Homset is deprecated; use 'isinstance(..., Homset)' instead") return isinstance(x, Homset) + def is_Endset(x): """ Return ``True`` if ``x`` is a set of endomorphisms in a category. @@ -1321,4 +1324,6 @@ def is_Endset(x): sage: is_Endset(g.parent()) True """ + from sage.misc.superseded import deprecation + deprecation(37922, "the function is_Endset is deprecated; use 'isinstance(..., Homset) and ....is_endomorphism_set()' instead") return isinstance(x, Homset) and x.is_endomorphism_set() diff --git a/src/sage/modules/matrix_morphism.py b/src/sage/modules/matrix_morphism.py index ce2b88ede82..c1f882852fd 100644 --- a/src/sage/modules/matrix_morphism.py +++ b/src/sage/modules/matrix_morphism.py @@ -112,7 +112,7 @@ def __init__(self, parent, side='left'): sage: loads(A.dumps()) == A True """ - if not sage.categories.homset.is_Homset(parent): + if not isinstance(parent, sage.categories.homset.Homset): raise TypeError("parent must be a Hom space") if side not in ["left", "right"]: raise ValueError("the argument side must be either 'left' or 'right'") From e8f71b626cc027e7b37bcdd417a49929552e42c3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 12 May 2024 13:59:46 -0700 Subject: [PATCH 3/6] src/sage/structure/parent.pyx: Deprecate is_Parent --- src/sage/categories/poor_man_map.py | 4 ++-- src/sage/rings/asymptotic/misc.py | 4 ++-- src/sage/rings/ring.pyx | 4 ++-- src/sage/sets/image_set.py | 4 ++-- src/sage/structure/parent.pyx | 2 ++ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/sage/categories/poor_man_map.py b/src/sage/categories/poor_man_map.py index 6fc55a02104..1ee3962f84f 100644 --- a/src/sage/categories/poor_man_map.py +++ b/src/sage/categories/poor_man_map.py @@ -225,8 +225,8 @@ def __mul__(self, other): other_codomain = None if self_domain is not None and other_codomain is not None: - from sage.structure.parent import is_Parent - if is_Parent(self_domain) and is_Parent(other_codomain): + from sage.structure.parent import Parent + if isinstance(self_domain, Parent) and isinstance(other_codomain, Parent): if not self_domain.has_coerce_map_from(other_codomain): raise ValueError("the codomain %r does not coerce into the domain %r" % (other_codomain, self_domain)) diff --git a/src/sage/rings/asymptotic/misc.py b/src/sage/rings/asymptotic/misc.py index 8117d8ede30..c33ea3e5a94 100644 --- a/src/sage/rings/asymptotic/misc.py +++ b/src/sage/rings/asymptotic/misc.py @@ -95,8 +95,8 @@ def extract(s): if type(P) is LazyImport: P = P._get_object() - from sage.structure.parent import is_Parent - if not is_Parent(P): + from sage.structure.parent import Parent + if not isinstance(P, Parent): raise ValueError("'%s' does not describe a parent." % (s,)) return P diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 36f8336786c..f01c1be5f69 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -426,7 +426,7 @@ cdef class Ring(ParentWithGens): coerce = True from sage.rings.ideal import Ideal_generic - from sage.structure.parent import is_Parent + from sage.structure.parent import Parent gens = args while isinstance(gens, (list, tuple)) and len(gens) == 1: first = gens[0] @@ -445,7 +445,7 @@ cdef class Ring(ParentWithGens): break elif isinstance(first, (list, tuple)): gens = first - elif is_Parent(first) and self.has_coerce_map_from(first): + elif isinstance(first, Parent) and self.has_coerce_map_from(first): gens = first.gens() # we have a ring as argument else: break diff --git a/src/sage/sets/image_set.py b/src/sage/sets/image_set.py index c98fc8c534b..07ef2de695d 100644 --- a/src/sage/sets/image_set.py +++ b/src/sage/sets/image_set.py @@ -27,7 +27,7 @@ from sage.rings.integer import Integer from sage.modules.free_module import FreeModule from sage.structure.element import Expression -from sage.structure.parent import Parent, is_Parent +from sage.structure.parent import Parent from .set import Set_base, Set_add_sub_operators, Set_boolean_operators @@ -82,7 +82,7 @@ def __init__(self, map, domain_subset, *, category=None, is_injective=None, inve sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling', ....: '_test_some_elements', '_test_elements']) """ - if not is_Parent(domain_subset): + if not isinstance(domain_subset, Parent): from sage.sets.set import Set domain_subset = Set(domain_subset) diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 2b579cdc60a..2dbfde5c9d1 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -154,6 +154,8 @@ def is_Parent(x): sage: is_Parent(Primes()) True """ + from sage.misc.superseded import deprecation_cython + deprecation_cython(37922, "the function is_Parent is deprecated; use 'isinstance(..., Parent)' instead") return isinstance(x, Parent) From 50b2035e3ecf5ca28b0c307143399bbb18e1a5cf Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 May 2024 22:15:32 -0700 Subject: [PATCH 4/6] src/sage/topology/simplicial_complex_homset.py: Deprecate is_SimplicialComplexHomset --- src/sage/topology/simplicial_complex_homset.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sage/topology/simplicial_complex_homset.py b/src/sage/topology/simplicial_complex_homset.py index 255e905a990..a5aeaafc15d 100644 --- a/src/sage/topology/simplicial_complex_homset.py +++ b/src/sage/topology/simplicial_complex_homset.py @@ -79,6 +79,8 @@ def is_SimplicialComplexHomset(x) -> bool: sage: is_SimplicialComplexHomset(H) True """ + from sage.misc.superseded import deprecation + deprecation(37922, "the function is_SimplicialComplexHomset is deprecated; use 'isinstance(..., SimplicialComplexHomset)' instead") return isinstance(x, SimplicialComplexHomset) From 8b37e56f5d295153e1d416d9e93e87284f7a5242 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 May 2024 22:20:25 -0700 Subject: [PATCH 5/6] src/sage/rings/homset.py: Deprecate is_RingHomset --- src/sage/rings/homset.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sage/rings/homset.py b/src/sage/rings/homset.py index b2f24a3800a..59131f326e2 100644 --- a/src/sage/rings/homset.py +++ b/src/sage/rings/homset.py @@ -34,6 +34,8 @@ def is_RingHomset(H): sage: is_RH(Hom(FreeModule(ZZ,1), FreeModule(QQ,1))) # needs sage.modules False """ + from sage.misc.superseded import deprecation + deprecation(37922, "the function is_RingHomset is deprecated; use 'isinstance(..., RingHomset_generic)' instead") return isinstance(H, RingHomset_generic) From ff1834aadf753864383110c7b1dce5f68029fa5e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 May 2024 22:53:44 -0700 Subject: [PATCH 6/6] Update doctests with deprecation warnings --- src/sage/categories/category.py | 4 ++++ src/sage/categories/homset.py | 11 ++++++++--- src/sage/rings/homset.py | 4 ++++ src/sage/structure/parent.pyx | 4 ++++ src/sage/topology/simplicial_complex_homset.py | 4 ++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/sage/categories/category.py b/src/sage/categories/category.py index f6d7552de58..37192366c6d 100644 --- a/src/sage/categories/category.py +++ b/src/sage/categories/category.py @@ -2571,6 +2571,10 @@ def is_Category(x): EXAMPLES:: sage: sage.categories.category.is_Category(CommutativeAdditiveSemigroups()) + doctest:warning... + DeprecationWarning: the function is_Category is deprecated; + use 'isinstance(..., Category)' instead + See https://github.com/sagemath/sage/issues/37922 for details. True sage: sage.categories.category.is_Category(ZZ) False diff --git a/src/sage/categories/homset.py b/src/sage/categories/homset.py index a3149248c5b..e763a022d4c 100644 --- a/src/sage/categories/homset.py +++ b/src/sage/categories/homset.py @@ -522,9 +522,6 @@ def End(X, category=None): from Alternating group of order 3!/2 as a permutation group to Alternating group of order 3!/2 as a permutation group in Category of finite enumerated permutation groups - sage: from sage.categories.homset import is_Endset - sage: is_Endset(S) - True sage: S.domain() Alternating group of order 3!/2 as a permutation group @@ -1298,6 +1295,10 @@ def is_Homset(x): sage: P. = ZZ[] sage: f = P.hom([1/2*t]) sage: is_Homset(f) + doctest:warning... + DeprecationWarning: the function is_Homset is deprecated; + use 'isinstance(..., Homset)' instead + See https://github.com/sagemath/sage/issues/37922 for details. False sage: is_Homset(f.category()) False @@ -1319,6 +1320,10 @@ def is_Endset(x): sage: P. = ZZ[] sage: f = P.hom([1/2*t]) sage: is_Endset(f.parent()) + doctest:warning... + DeprecationWarning: the function is_Endset is deprecated; + use 'isinstance(..., Homset) and ....is_endomorphism_set()' instead + See https://github.com/sagemath/sage/issues/37922 for details. False sage: g = P.hom([2*t]) sage: is_Endset(g.parent()) diff --git a/src/sage/rings/homset.py b/src/sage/rings/homset.py index 59131f326e2..6e3126d7ebd 100644 --- a/src/sage/rings/homset.py +++ b/src/sage/rings/homset.py @@ -26,6 +26,10 @@ def is_RingHomset(H): sage: from sage.rings.homset import is_RingHomset as is_RH sage: is_RH(Hom(ZZ, QQ)) + doctest:warning... + DeprecationWarning: the function is_RingHomset is deprecated; + use 'isinstance(..., RingHomset_generic)' instead + See https://github.com/sagemath/sage/issues/37922 for details. True sage: is_RH(ZZ) False diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 2dbfde5c9d1..c775be1a023 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -148,6 +148,10 @@ def is_Parent(x): sage: from sage.structure.parent import is_Parent sage: is_Parent(2/3) + doctest:warning... + DeprecationWarning: the function is_Parent is deprecated; + use 'isinstance(..., Parent)' instead + See https://github.com/sagemath/sage/issues/37922 for details. False sage: is_Parent(ZZ) True diff --git a/src/sage/topology/simplicial_complex_homset.py b/src/sage/topology/simplicial_complex_homset.py index a5aeaafc15d..eaad72b8905 100644 --- a/src/sage/topology/simplicial_complex_homset.py +++ b/src/sage/topology/simplicial_complex_homset.py @@ -77,6 +77,10 @@ def is_SimplicialComplexHomset(x) -> bool: in Category of finite simplicial complexes sage: from sage.topology.simplicial_complex_homset import is_SimplicialComplexHomset sage: is_SimplicialComplexHomset(H) + doctest:warning... + DeprecationWarning: the function is_SimplicialComplexHomset is deprecated; + use 'isinstance(..., SimplicialComplexHomset)' instead + See https://github.com/sagemath/sage/issues/37922 for details. True """ from sage.misc.superseded import deprecation