diff --git a/src/sage/geometry/cone.py b/src/sage/geometry/cone.py index fc0b3731945..6dabca389f9 100644 --- a/src/sage/geometry/cone.py +++ b/src/sage/geometry/cone.py @@ -211,7 +211,6 @@ from sage.combinat.posets.posets import FinitePoset from sage.geometry.point_collection import PointCollection from sage.geometry.polyhedron.constructor import Polyhedron -from sage.geometry.polyhedron.base import is_Polyhedron from sage.geometry.hasse_diagram import lattice_from_incidences from sage.geometry.toric_lattice import (ToricLattice, is_ToricLattice, is_ToricLatticeQuotient) @@ -259,6 +258,9 @@ def is_Cone(x): sage: from sage.geometry.cone import is_Cone sage: is_Cone(1) + doctest:warning... + DeprecationWarning: is_Cone is deprecated, use isinstance instead + See https://github.com/sagemath/sage/issues/34307 for details. False sage: quadrant = Cone([(1,0), (0,1)]) sage: quadrant @@ -266,6 +268,8 @@ def is_Cone(x): sage: is_Cone(quadrant) True """ + from sage.misc.superseded import deprecation + deprecation(34307, "is_Cone is deprecated, use isinstance instead") return isinstance(x, ConvexRationalPolyhedralCone) @@ -439,7 +443,7 @@ def Cone(rays, lattice=None, check=True, normalize=True): 0-d cone in 2-d lattice N """ # Cone from Polyhedron - if is_Polyhedron(rays): + if isinstance(rays, sage.geometry.abc.Polyhedron): polyhedron = rays if lattice is None: lattice = ToricLattice(polyhedron.ambient_dim()) @@ -1894,7 +1898,7 @@ def cartesian_product(self, other, lattice=None): N+N(0, 1) in 2-d lattice N+N """ - assert is_Cone(other) + assert isinstance(other, sage.geometry.abc.ConvexRationalPolyhedralCone) rc = super().cartesian_product(other, lattice) return ConvexRationalPolyhedralCone(rc.rays(), rc.lattice()) @@ -1952,7 +1956,7 @@ def __richcmp__(self, right, op): sage: c2 is c3 False """ - if is_Cone(right): + if isinstance(right, sage.geometry.abc.ConvexRationalPolyhedralCone): # We don't care about particular type of right in this case return richcmp((self.lattice(), self.rays()), (right.lattice(), right.rays()), op) @@ -2413,7 +2417,7 @@ def embed(self, cone): ValueError: 2-d cone in 3-d lattice N is not a face of 3-d cone in 3-d lattice N! """ - assert is_Cone(cone) + assert isinstance(cone, sage.geometry.abc.ConvexRationalPolyhedralCone) if cone.ambient() is self: return cone if self.is_strictly_convex(): @@ -2935,7 +2939,7 @@ def facet_of(self): L = self._ambient._face_lattice_function() H = L.hasse_diagram() return self._sort_faces( - f for f in H.neighbors_out(L(self)) if is_Cone(f)) + f for f in H.neighbors_out(L(self)) if isinstance(f, sage.geometry.abc.ConvexRationalPolyhedralCone)) def facets(self): r""" @@ -6387,9 +6391,8 @@ def random_cone(lattice=None, min_ambient_dim=0, max_ambient_dim=None, It's hard to test the output of a random process, but we can at least make sure that we get a cone back:: - sage: from sage.geometry.cone import is_Cone sage: K = random_cone(max_ambient_dim=6, max_rays=10) - sage: is_Cone(K) + sage: isinstance(K, sage.geometry.abc.ConvexRationalPolyhedralCone) True The upper/lower bounds are respected:: diff --git a/src/sage/geometry/fan.py b/src/sage/geometry/fan.py index 832a76bb65d..0fffcdeb58c 100644 --- a/src/sage/geometry/fan.py +++ b/src/sage/geometry/fan.py @@ -238,6 +238,8 @@ from copy import copy from warnings import warn +import sage.geometry.abc + from sage.structure.richcmp import richcmp_method, richcmp from sage.combinat.combination import Combinations from sage.combinat.posets.posets import FinitePoset @@ -245,7 +247,6 @@ Cone, ConvexRationalPolyhedralCone, IntegralRayCollection, - is_Cone, normalize_rays) from sage.geometry.hasse_diagram import lattice_from_incidences from sage.geometry.point_collection import PointCollection @@ -571,7 +572,7 @@ def result(): cones = ((), ) rays = () return result() - if is_Cone(cones[0]): + if isinstance(cones[0], sage.geometry.abc.ConvexRationalPolyhedralCone): # Construct the fan from Cone objects if lattice is None: lattice = cones[0].lattice() @@ -749,11 +750,10 @@ def FaceFan(polytope, lattice=None): ValueError: face fans are defined only for polytopes containing the origin as an interior point! """ - from sage.geometry.lattice_polytope import is_LatticePolytope interior_point_error = ValueError( "face fans are defined only for polytopes containing " "the origin as an interior point!") - if is_LatticePolytope(polytope): + if isinstance(polytope, sage.geometry.abc.LatticePolytope): if any(d <= 0 for d in polytope.distances([0] * polytope.dim())): raise interior_point_error cones = (f.ambient_vertex_indices() for f in polytope.facets()) @@ -843,8 +843,7 @@ def NormalFan(polytope, lattice=None): """ dimension_error = ValueError( 'the normal fan is only defined for full-dimensional polytopes') - from sage.geometry.lattice_polytope import is_LatticePolytope - if is_LatticePolytope(polytope): + if isinstance(polytope, sage.geometry.abc.LatticePolytope): if polytope.dim() != polytope.lattice_dim(): raise dimension_error rays = polytope.facet_normals() @@ -2425,7 +2424,7 @@ def embed(self, cone): ValueError: 2-d cone in 3-d lattice N does not belong to Rational polyhedral fan in 3-d lattice N! """ - if not is_Cone(cone): + if not isinstance(cone, sage.geometry.abc.ConvexRationalPolyhedralCone): raise TypeError("%s is not a cone!" % cone) if cone.ambient() is self: return cone diff --git a/src/sage/geometry/hyperplane_arrangement/hyperplane.py b/src/sage/geometry/hyperplane_arrangement/hyperplane.py index 9ca1a7c42ac..dfd1e4c6169 100644 --- a/src/sage/geometry/hyperplane_arrangement/hyperplane.py +++ b/src/sage/geometry/hyperplane_arrangement/hyperplane.py @@ -108,9 +108,10 @@ # http://www.gnu.org/licenses/ # ***************************************************************************** +import sage.geometry.abc -from sage.misc.cachefunc import cached_method from sage.geometry.linear_expression import LinearExpression, LinearExpressionModule +from sage.misc.cachefunc import cached_method class Hyperplane(LinearExpression): @@ -460,9 +461,8 @@ def intersection(self, other): sage: h.intersection(polytopes.cube()) A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 3 vertices """ - from sage.geometry.polyhedron.base import is_Polyhedron from sage.geometry.polyhedron.constructor import Polyhedron - if not is_Polyhedron(other): + if not isinstance(other, sage.geometry.abc.Polyhedron): try: other = other.polyhedron() except AttributeError: diff --git a/src/sage/geometry/lattice_polytope.py b/src/sage/geometry/lattice_polytope.py index b652e68c946..666548b9f39 100644 --- a/src/sage/geometry/lattice_polytope.py +++ b/src/sage/geometry/lattice_polytope.py @@ -482,6 +482,9 @@ def is_LatticePolytope(x): sage: from sage.geometry.lattice_polytope import is_LatticePolytope sage: is_LatticePolytope(1) + doctest:warning... + DeprecationWarning: is_LatticePolytope is deprecated, use isinstance instead + See https://github.com/sagemath/sage/issues/34307 for details. False sage: p = LatticePolytope([(1,0), (0,1), (-1,-1)]) sage: p # needs palp @@ -489,6 +492,8 @@ def is_LatticePolytope(x): sage: is_LatticePolytope(p) True """ + from sage.misc.superseded import deprecation + deprecation(34307, "is_LatticePolytope is deprecated, use isinstance instead") return isinstance(x, LatticePolytopeClass) @richcmp_method @@ -989,7 +994,7 @@ def _palp(self, command, reduce_dimension=False): sage: o = lattice_polytope.cross_polytope(3) sage: o._palp("poly.x -f") # needs palp 'M:7 6 N:27 8 Pic:17 Cor:0\n' - sage: print(o._palp("nef.x -f -N -p")) # random time information # needs palp + sage: print(o._palp("nef.x -f -N -p")) # random time information # needs palp M:27 8 N:7 6 codim=2 #part=5 H:[0] P:0 V:2 4 5 0sec 0cpu H:[0] P:2 V:3 4 5 0sec 0cpu @@ -1234,7 +1239,7 @@ def _read_nef_partitions(self, data): sage: o = lattice_polytope.cross_polytope(3) sage: s = o.nef_x("-p -N -Lv") # needs palp - sage: print(s) # random time values # needs palp + sage: print(s) # random time values # needs palp M:27 8 N:7 6 codim=2 #part=5 3 6 Vertices in N-lattice: 1 0 0 -1 0 0 @@ -3139,7 +3144,7 @@ def normal_form(self, algorithm="palp_native", permutation=False): M( 12, -1, -9, -6, 6), M( 12, -1, -6, -3, 3) in 5-d lattice M - sage: P.normal_form(algorithm="palp_modified") # not tested (22s; MemoryError on 32 bit), needs sage.groups + sage: P.normal_form(algorithm="palp_modified") # not tested (22s; MemoryError on 32 bit), needs sage.groups M( 6, 0, 0, 0, 0), M( -6, 0, 0, 0, 0), M( 0, 1, 0, 0, 0), @@ -5264,7 +5269,7 @@ def _read_nef_x_partitions(data): sage: o = lattice_polytope.cross_polytope(3) sage: s = o.nef_x("-N -p") # needs palp - sage: print(s) # random # needs palp + sage: print(s) # random # needs palp M:27 8 N:7 6 codim=2 #part=5 P:0 V:2 4 5 0sec 0cpu P:2 V:3 4 5 0sec 0cpu diff --git a/src/sage/geometry/newton_polygon.py b/src/sage/geometry/newton_polygon.py index 28101e70646..c8e185d01e6 100644 --- a/src/sage/geometry/newton_polygon.py +++ b/src/sage/geometry/newton_polygon.py @@ -14,6 +14,8 @@ # https://www.gnu.org/licenses/ ############################################################################# +import sage.geometry.abc + from sage.structure.unique_representation import UniqueRepresentation from sage.structure.parent import Parent from sage.structure.element import Element @@ -22,7 +24,6 @@ from sage.rings.infinity import Infinity from sage.geometry.polyhedron.constructor import Polyhedron -from sage.geometry.polyhedron.base import is_Polyhedron class NewtonPolygon_element(Element): @@ -716,7 +717,7 @@ def _element_constructor_(self, arg, sort_slopes=True, last_slope=Infinity): sage: NewtonPolygon(1) Finite Newton polygon with 1 vertex: (0, 0) """ - if is_Polyhedron(arg): + if isinstance(arg, sage.geometry.abc.Polyhedron): return self.element_class(arg, parent=self) if arg == 0: polyhedron = Polyhedron(base_ring=self.base_ring(), ambient_dim=2) diff --git a/src/sage/geometry/polyhedral_complex.py b/src/sage/geometry/polyhedral_complex.py index 09200a60be9..981404eb174 100644 --- a/src/sage/geometry/polyhedral_complex.py +++ b/src/sage/geometry/polyhedral_complex.py @@ -110,9 +110,11 @@ # **************************************************************************** from copy import copy + +import sage.geometry.abc + from sage.topology.cell_complex import GenericCellComplex from sage.geometry.polyhedron.constructor import Polyhedron -from sage.geometry.polyhedron.base import is_Polyhedron from sage.modules.free_module_element import vector from sage.rings.integer_ring import ZZ from sage.graphs.graph import Graph @@ -308,7 +310,7 @@ def __init__(self, maximal_cells=None, backend=None, maximality_check=True, ambient_dim = next(iter(cells_dict[self._dim])).ambient_dim() self._ambient_dim = ambient_dim self._maximal_cells = cells_dict - if not all((is_Polyhedron(cell) and + if not all((isinstance(cell, sage.geometry.abc.Polyhedron) and cell.ambient_dim() == self._ambient_dim) for cell in self.maximal_cell_iterator()): raise ValueError("the given cells are not polyhedra " + @@ -959,7 +961,7 @@ def __contains__(self, x): sage: (0, 0) in pc # not a polyhedron False """ - if not is_Polyhedron(x): + if not isinstance(x, sage.geometry.abc.Polyhedron): return False dim = x.dimension() return dim in self.cells() and x in self.cells()[dim] @@ -2028,7 +2030,7 @@ def add_cell(self, cell): """ if self._is_immutable: raise ValueError("this polyhedral complex is not mutable") - if not is_Polyhedron(cell) or cell.ambient_dim() != self._ambient_dim: + if not isinstance(cell, sage.geometry.abc.Polyhedron) or cell.ambient_dim() != self._ambient_dim: raise ValueError("the given cell is not a polyhedron " + "in the same ambient space") # if cell is already in self, do nothing. @@ -2191,7 +2193,7 @@ def remove_cell(self, cell, check=False): """ if self._is_immutable: raise ValueError("this polyhedral complex is not mutable") - if not is_Polyhedron(cell) or cell.ambient_dim() != self._ambient_dim: + if not isinstance(cell, sage.geometry.abc.Polyhedron) or cell.ambient_dim() != self._ambient_dim: raise ValueError("the given cell is not a polyhedron " + "in the same ambient space") # if cell is not in self, delete nothing. diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py index f9ce84be09d..82e92b72bd3 100644 --- a/src/sage/geometry/polyhedron/base.py +++ b/src/sage/geometry/polyhedron/base.py @@ -74,10 +74,15 @@ def is_Polyhedron(X): sage: p = polytopes.hypercube(2) sage: from sage.geometry.polyhedron.base import is_Polyhedron sage: is_Polyhedron(p) + doctest:warning... + DeprecationWarning: is_Polyhedron is deprecated, use isinstance instead + See https://github.com/sagemath/sage/issues/34307 for details. True sage: is_Polyhedron(123456) False """ + from sage.misc.superseded import deprecation + deprecation(34307, "is_Polyhedron is deprecated, use isinstance instead") return isinstance(X, Polyhedron_base) diff --git a/src/sage/geometry/polyhedron/parent.py b/src/sage/geometry/polyhedron/parent.py index 7dafad76437..5fad17dc55a 100644 --- a/src/sage/geometry/polyhedron/parent.py +++ b/src/sage/geometry/polyhedron/parent.py @@ -9,6 +9,8 @@ # https://www.gnu.org/licenses/ # ***************************************************************************** +import sage.geometry.abc + from sage.structure.parent import Parent from sage.structure.element import get_coercion_model from sage.structure.unique_representation import UniqueRepresentation @@ -22,8 +24,6 @@ from sage.categories.fields import Fields from sage.categories.rings import Rings from sage.categories.modules import Modules - -from sage.geometry.polyhedron.base import is_Polyhedron from .representation import Inequality, Equation, Vertex, Ray, Line @@ -691,7 +691,7 @@ def convert_base_ring_Hrep(lstlst): if convert and Vrep: Vrep = [convert_base_ring(_) for _ in Vrep] return self.element_class(self, Vrep, Hrep, **kwds) - if nargs == 1 and is_Polyhedron(args[0]): + if nargs == 1 and isinstance(args[0], sage.geometry.abc.Polyhedron): copy = kwds.pop('copy', args[0].parent() is not self) mutable = kwds.pop('mutable', False) diff --git a/src/sage/schemes/toric/variety.py b/src/sage/schemes/toric/variety.py index aee10319916..6a6a8d3252a 100644 --- a/src/sage/schemes/toric/variety.py +++ b/src/sage/schemes/toric/variety.py @@ -2660,7 +2660,7 @@ def _orbit_closure_projection(self, cone, x): # TODO: make the following work nicely. # if x in cone.lattice(): # return quot(x) - # assert is_Cone(x) + # assert x is ConvexRationalPolyhedralCone object # return Cone(x.rays(), lattice=quot) def orbit_closure(self, cone):