Skip to content

Commit

Permalink
sagemathgh-37922: Deprecate is_Category, is_Endset, is_Homset, …
Browse files Browse the repository at this point in the history
…`is_Parent`, `is_RingHomset`, `is_SimplicialComplexHomset`

    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#37922
Reported by: Matthias Köppe
Reviewer(s): Vincent Delecroix
  • Loading branch information
Release Manager committed May 8, 2024
2 parents 6907458 + 78bfdcb commit ff465b3
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/sage/categories/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -2571,10 +2571,16 @@ 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
"""
from sage.misc.superseded import deprecation
deprecation(37922, "the function is_Category is deprecated; use 'isinstance(..., Category)' instead")
return isinstance(x, Category)


Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/functor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/sage/categories/homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1298,14 +1295,21 @@ def is_Homset(x):
sage: P.<t> = 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
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.
Expand All @@ -1316,9 +1320,15 @@ def is_Endset(x):
sage: P.<t> = 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())
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()
4 changes: 2 additions & 2 deletions src/sage/categories/poor_man_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/matrix_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/asymptotic/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/sage/rings/homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,6 +38,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)


Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,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]
Expand All @@ -435,7 +435,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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/sets/image_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions src/sage/structure/parent.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,18 @@ 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
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)


Expand Down
6 changes: 6 additions & 0 deletions src/sage/topology/simplicial_complex_homset.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@ 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
deprecation(37922, "the function is_SimplicialComplexHomset is deprecated; use 'isinstance(..., SimplicialComplexHomset)' instead")
return isinstance(x, SimplicialComplexHomset)


Expand Down

0 comments on commit ff465b3

Please sign in to comment.