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

Deprecate is_Map, is_...Morphism #38103

Merged
merged 5 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sage/categories/functor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ cdef class Functor(SageObject):
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.Homsets())):
Expand Down
5 changes: 5 additions & 0 deletions src/sage/categories/map.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ def is_Map(x):
sage: f = R.hom([x+y, x-y], R)
sage: from sage.categories.map import is_Map
sage: is_Map(f)
doctest:warning...
DeprecationWarning: The function is_Map is deprecated; use 'isinstance(..., Map)' instead.
See https://github.com/sagemath/sage/issues/38103 for details.
True
"""
from sage.misc.superseded import deprecation_cython
deprecation_cython(38103, "The function is_Map is deprecated; use 'isinstance(..., Map)' instead.")
return isinstance(x, Map)


Expand Down
2 changes: 2 additions & 0 deletions src/sage/categories/morphism.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ from sage.structure.parent cimport Parent


def is_Morphism(x):
from sage.misc.superseded import deprecation_cython
deprecation_cython(38103, "The function is_Morphism is deprecated; use 'isinstance(..., Morphism)' instead.")
return isinstance(x, Morphism)


Expand Down
4 changes: 4 additions & 0 deletions src/sage/groups/abelian_gps/abelian_group_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@


def is_AbelianGroupMorphism(f):
from sage.misc.superseded import deprecation
deprecation(38103,
"The function is_AbelianGroupMorphism is deprecated; "
"use 'isinstance(..., AbelianGroupMorphism)' instead.")
return isinstance(f, AbelianGroupMorphism)


Expand Down
8 changes: 8 additions & 0 deletions src/sage/groups/perm_gps/permgroup_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ def is_PermutationGroupMorphism(f) -> bool:
sage: H = DihedralGroup(4)
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
sage: is_PermutationGroupMorphism(phi)
doctest:warning...
DeprecationWarning: The function is_PermutationGroupMorphism is deprecated;
use 'isinstance(..., PermutationGroupMorphism)' instead.
See https://github.com/sagemath/sage/issues/38103 for details.
True
"""
from sage.misc.superseded import deprecation
deprecation(38103,
"The function is_PermutationGroupMorphism is deprecated; "
"use 'isinstance(..., PermutationGroupMorphism)' instead.")
return isinstance(f, PermutationGroupMorphism)
8 changes: 8 additions & 0 deletions src/sage/homology/chain_complex_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@ def is_ChainComplexMorphism(x):
From: Chain complex with at most 7 nonzero terms over Integer Ring
To: Chain complex with at most 7 nonzero terms over Integer Ring
sage: is_ChainComplexMorphism(x)
doctest:warning...
DeprecationWarning: The function is_ChainComplexMorphism is deprecated;
use 'isinstance(..., ChainComplexMorphism)' instead.
See https://github.com/sagemath/sage/issues/38103 for details.
True
"""
from sage.misc.superseded import deprecation
deprecation(38103,
"The function is_ChainComplexMorphism is deprecated; "
"use 'isinstance(..., ChainComplexMorphism)' instead.")
return isinstance(x, ChainComplexMorphism)


Expand Down
4 changes: 2 additions & 2 deletions src/sage/modules/fg_pid/fgp_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# https://www.gnu.org/licenses/
# *************************************************************************

from sage.categories.morphism import Morphism, is_Morphism
from sage.categories.morphism import Morphism
from .fgp_module import DEBUG
from sage.structure.richcmp import richcmp, op_NE
from sage.misc.cachefunc import cached_method
Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(self, parent, phi, check=True):
# input: phi is a morphism from MO = M.optimized().V() to N.V()
# that sends MO.W() to N.W()
if check:
if not is_Morphism(phi) and M == N:
if not isinstance(phi, Morphism) and M == N:
A = M.optimized()[0].V()
B = N.V()
s = M.base_ring()(phi) * B.coordinate_module(A).basis_matrix()
Expand Down
4 changes: 2 additions & 2 deletions src/sage/quivers/morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ def __init__(self, domain, codomain, data={}):
start_index += dim

# Get the coordinates of the vector
from sage.categories.map import is_Map
from sage.categories.map import Map
vector = []
for v in self._quiver:
if v in maps_dict:
if is_Map(maps_dict[v]):
if isinstance(maps_dict[v], Map):
try:
m = maps_dict[v].matrix()
except (AttributeError, ValueError):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/quivers/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def create_key(self, k, P, *args, **kwds):
# Note that the first space is assigned to key[3] and the first
# vertex is 1 so the space assigned to vertex v is key[2 + v]
from sage.matrix.constructor import Matrix
from sage.categories.morphism import is_Morphism
from sage.categories.morphism import Morphism
for x in P._sorted_edges:
if x in maps:
e = maps[x]
Expand All @@ -724,7 +724,7 @@ def create_key(self, k, P, *args, **kwds):
# If a morphism is specified take it's matrix. Create one if
# needed. Otherwise assume the Matrix function can convert the
# object to a Matrix.
if is_Morphism(e):
if isinstance(e, Morphism):
if hasattr(e, 'matrix'):
key.append(e.matrix())
else:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/finite_rings/finite_field_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ cdef class FiniteField(Field):
return self.__vector_space

from sage.modules.free_module import VectorSpace
from sage.categories.morphism import is_Morphism
from sage.categories.morphism import Morphism

if base is None:
base = self.prime_subfield()
Expand All @@ -1269,7 +1269,7 @@ cdef class FiniteField(Field):
self.__vector_space = VectorSpace(base, s)
V = self.__vector_space
inclusion_map = None
elif is_Morphism(base):
elif isinstance(base, Morphism):
inclusion_map = base
base = inclusion_map.domain()
s = self.degree() // base.degree()
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ def apply_morphism(self, phi):
sage: taus[1](B) # needs sage.rings.number_fields
Fractional ideal (2, a + 1)
"""
from sage.categories.morphism import is_Morphism
if not is_Morphism(phi):
from sage.categories.morphism import Morphism
if not isinstance(phi, Morphism):
raise TypeError("phi must be a morphism")
# delegate: morphisms know how to apply themselves to ideals
return phi(self)
Expand Down
10 changes: 5 additions & 5 deletions src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,18 +1438,18 @@ def _convert_map_from_(self, other):
i - a

"""
from sage.categories.map import is_Map
from sage.categories.map import Map
if self._structure is not None:
structure = self.structure()
if len(structure) >= 2:
to_self = structure[1]
if is_Map(to_self) and to_self.domain() is other:
if isinstance(to_self, Map) and to_self.domain() is other:
return to_self
if isinstance(other, NumberField_generic) and other._structure is not None:
structure = other.structure()
if len(structure) >= 1:
from_other = structure[0]
if is_Map(from_other) and from_other.codomain() is self:
if isinstance(from_other, Map) and from_other.codomain() is self:
return from_other

@cached_method
Expand Down Expand Up @@ -9956,8 +9956,8 @@ def relativize(self, alpha, names, structure=None):
from sage.matrix.constructor import matrix
from sage.modules.free_module_element import vector

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")
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/number_field/number_field_rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

import sage.libs.ntl.all as ntl

from sage.categories.map import is_Map
from sage.categories.map import Map
from sage.structure.sequence import Sequence

import sage.structure.parent_gens
Expand Down Expand Up @@ -2678,7 +2678,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
Expand Down
6 changes: 3 additions & 3 deletions src/sage/sets/image_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from typing import Iterator

from sage.categories.map import is_Map
from sage.categories.map import Map
from sage.categories.poor_man_map import PoorManMap
from sage.categories.sets_cat import Sets
from sage.categories.enumerated_sets import EnumeratedSets
Expand Down Expand Up @@ -86,7 +86,7 @@ def __init__(self, map, domain_subset, *, category=None, is_injective=None, inve
from sage.sets.set import Set
domain_subset = Set(domain_subset)

if not is_Map(map) and not isinstance(map, PoorManMap):
if not isinstance(map, Map) and not isinstance(map, PoorManMap):
map_name = f"The map {map}"
if isinstance(map, Expression) and map.is_callable():
domain = map.parent().base()
Expand All @@ -100,7 +100,7 @@ def map(arg):
domain = domain_subset
map = PoorManMap(map, domain, name=map_name)

if is_Map(map):
if isinstance(map, Map):
map_category = map.category_for()
if is_injective is None:
try:
Expand Down
8 changes: 8 additions & 0 deletions src/sage/topology/simplicial_complex_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,17 @@ def is_SimplicialComplexMorphism(x):
sage: f = {0:0,1:1,3:3,4:4}
sage: x = H(f)
sage: is_SimplicialComplexMorphism(x)
doctest:warning...
DeprecationWarning: The function is_SimplicialComplexMorphism is deprecated;
use 'isinstance(..., SimplicialComplexMorphism)' instead.
See https://github.com/sagemath/sage/issues/38103 for details.
True

"""
from sage.misc.superseded import deprecation
deprecation(38103,
"The function is_SimplicialComplexMorphism is deprecated; "
"use 'isinstance(..., SimplicialComplexMorphism)' instead.")
return isinstance(x, SimplicialComplexMorphism)


Expand Down
Loading