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

Commit

Permalink
sage.modules.{free_module_homspace,vector_space_homspace,vector_space…
Browse files Browse the repository at this point in the history
…_morphism}: Use callable(...) instead of inspect.isfunction(...)
  • Loading branch information
Matthias Koeppe committed Sep 6, 2021
1 parent 903c6d4 commit 1ac057d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/sage/modules/free_module_homspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
from sage.structure.element import is_Matrix
from sage.matrix.constructor import matrix, identity_matrix
from sage.matrix.matrix_space import MatrixSpace
from inspect import isfunction
from sage.misc.cachefunc import cached_method


Expand Down Expand Up @@ -202,7 +201,7 @@ def __call__(self, A, **kwds):
# generators of the domain to the elements of A.
C = self.codomain()
try:
if isfunction(A):
if callable(A):
v = [C(A(g)) for g in self.domain().gens()]
A = matrix([C.coordinates(a) for a in v], ncols=C.rank())
if side == "right":
Expand Down
3 changes: 1 addition & 2 deletions src/sage/modules/vector_space_homspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@
# http://www.gnu.org/licenses/
####################################################################################

import inspect
import sage.matrix.all as matrix
import sage.modules.free_module_homspace

Expand Down Expand Up @@ -374,7 +373,7 @@ def __call__(self, A, check=True, **kwds):
pass
elif is_VectorSpaceMorphism(A):
A = A.matrix()
elif inspect.isfunction(A):
elif callable(A):
try:
images = [A(g) for g in D.basis()]
except (ValueError, TypeError, IndexError) as e:
Expand Down
5 changes: 2 additions & 3 deletions src/sage/modules/vector_space_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,6 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'):
from sage.categories.homset import Hom
from sage.symbolic.ring import SR
from sage.modules.vector_callable_symbolic_dense import Vector_callable_symbolic_dense
from inspect import isfunction

if not side in ['left', 'right']:
raise ValueError("side must be 'left' or 'right', not {0}".format(side))
Expand Down Expand Up @@ -734,8 +733,6 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'):
arg2 = arg2.transpose()
elif isinstance(arg2, (list, tuple)):
pass
elif isfunction(arg2):
pass
elif isinstance(arg2, Vector_callable_symbolic_dense):
args = arg2.parent().base_ring()._arguments
exprs = arg2.change_ring(SR)
Expand All @@ -758,6 +755,8 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'):
except (ArithmeticError, TypeError) as e:
msg = 'some image of the function is not in the codomain, because\n' + e.args[0]
raise ArithmeticError(msg)
elif callable(arg2):
pass
else:
msg = 'third argument must be a matrix, function, or list of images, not {0}'
raise TypeError(msg.format(arg2))
Expand Down

0 comments on commit 1ac057d

Please sign in to comment.