From 7ab8ccff185f779571cd6d4b78f0f9e7e365b0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 14 Nov 2025 20:01:56 +0100 Subject: [PATCH] typing "__contains__" in categories,geometry,groups,monoids --- src/sage/categories/algebras.py | 2 +- src/sage/categories/category.py | 2 +- src/sage/categories/category_types.py | 4 ++-- src/sage/categories/commutative_algebras.py | 2 +- .../categories/examples/finite_coxeter_groups.py | 4 ++-- .../categories/examples/finite_enumerated_sets.py | 6 +++--- .../examples/infinite_enumerated_sets.py | 4 ++-- src/sage/categories/examples/sets_cat.py | 14 +++++++------- src/sage/categories/facade_sets.py | 2 +- src/sage/categories/fields.py | 2 +- src/sage/categories/finite_fields.py | 2 +- src/sage/categories/homset.py | 6 +++--- src/sage/categories/integral_domains.py | 2 +- src/sage/categories/number_fields.py | 2 +- src/sage/categories/objects.py | 2 +- src/sage/categories/sets_cat.py | 4 ++-- .../categories/unique_factorization_domains.py | 2 +- src/sage/geometry/cone.py | 6 +++--- src/sage/geometry/fan.py | 2 +- .../hyperplane_arrangement/affine_subspace.py | 2 +- .../geometry/hyperplane_arrangement/hyperplane.py | 2 +- src/sage/geometry/relative_interior.py | 4 ++-- src/sage/geometry/toric_lattice.py | 2 +- src/sage/groups/abelian_gps/abelian_group.py | 2 +- src/sage/groups/abelian_gps/dual_abelian_group.py | 2 +- src/sage/groups/conjugacy_classes.py | 4 ++-- src/sage/groups/libgap_mixin.py | 2 +- src/sage/groups/perm_gps/permgroup_named.py | 10 +++++----- src/sage/monoids/free_abelian_monoid.py | 2 +- src/sage/monoids/free_monoid.py | 2 +- src/sage/monoids/string_monoid.py | 4 ++-- 31 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/sage/categories/algebras.py b/src/sage/categories/algebras.py index db42b0ea6d1..9fe03c5c309 100644 --- a/src/sage/categories/algebras.py +++ b/src/sage/categories/algebras.py @@ -59,7 +59,7 @@ class Algebras(CategoryWithAxiom_over_base_ring): _base_category_class_and_axiom = (AssociativeAlgebras, 'Unital') # For backward compatibility? - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Membership testing. diff --git a/src/sage/categories/category.py b/src/sage/categories/category.py index 360127f0a78..7643bb08abe 100644 --- a/src/sage/categories/category.py +++ b/src/sage/categories/category.py @@ -684,7 +684,7 @@ def _subcategory_hook_(self, category): """ return issubclass(category.parent_class, self.parent_class) - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Membership testing. diff --git a/src/sage/categories/category_types.py b/src/sage/categories/category_types.py index c29a4e385c0..2b976b54083 100644 --- a/src/sage/categories/category_types.py +++ b/src/sage/categories/category_types.py @@ -491,7 +491,7 @@ def _subcategory_hook_(self, C): return C.base() in base_ring return False - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Return whether ``x`` is an object of this category. @@ -605,7 +605,7 @@ def ring(self): """ return self.ambient() - def __contains__(self, x): + def __contains__(self, x) -> bool: """ EXAMPLES:: diff --git a/src/sage/categories/commutative_algebras.py b/src/sage/categories/commutative_algebras.py index aa3107fc509..506004a2dbb 100644 --- a/src/sage/categories/commutative_algebras.py +++ b/src/sage/categories/commutative_algebras.py @@ -46,7 +46,7 @@ class CommutativeAlgebras(CategoryWithAxiom_over_base_ring): - coproduct ( = tensor product over base ring) """ - def __contains__(self, A): + def __contains__(self, A) -> bool: """ EXAMPLES:: diff --git a/src/sage/categories/examples/finite_coxeter_groups.py b/src/sage/categories/examples/finite_coxeter_groups.py index 9764e5b3587..032f93cbb25 100644 --- a/src/sage/categories/examples/finite_coxeter_groups.py +++ b/src/sage/categories/examples/finite_coxeter_groups.py @@ -103,7 +103,7 @@ def __init__(self, n=5): Parent.__init__(self, category=FiniteCoxeterGroups()) self.n = n - def _repr_(self): + def _repr_(self) -> str: r""" EXAMPLES:: @@ -114,7 +114,7 @@ def _repr_(self): """ return "The %s-th dihedral group of order %s" % (self.n, 2 * self.n) - def __contains__(self, x): + def __contains__(self, x) -> bool: r""" Check if the element ``x`` is in the mathematical parent ``self``. diff --git a/src/sage/categories/examples/finite_enumerated_sets.py b/src/sage/categories/examples/finite_enumerated_sets.py index 04b7d2f0dad..e14386904e4 100644 --- a/src/sage/categories/examples/finite_enumerated_sets.py +++ b/src/sage/categories/examples/finite_enumerated_sets.py @@ -81,7 +81,7 @@ def __init__(self): Parent.__init__(self, facade=IntegerRing(), category=FiniteEnumeratedSets()) - def _repr_(self): + def _repr_(self) -> str: """ TESTS:: @@ -90,7 +90,7 @@ def _repr_(self): """ return "An example of a finite enumerated set: {1,2,3}" - def __contains__(self, o): + def __contains__(self, o) -> bool: """ EXAMPLES:: @@ -182,7 +182,7 @@ def retract(self, x): """ return x ** 2 - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Membership testing by checking whether the preimage by the bijection is in the ambient space. diff --git a/src/sage/categories/examples/infinite_enumerated_sets.py b/src/sage/categories/examples/infinite_enumerated_sets.py index 49935ff6d02..4d1dc54dc31 100644 --- a/src/sage/categories/examples/infinite_enumerated_sets.py +++ b/src/sage/categories/examples/infinite_enumerated_sets.py @@ -91,7 +91,7 @@ def __init__(self): """ Parent.__init__(self, category=InfiniteEnumeratedSets()) - def _repr_(self): + def _repr_(self) -> str: """ TESTS:: @@ -100,7 +100,7 @@ def _repr_(self): """ return "An example of an infinite enumerated set: the nonnegative integers" - def __contains__(self, elt): + def __contains__(self, elt) -> bool: """ EXAMPLES:: diff --git a/src/sage/categories/examples/sets_cat.py b/src/sage/categories/examples/sets_cat.py index c28f483df03..57a7656dd8c 100644 --- a/src/sage/categories/examples/sets_cat.py +++ b/src/sage/categories/examples/sets_cat.py @@ -115,9 +115,9 @@ def an_element(self): sage: x.parent() Integer Ring """ - return self(47) # if speed is needed, call: self.element_class(47) + return self(47) # if speed is needed, call: self.element_class(47) - def __contains__(self, p): + def __contains__(self, p) -> bool: """ TESTS:: @@ -393,7 +393,7 @@ def __init__(self): super().__init__() self._populate_coercion_lists_(embedding=IntegerRing()) - def __contains__(self, p): + def __contains__(self, p) -> bool: """ TESTS:: @@ -502,7 +502,7 @@ def __init__(self): self.mor = Hom(self, IntegerRing())(lambda z: z.value) self._populate_coercion_lists_(embedding=self.mor) - def _repr_(self): + def _repr_(self) -> str: """ TESTS:: @@ -511,7 +511,7 @@ def _repr_(self): """ return "Set of prime numbers (wrapper implementation)" - def __contains__(self, p): + def __contains__(self, p) -> bool: """ TESTS:: @@ -665,7 +665,7 @@ def __init__(self): """ Parent.__init__(self, facade=IntegerRing(), category=Sets()) - def _repr_(self): + def _repr_(self) -> str: """ TESTS:: @@ -674,7 +674,7 @@ def _repr_(self): """ return "Set of prime numbers (facade implementation)" - def __contains__(self, p): + def __contains__(self, p) -> bool: """ TESTS:: diff --git a/src/sage/categories/facade_sets.py b/src/sage/categories/facade_sets.py index 0bdd7c6df2b..e9ce33c9bf2 100644 --- a/src/sage/categories/facade_sets.py +++ b/src/sage/categories/facade_sets.py @@ -180,7 +180,7 @@ def is_parent_of(self, element): from sage.structure.element import parent return parent(element) in parents - def __contains__(self, element): + def __contains__(self, element) -> bool: """ Membership testing. diff --git a/src/sage/categories/fields.py b/src/sage/categories/fields.py index 0c07b4d85e2..62288165df0 100644 --- a/src/sage/categories/fields.py +++ b/src/sage/categories/fields.py @@ -61,7 +61,7 @@ def extra_super_categories(self): """ return [EuclideanDomains(), NoetherianRings()] - def __contains__(self, x): + def __contains__(self, x) -> bool: """ EXAMPLES:: diff --git a/src/sage/categories/finite_fields.py b/src/sage/categories/finite_fields.py index 7c418ec596d..55a69ab48b6 100644 --- a/src/sage/categories/finite_fields.py +++ b/src/sage/categories/finite_fields.py @@ -66,7 +66,7 @@ def extra_super_categories(self): """ return [EnumeratedSets().Finite()] - def __contains__(self, x): + def __contains__(self, x) -> bool: """ EXAMPLES:: diff --git a/src/sage/categories/homset.py b/src/sage/categories/homset.py index 94a65904c90..1e627d87516 100644 --- a/src/sage/categories/homset.py +++ b/src/sage/categories/homset.py @@ -1074,7 +1074,7 @@ def element_class_set_morphism(self): """ return self.__make_element_class__(morphism.SetMorphism) - def __eq__(self, other): + def __eq__(self, other) -> bool: """ For two homsets, it is tested whether the domain, the codomain and the category coincide. @@ -1094,7 +1094,7 @@ def __eq__(self, other): and self._codomain == other._codomain and self.__category == other.__category) - def __ne__(self, other): + def __ne__(self, other) -> bool: """ Check for not-equality of ``self`` and ``other``. @@ -1113,7 +1113,7 @@ def __ne__(self, other): """ return not (self == other) - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Test whether the parent of the argument is ``self``. diff --git a/src/sage/categories/integral_domains.py b/src/sage/categories/integral_domains.py index d426366243e..65653640002 100644 --- a/src/sage/categories/integral_domains.py +++ b/src/sage/categories/integral_domains.py @@ -62,7 +62,7 @@ class IntegralDomains(CategoryWithAxiom): """ _base_category_class_and_axiom = (Domains, "Commutative") - def __contains__(self, x): + def __contains__(self, x) -> bool: """ EXAMPLES:: diff --git a/src/sage/categories/number_fields.py b/src/sage/categories/number_fields.py index c6edc341bb1..73dfb39c105 100644 --- a/src/sage/categories/number_fields.py +++ b/src/sage/categories/number_fields.py @@ -68,7 +68,7 @@ def super_categories(self): """ return [Fields().Infinite()] - def __contains__(self, x): + def __contains__(self, x) -> bool: r""" Return ``True`` if ``x`` is a number field. diff --git a/src/sage/categories/objects.py b/src/sage/categories/objects.py index 169adf5af77..4dd1c61e2c7 100644 --- a/src/sage/categories/objects.py +++ b/src/sage/categories/objects.py @@ -62,7 +62,7 @@ def super_categories(self): """ return [] - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Anything is in the category of objects. diff --git a/src/sage/categories/sets_cat.py b/src/sage/categories/sets_cat.py index a44e7ae97d5..4d8dee22b9f 100644 --- a/src/sage/categories/sets_cat.py +++ b/src/sage/categories/sets_cat.py @@ -1037,7 +1037,7 @@ def is_parent_of(self, element): return parent(element) == self @abstract_method - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Test whether the set ``self`` contains the object ``x``. @@ -3116,7 +3116,7 @@ def _an_element_(self): return self.a_realization().an_element() # TODO: maybe this could be taken care of by Sets.Facade()? - def __contains__(self, x): + def __contains__(self, x) -> bool: r""" Test whether ``x`` is in ``self``, that is if it is an element of some realization of ``self``. diff --git a/src/sage/categories/unique_factorization_domains.py b/src/sage/categories/unique_factorization_domains.py index f01763d4a7e..a9704872d84 100644 --- a/src/sage/categories/unique_factorization_domains.py +++ b/src/sage/categories/unique_factorization_domains.py @@ -60,7 +60,7 @@ def additional_structure(self): """ return None - def __contains__(self, x): + def __contains__(self, x) -> bool: """ EXAMPLES:: diff --git a/src/sage/geometry/cone.py b/src/sage/geometry/cone.py index 933f3341613..2a6cdfc2e5b 100644 --- a/src/sage/geometry/cone.py +++ b/src/sage/geometry/cone.py @@ -1560,7 +1560,7 @@ def _PPL_cone(self): self._PPL_C_Polyhedron = C_Polyhedron(gs) return self._PPL_C_Polyhedron - def __contains__(self, point): + def __contains__(self, point) -> bool: r""" Check if ``point`` is contained in ``self``. @@ -1599,7 +1599,7 @@ def __getstate__(self): False """ state = copy(self.__dict__) - state.pop("_PPL_C_Polyhedron", None) # PPL is not picklable. + state.pop("_PPL_C_Polyhedron", None) # PPL is not picklable. # TODO: do we want to keep the face lattice in the pickle? # Currently there is an unpickling loop if do: @@ -1611,7 +1611,7 @@ def __getstate__(self): state.pop("_face_lattice", None) return state - def _contains(self, point, region='whole cone'): + def _contains(self, point, region='whole cone') -> bool: r""" Check if ``point`` is contained in ``self``. diff --git a/src/sage/geometry/fan.py b/src/sage/geometry/fan.py index b4f00a3bab4..6ade0e7c3d9 100644 --- a/src/sage/geometry/fan.py +++ b/src/sage/geometry/fan.py @@ -1327,7 +1327,7 @@ def __richcmp__(self, right, op): else: return NotImplemented - def __contains__(self, cone): + def __contains__(self, cone) -> bool: r""" Check if ``cone`` is equivalent to a cone of the fan. diff --git a/src/sage/geometry/hyperplane_arrangement/affine_subspace.py b/src/sage/geometry/hyperplane_arrangement/affine_subspace.py index 94d004f987f..034bba9cf36 100644 --- a/src/sage/geometry/hyperplane_arrangement/affine_subspace.py +++ b/src/sage/geometry/hyperplane_arrangement/affine_subspace.py @@ -254,7 +254,7 @@ def __lt__(self, other): return False return self <= other - def __contains__(self, q): + def __contains__(self, q) -> bool: r""" Test whether the point ``q`` is in the affine space. diff --git a/src/sage/geometry/hyperplane_arrangement/hyperplane.py b/src/sage/geometry/hyperplane_arrangement/hyperplane.py index 38e0761330b..f751811db12 100644 --- a/src/sage/geometry/hyperplane_arrangement/hyperplane.py +++ b/src/sage/geometry/hyperplane_arrangement/hyperplane.py @@ -249,7 +249,7 @@ def _normal_pivot(self): max_value = values[i] return max_pos - def __contains__(self, q): + def __contains__(self, q) -> bool: r""" Test whether the point ``q`` is in the hyperplane. diff --git a/src/sage/geometry/relative_interior.py b/src/sage/geometry/relative_interior.py index 3d7aa5d1c36..8dc9f95018c 100644 --- a/src/sage/geometry/relative_interior.py +++ b/src/sage/geometry/relative_interior.py @@ -56,7 +56,7 @@ def __init__(self, polyhedron): if hasattr(polyhedron, "_add_dependent_object"): polyhedron._add_dependent_object(self) - def __hash__(self): + def __hash__(self) -> int: r""" TESTS:: @@ -67,7 +67,7 @@ def __hash__(self): """ return hash(self._polyhedron) ^ 1789 - def __contains__(self, point): + def __contains__(self, point) -> bool: r""" Return whether ``self`` contains ``point``. diff --git a/src/sage/geometry/toric_lattice.py b/src/sage/geometry/toric_lattice.py index 53346206c05..b24384b3c68 100644 --- a/src/sage/geometry/toric_lattice.py +++ b/src/sage/geometry/toric_lattice.py @@ -483,7 +483,7 @@ def _coerce_map_from_(self, other): return None return super()._convert_map_from_(other) - def __contains__(self, point): + def __contains__(self, point) -> bool: r""" Check if ``point`` is an element of ``self``. diff --git a/src/sage/groups/abelian_gps/abelian_group.py b/src/sage/groups/abelian_gps/abelian_group.py index 22109fb13fa..80a117f041d 100644 --- a/src/sage/groups/abelian_gps/abelian_group.py +++ b/src/sage/groups/abelian_gps/abelian_group.py @@ -1741,7 +1741,7 @@ def __init__(self, ambient, gens, names='f', category=None): category = Groups().Commutative().Subobjects() AbelianGroup_class.__init__(self, invs, names, category=category) - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Test whether ``x`` is an element of this subgroup. diff --git a/src/sage/groups/abelian_gps/dual_abelian_group.py b/src/sage/groups/abelian_gps/dual_abelian_group.py index 1c353a90136..9a06c276048 100644 --- a/src/sage/groups/abelian_gps/dual_abelian_group.py +++ b/src/sage/groups/abelian_gps/dual_abelian_group.py @@ -332,7 +332,7 @@ def invariants(self): # TODO: deprecate return self.group().gens_orders() - def __contains__(self, X): + def __contains__(self, X) -> bool: """ Implement "in". diff --git a/src/sage/groups/conjugacy_classes.py b/src/sage/groups/conjugacy_classes.py index e51995e51d8..a367e61ac7d 100644 --- a/src/sage/groups/conjugacy_classes.py +++ b/src/sage/groups/conjugacy_classes.py @@ -159,7 +159,7 @@ def __ne__(self, other): """ return not (self == other) - def __contains__(self, element): + def __contains__(self, element) -> bool: r""" Check if ``element`` belongs to the conjugacy class ``self``. @@ -440,7 +440,7 @@ def cardinality(self): """ return self._gap_().Size().sage() - def __contains__(self, g): + def __contains__(self, g) -> bool: r""" Containment test. diff --git a/src/sage/groups/libgap_mixin.py b/src/sage/groups/libgap_mixin.py index a6054fb0371..c1bf5ef7742 100644 --- a/src/sage/groups/libgap_mixin.py +++ b/src/sage/groups/libgap_mixin.py @@ -22,7 +22,7 @@ class GroupMixinLibGAP: - def __contains__(self, elt): + def __contains__(self, elt) -> bool: r""" TESTS:: diff --git a/src/sage/groups/perm_gps/permgroup_named.py b/src/sage/groups/perm_gps/permgroup_named.py index d0c139469e6..2975421e51d 100644 --- a/src/sage/groups/perm_gps/permgroup_named.py +++ b/src/sage/groups/perm_gps/permgroup_named.py @@ -2035,7 +2035,7 @@ def __init__(self): # We override the __call__ as the elements are not instances of Element __call__ = DisjointUnionEnumeratedSets._element_constructor_facade - def _repr_(self): + def _repr_(self) -> str: """ TESTS:: @@ -2044,7 +2044,7 @@ def _repr_(self): """ return "Transitive Groups" - def __contains__(self, G): + def __contains__(self, G) -> bool: r""" EXAMPLES:: @@ -2111,7 +2111,7 @@ def _repr_(self): """ return "Transitive Groups of degree %s" % (self._degree,) - def __contains__(self, G): + def __contains__(self, G) -> bool: r""" EXAMPLES:: @@ -2445,7 +2445,7 @@ def _repr_(self): """ return "Primitive Groups" - def __contains__(self, G): + def __contains__(self, G) -> bool: r""" Test whether `G` is in ``self``. @@ -2518,7 +2518,7 @@ def _repr_(self): """ return "Primitive Groups of degree %s" % (self._degree) - def __contains__(self, G): + def __contains__(self, G) -> bool: r""" Test whether `G` is in ``self``. diff --git a/src/sage/monoids/free_abelian_monoid.py b/src/sage/monoids/free_abelian_monoid.py index 26144cbe6c6..77da79e29cb 100644 --- a/src/sage/monoids/free_abelian_monoid.py +++ b/src/sage/monoids/free_abelian_monoid.py @@ -224,7 +224,7 @@ def __call__(self, x): return x return self.element_class(self, x) - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Return ``True`` if `x` is an element of this abelian monoid. diff --git a/src/sage/monoids/free_monoid.py b/src/sage/monoids/free_monoid.py index 4d6afef8e9f..e5efbf477e7 100644 --- a/src/sage/monoids/free_monoid.py +++ b/src/sage/monoids/free_monoid.py @@ -271,7 +271,7 @@ def _element_constructor_(self, x, check=True): raise TypeError("argument x (= %s) is of the wrong type" % x) - def __contains__(self, x): + def __contains__(self, x) -> bool: return isinstance(x, FreeMonoidElement) and x.parent() == self def gen(self, i=0): diff --git a/src/sage/monoids/string_monoid.py b/src/sage/monoids/string_monoid.py index 61814c421c5..e60bbbf0b02 100644 --- a/src/sage/monoids/string_monoid.py +++ b/src/sage/monoids/string_monoid.py @@ -54,10 +54,10 @@ def __init__(self, n, alphabet=()): FreeMonoid.__init__(self, n) self._alphabet = alphabet - def __contains__(self, x): + def __contains__(self, x) -> bool: return isinstance(x, StringMonoidElement) and x.parent() == self - def alphabet(self): + def alphabet(self) -> tuple: return tuple(self._alphabet) def one(self):