From 2a1fcfd0e1f3127cc94e0ecf82522e522bb76b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 15 Dec 2025 14:15:44 +0100 Subject: [PATCH] some annotations -> bool --- src/sage/combinat/regular_sequence.py | 6 ++-- src/sage/combinat/regular_sequence_bounded.py | 12 +++---- src/sage/geometry/convex_set.py | 32 +++++++++---------- .../hyperbolic_space/hyperbolic_model.py | 10 +++--- src/sage/geometry/polyhedron/base0.py | 22 +++++++------ src/sage/geometry/polyhedron/face.py | 4 +-- .../polyhedron/ppl_lattice_polytope.py | 13 ++++---- .../numerical/interactive_simplex_method.py | 20 ++++++------ 8 files changed, 60 insertions(+), 59 deletions(-) diff --git a/src/sage/combinat/regular_sequence.py b/src/sage/combinat/regular_sequence.py index b77a69cbce7..c9fa63c6855 100644 --- a/src/sage/combinat/regular_sequence.py +++ b/src/sage/combinat/regular_sequence.py @@ -332,7 +332,7 @@ def __iter__(self): return iter(self[n] for n in count()) @cached_method - def is_degenerated(self): + def is_degenerated(self) -> bool: r""" Return whether this `k`-regular sequence is degenerated, i.e., whether this `k`-regular sequence does not satisfy @@ -363,7 +363,7 @@ def is_degenerated(self): False """ from sage.rings.integer_ring import ZZ - return (self.mu[ZZ(0)] * self.right) != self.right + return (self.mu[ZZ.zero()] * self.right) != self.right def _error_if_degenerated_(self): r""" @@ -1280,7 +1280,7 @@ def partial_sums(self, include_n=False): return result @cached_method - def is_bounded(self): + def is_bounded(self) -> bool: r""" Return whether this `k`-regular sequence is bounded. diff --git a/src/sage/combinat/regular_sequence_bounded.py b/src/sage/combinat/regular_sequence_bounded.py index ea63ed8a35e..6db8eaafdfe 100644 --- a/src/sage/combinat/regular_sequence_bounded.py +++ b/src/sage/combinat/regular_sequence_bounded.py @@ -160,7 +160,7 @@ def get_immutable(M): raise RuntimeError('Phi too large.') -def is_integer_valued(matrices): +def is_integer_valued(matrices) -> bool: r""" Return whether every matrix in ``matrices`` is integer-valued. @@ -203,7 +203,7 @@ def is_integer_valued(matrices): return all(mat in M for mat in matrices) -def is_non_negative(matrices): +def is_non_negative(matrices) -> bool: r""" Return whether every matrix in ``matrices`` is non-negative. @@ -234,10 +234,10 @@ def is_non_negative(matrices): sage: is_non_negative(matrices) True """ - return all(min(mat.list()) >= 0 for mat in matrices) + return all(v >= 0 for mat in matrices for v in mat.list()) -def is_bounded_via_mandel_simon_algorithm(matrices): +def is_bounded_via_mandel_simon_algorithm(matrices) -> bool: r""" Return whether the semigroup generated whether the semigroup of all possible products of ``matrices`` is finite/bounded. @@ -287,10 +287,10 @@ def is_bounded_via_mandel_simon_algorithm(matrices): sage: is_bounded_via_mandel_simon_algorithm(N) Traceback (most recent call last): ... - ValueError: Not all matrices are integer-valued. + ValueError: not all matrices are integer-valued """ if not is_integer_valued(matrices): - raise ValueError('Not all matrices are integer-valued.') + raise ValueError('not all matrices are integer-valued') phi = construct_phi(matrices) return not any(multiply_reduce(M, M) == M and not M**2 == M**3 diff --git a/src/sage/geometry/convex_set.py b/src/sage/geometry/convex_set.py index 2117eccfcc6..28aacbb4f55 100644 --- a/src/sage/geometry/convex_set.py +++ b/src/sage/geometry/convex_set.py @@ -41,7 +41,7 @@ class ConvexSet_base(SageObject, Set_base): Abstract base class for convex sets. """ - def is_empty(self): + def is_empty(self) -> bool: r""" Test whether ``self`` is the empty set. @@ -56,7 +56,7 @@ def is_empty(self): """ return self.dim() < 0 - def is_finite(self): + def is_finite(self) -> bool: r""" Test whether ``self`` is a finite set. @@ -106,7 +106,7 @@ def cardinality(self): return ZZ(1) return infinity - def is_universe(self): + def is_universe(self) -> bool: r""" Test whether ``self`` is the whole ambient space. @@ -445,7 +445,7 @@ def codimension(self): codim = codimension - def is_full_dimensional(self): + def is_full_dimensional(self) -> bool: r""" Return whether ``self`` is full dimensional. @@ -465,7 +465,7 @@ def is_full_dimensional(self): """ return self.dim() == self.ambient_dim() - def is_open(self): + def is_open(self) -> bool: r""" Return whether ``self`` is open. @@ -489,7 +489,7 @@ def is_open(self): return True raise NotImplementedError - def is_relatively_open(self): + def is_relatively_open(self) -> bool: r""" Return whether ``self`` is relatively open. @@ -514,7 +514,7 @@ def is_relatively_open(self): return True raise NotImplementedError - def is_closed(self): + def is_closed(self) -> bool: r""" Return whether ``self`` is closed. @@ -536,7 +536,7 @@ def is_closed(self): return True raise NotImplementedError - def is_compact(self): + def is_compact(self) -> bool: r""" Return whether ``self`` is compact. @@ -969,7 +969,7 @@ class ConvexSet_closed(ConvexSet_base): Abstract base class for closed convex sets. """ - def is_closed(self): + def is_closed(self) -> bool: r""" Return whether ``self`` is closed. @@ -983,7 +983,7 @@ def is_closed(self): """ return True - def is_open(self): + def is_open(self) -> bool: r""" Return whether ``self`` is open. @@ -1007,7 +1007,7 @@ class ConvexSet_compact(ConvexSet_closed): Abstract base class for compact convex sets. """ - def is_universe(self): + def is_universe(self) -> bool: r""" Return whether ``self`` is the whole ambient space. @@ -1025,7 +1025,7 @@ def is_universe(self): """ return self.ambient_dim() == 0 and not self.is_empty() - def is_compact(self): + def is_compact(self) -> bool: r""" Return whether ``self`` is compact. @@ -1047,7 +1047,7 @@ class ConvexSet_relatively_open(ConvexSet_base): Abstract base class for relatively open convex sets. """ - def is_relatively_open(self): + def is_relatively_open(self) -> bool: r""" Return whether ``self`` is relatively open. @@ -1062,7 +1062,7 @@ def is_relatively_open(self): """ return True - def is_open(self): + def is_open(self) -> bool: r""" Return whether ``self`` is open. @@ -1083,7 +1083,7 @@ class ConvexSet_open(ConvexSet_relatively_open): Abstract base class for open convex sets. """ - def is_open(self): + def is_open(self) -> bool: r""" Return whether ``self`` is open. @@ -1098,7 +1098,7 @@ def is_open(self): """ return True - def is_closed(self): + def is_closed(self) -> bool: r""" Return whether ``self`` is closed. diff --git a/src/sage/geometry/hyperbolic_space/hyperbolic_model.py b/src/sage/geometry/hyperbolic_space/hyperbolic_model.py index 4d507877d38..4bf8eeeb1a2 100644 --- a/src/sage/geometry/hyperbolic_space/hyperbolic_model.py +++ b/src/sage/geometry/hyperbolic_space/hyperbolic_model.py @@ -169,7 +169,7 @@ def _element_constructor_(self, x, is_boundary=None, **graphics_options): # Abs """ return self.get_point(x, is_boundary, **graphics_options) - def name(self): # Abstract + def name(self) -> str: # Abstract """ Return the name of this model. @@ -181,7 +181,7 @@ def name(self): # Abstract """ return self._name - def short_name(self): + def short_name(self) -> str: """ Return the short name of this model. @@ -193,7 +193,7 @@ def short_name(self): """ return self._short_name - def is_bounded(self): + def is_bounded(self) -> bool: """ Return ``True`` if ``self`` is a bounded model. @@ -210,7 +210,7 @@ def is_bounded(self): """ return self._bounded - def is_conformal(self): + def is_conformal(self) -> bool: """ Return ``True`` if ``self`` is a conformal model. @@ -222,7 +222,7 @@ def is_conformal(self): """ return self._conformal - def is_isometry_group_projective(self): + def is_isometry_group_projective(self) -> bool: """ Return ``True`` if the isometry group of ``self`` is projective. diff --git a/src/sage/geometry/polyhedron/base0.py b/src/sage/geometry/polyhedron/base0.py index c710c5dfa62..0d75e9cab82 100644 --- a/src/sage/geometry/polyhedron/base0.py +++ b/src/sage/geometry/polyhedron/base0.py @@ -446,7 +446,7 @@ def change_ring(self, base_ring, backend=None): new_parent = self.parent().change_ring(base_ring, backend) return new_parent([vertices, rays, lines], None) - def is_mutable(self): + def is_mutable(self) -> bool: r""" Return ``True`` if the polyhedron is mutable, i.e. it can be modified in place. @@ -458,7 +458,7 @@ def is_mutable(self): """ return False - def is_immutable(self): + def is_immutable(self) -> bool: r""" Return ``True`` if the polyhedron is immutable, i.e. it cannot be modified in place. @@ -542,10 +542,11 @@ def n_vertices(self): return len(self.vertices()) @cached_method - def n_rays(self): + def n_rays(self) -> int: """ - Return the number of rays. The representation will - always be minimal. + Return the number of rays. + + The representation will always be minimal. EXAMPLES:: @@ -556,10 +557,11 @@ def n_rays(self): return len(self.rays()) @cached_method - def n_lines(self): + def n_lines(self) -> int: """ - Return the number of lines. The representation will - always be minimal. + Return the number of lines. + + The representation will always be minimal. EXAMPLES:: @@ -569,7 +571,7 @@ def n_lines(self): """ return len(self.lines()) - def is_compact(self): + def is_compact(self) -> bool: """ Test for boundedness of the polytope. @@ -582,7 +584,7 @@ def is_compact(self): sage: p.is_compact() False """ - return self.n_rays() == 0 and self.n_lines() == 0 + return self.n_rays() == 0 == self.n_lines() def Hrepresentation(self, index=None): """ diff --git a/src/sage/geometry/polyhedron/face.py b/src/sage/geometry/polyhedron/face.py index e03200cd2dd..e421e735226 100644 --- a/src/sage/geometry/polyhedron/face.py +++ b/src/sage/geometry/polyhedron/face.py @@ -682,7 +682,7 @@ def ambient_vector_space(self, base_field=None): """ return self.polyhedron().ambient_vector_space(base_field=base_field) - def is_relatively_open(self): + def is_relatively_open(self) -> bool: r""" Return whether ``self`` is relatively open. @@ -699,7 +699,7 @@ def is_relatively_open(self): """ return self.as_polyhedron().is_relatively_open() - def is_compact(self): + def is_compact(self) -> bool: r""" Return whether ``self`` is compact. diff --git a/src/sage/geometry/polyhedron/ppl_lattice_polytope.py b/src/sage/geometry/polyhedron/ppl_lattice_polytope.py index b30bdc3e077..61bb057fbd2 100644 --- a/src/sage/geometry/polyhedron/ppl_lattice_polytope.py +++ b/src/sage/geometry/polyhedron/ppl_lattice_polytope.py @@ -216,7 +216,7 @@ def __repr__(self): desc += 'A ' + repr(self.affine_dimension()) + '-dimensional lattice polytope' desc += ' in ZZ^' + repr(self.space_dimension()) - if self.n_vertices() > 0: + if self.n_vertices(): desc += ' with ' desc += repr(self.n_vertices()) if self.n_vertices() == 1: @@ -225,7 +225,7 @@ def __repr__(self): desc += ' vertices' return desc - def is_bounded(self): + def is_bounded(self) -> bool: """ Return whether the lattice polytope is compact. @@ -255,7 +255,7 @@ def n_vertices(self): return len(self.minimized_generators()) @cached_method - def is_simplex(self): + def is_simplex(self) -> bool: r""" Return whether the polyhedron is a simplex. @@ -270,7 +270,7 @@ def is_simplex(self): sage: LatticePolytope_PPL((0,0,0), (1,0,0), (0,1,0)).is_simplex() True """ - return self.affine_dimension()+1 == self.n_vertices() + return self.affine_dimension() + 1 == self.n_vertices() @cached_method def bounding_box(self): @@ -525,7 +525,7 @@ def vertices_saturating(self, constraint): return tuple(result) @cached_method - def is_full_dimensional(self): + def is_full_dimensional(self) -> bool: """ Return whether the lattice polytope is full dimensional. @@ -542,7 +542,6 @@ def is_full_dimensional(self): sage: q.is_full_dimensional() True """ - return self.affine_dimension() == self.space_dimension() def fibration_generator(self, dim): @@ -576,7 +575,7 @@ def fibration_generator(self, dim): # "points" are the potential vertices of the fiber. They are # in the $codim$-skeleton of the polytope, which is contained # in the points that saturate at least $dim$ equations. - points = [ p for p in self._integral_points_saturating() if len(p[1]) >= dim ] + points = [p for p in self._integral_points_saturating() if len(p[1]) >= dim] points = sorted(points, key=lambda x:len(x[1])) # iterate over point combinations subject to all points being on one facet. diff --git a/src/sage/numerical/interactive_simplex_method.py b/src/sage/numerical/interactive_simplex_method.py index e1e0eb63fed..7b7cd7c26c4 100644 --- a/src/sage/numerical/interactive_simplex_method.py +++ b/src/sage/numerical/interactive_simplex_method.py @@ -1184,11 +1184,11 @@ def feasible_set(self): R = QQ else: R = RDF - ieqs = [[R(_) for _ in ieq] for ieq in ieqs] - eqns = [[R(_) for _ in eqn] for eqn in eqns] + ieqs = [[R(v) for v in ieq] for ieq in ieqs] + eqns = [[R(v) for v in eqn] for eqn in eqns] return Polyhedron(ieqs=ieqs, eqns=eqns, base_ring=R) - def is_bounded(self): + def is_bounded(self) -> bool: r""" Check if ``self`` is bounded. @@ -1214,7 +1214,7 @@ def is_bounded(self): """ return self.optimal_solution() is not None or not self.is_feasible() - def is_feasible(self, *x): + def is_feasible(self, *x) -> bool: r""" Check if ``self`` or given solution is feasible. @@ -1251,7 +1251,7 @@ def is_feasible(self, *x): return self.feasible_set().contains(self._solution(x)) return self.optimal_value() is not None - def is_negative(self): + def is_negative(self) -> bool: r""" Return ``True`` when the problem is of type ``'-max'`` or ``'-min'``. @@ -1269,7 +1269,7 @@ def is_negative(self): """ return self._is_negative - def is_primal(self): + def is_primal(self) -> bool: r""" Check if we consider this problem to be primal or dual. @@ -1290,7 +1290,7 @@ def is_primal(self): """ return self._is_primal - def is_optimal(self, *x): + def is_optimal(self, *x) -> bool: r""" Check if given solution is feasible. @@ -3058,7 +3058,7 @@ def entering_coefficients(self): "its coefficients") return self.column_coefficients(self._entering) - def is_dual_feasible(self): + def is_dual_feasible(self) -> bool: r""" Check if ``self`` is dual feasible. @@ -3082,7 +3082,7 @@ def is_dual_feasible(self): """ return all(ci <= 0 for ci in self.objective_coefficients()) - def is_feasible(self): + def is_feasible(self) -> bool: r""" Check if ``self`` is feasible. @@ -3106,7 +3106,7 @@ def is_feasible(self): """ return all(bi >= 0 for bi in self.constant_terms()) - def is_optimal(self): + def is_optimal(self) -> bool: r""" Check if ``self`` is optimal.