diff --git a/src/sage/rings/complex_arb.pyx b/src/sage/rings/complex_arb.pyx index 0cab5ba87e9..cdd0a688aa5 100644 --- a/src/sage/rings/complex_arb.pyx +++ b/src/sage/rings/complex_arb.pyx @@ -360,7 +360,7 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): """ return super().__classcall__(cls, precision) - def __init__(self, long precision=53): + def __init__(self, long precision=53) -> None: r""" Initialize the complex ball field. @@ -1399,7 +1399,7 @@ cdef class ComplexBall(RingElement): """ acb_clear(self.value) - def __init__(self, parent, x=None, y=None): + def __init__(self, parent, x=None, y=None) -> None: """ Initialize the :class:`ComplexBall`. @@ -1529,7 +1529,7 @@ cdef class ComplexBall(RingElement): else: raise TypeError("unsupported initializer") - def __hash__(self): + def __hash__(self) -> int: """ TESTS:: @@ -2333,7 +2333,7 @@ cdef class ComplexBall(RingElement): return (arb_is_nonzero(acb_realref(self.value)) or arb_is_nonzero(acb_imagref(self.value))) - def __bool__(self): + def __bool__(self) -> bool: """ Return ``True`` iff this complex ball is not the zero ball, i.e. if the midpoint and radius of its real and imaginary parts are not all zero. @@ -2590,7 +2590,7 @@ cdef class ComplexBall(RingElement): if _do_sig(prec(self)): sig_off() return res - def __contains__(self, other): + def __contains__(self, other) -> bool: """ Return ``True`` if ``other`` can be verified to be contained in ``self``. diff --git a/src/sage/rings/complex_interval.pyx b/src/sage/rings/complex_interval.pyx index b0b9f14263b..6ef90638d3b 100644 --- a/src/sage/rings/complex_interval.pyx +++ b/src/sage/rings/complex_interval.pyx @@ -125,7 +125,7 @@ cdef class ComplexIntervalFieldElement(FieldElement): mpfi_init2(self.__re, self._prec) mpfi_init2(self.__im, self._prec) - def __init__(self, parent, real, imag=None, int base=10): + def __init__(self, parent, real, imag=None, int base=10) -> None: """ Initialize a complex number (interval). @@ -168,7 +168,7 @@ cdef class ComplexIntervalFieldElement(FieldElement): """ return self.str(10) - def __hash__(self): + def __hash__(self) -> int: """ Return the hash value of ``self``. @@ -664,7 +664,7 @@ cdef class ComplexIntervalFieldElement(FieldElement): return center - def __contains__(self, other): + def __contains__(self, other) -> bool: """ Test whether ``other`` is totally contained in ``self``. @@ -1406,7 +1406,7 @@ cdef class ComplexIntervalFieldElement(FieldElement): return complex(self.real().n(self._prec), self.imag().n(self._prec)) - def __bool__(self): + def __bool__(self) -> bool: """ Return ``True`` if ``self`` is not known to be exactly zero. diff --git a/src/sage/rings/ideal.py b/src/sage/rings/ideal.py index 589962e599d..eacdda6dd2f 100644 --- a/src/sage/rings/ideal.py +++ b/src/sage/rings/ideal.py @@ -31,7 +31,7 @@ from sage.categories.rings import Rings from sage.categories.fields import Fields from sage.structure.element import MonoidElement -from sage.structure.richcmp import rich_to_bool, richcmp, op_NE +from sage.structure.richcmp import rich_to_bool, op_NE from sage.structure.sequence import Sequence @@ -253,7 +253,7 @@ class Ideal_generic(MonoidElement): See :func:`Ideal()`. """ - def __init__(self, ring, gens, coerce=True, **kwds): + def __init__(self, ring, gens, coerce=True, **kwds) -> None: """ Initialize this ideal. @@ -318,7 +318,7 @@ def _repr_short(self): s = repr(x) if '\n' in s: has_return = True - s = s.replace('\n','\n ') + s = s.replace('\n', '\n ') L.append(s) if has_return: return '\n(\n %s\n)\n' % (',\n\n '.join(L)) @@ -395,7 +395,7 @@ def _richcmp_(self, other, op): return rich_to_bool(op, +1) raise NotImplementedError(f'ideal comparison in {self.ring()} is not implemented') - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Check if ``x`` is in ``self``. @@ -439,7 +439,7 @@ def _contains_(self, x): """ raise NotImplementedError - def __bool__(self): + def __bool__(self) -> bool: r""" Return ``True`` if this ideal is not `(0)`. @@ -1081,7 +1081,7 @@ def __mul__(self, other): try: if self.ring().has_coerce_map_from(other): return self - except (TypeError,ArithmeticError,ValueError): + except (TypeError, ArithmeticError, ValueError): pass other = self.ring().ideal(other) return self._mul_(other) @@ -1107,7 +1107,8 @@ def _mul_(self, other): sage: I._mul_(J) Ideal (x^3*y, x^2*y^2, x^3*z, x^2*y*z, x^4, x^3*y) of Multivariate Polynomial Ring in x, y, z over Rational Field """ - return self.ring().ideal([z for z in [x*y for x in self.gens() for y in other.gens()] if z]) + return self.ring().ideal([z for x in self.gens() for y in other.gens() + if (z := x * y)]) def __rmul__(self, other): """ @@ -1124,10 +1125,11 @@ def __rmul__(self, other): try: if self.ring().has_coerce_map_from(other): return self - except (TypeError,ArithmeticError,ValueError): + except (TypeError, ArithmeticError, ValueError): pass other = self.ring().ideal(other) - return self.ring().ideal([z for z in [y*x for x in self.gens() for y in other.gens()] if z]) + return self.ring().ideal([z for x in self.gens() for y in other.gens() + if (z := y * x)]) def norm(self): """ @@ -1284,7 +1286,7 @@ class Ideal_principal(Ideal_generic): See :func:`Ideal()`. """ # now Ideal_principal takes a list. - #def __init__(self, ring, gen): + # def __init__(self, ring, gen): # Ideal_generic.__init__(self, ring, [gen]) def _repr_(self): @@ -1366,7 +1368,7 @@ def gen(self, i=0): raise ValueError(f"i (={i}) must be 0") return self.gens()[0] - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Return ``True`` if ``x`` is in ``self``. @@ -1388,7 +1390,7 @@ def __contains__(self, x): except NotImplementedError: return self._contains_(self.ring()(x)) - def __hash__(self): + def __hash__(self) -> int: r""" Very stupid constant hash function! @@ -1622,10 +1624,10 @@ def is_prime(self): sage: RR.ideal(7).is_prime() False """ - if self.is_zero(): # PIDs are integral domains by definition + if self.is_zero(): # PIDs are integral domains by definition return True g = self.gen() - if g.is_one(): # The ideal (1) is never prime + if g.is_one(): # The ideal (1) is never prime return False if hasattr(g, 'is_irreducible'): return g.is_irreducible() @@ -1819,7 +1821,7 @@ def Cyclic(R, n=None, homog=False, singular=None): if not homog: I = singular.cyclic(n) else: - I = singular.cyclic(n).homog(R2.gen(n-1)) + I = singular.cyclic(n).homog(R2.gen(n - 1)) return R2.ideal(I).change_ring(R) @@ -1870,7 +1872,7 @@ def Katsura(R, n=None, homog=False, singular=None): if not homog: I = singular.katsura(n) else: - I = singular.katsura(n).homog(R2.gen(n-1)) + I = singular.katsura(n).homog(R2.gen(n - 1)) return R2.ideal(I).change_ring(R) diff --git a/src/sage/rings/polynomial/laurent_polynomial_ideal.py b/src/sage/rings/polynomial/laurent_polynomial_ideal.py index 096e6bff57d..a32d9ef506e 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ideal.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ideal.py @@ -28,7 +28,7 @@ class LaurentPolynomialIdeal( Ideal_generic ): - def __init__(self, ring, gens, coerce=True, hint=None): + def __init__(self, ring, gens, coerce=True, hint=None) -> None: r""" Create an ideal in a Laurent polynomial ring. @@ -184,7 +184,7 @@ def _richcmp_(self, right_r, op): else: raise ValueError("invalid comparison") - def __contains__(self, f): + def __contains__(self, f) -> bool: """ Implement containment testing (in) for Laurent polynomial ideals. diff --git a/src/sage/rings/polynomial/pbori/pbori.pyx b/src/sage/rings/polynomial/pbori/pbori.pyx index d5bc16bbe11..88e4095678a 100644 --- a/src/sage/rings/polynomial/pbori/pbori.pyx +++ b/src/sage/rings/polynomial/pbori/pbori.pyx @@ -325,7 +325,7 @@ cdef class BooleanPolynomialRing(BooleanPolynomialRing_base): sage: P == S False """ - def __init__(self, n=None, names=None, order='lex'): + def __init__(self, n=None, names=None, order='lex') -> None: """ Create a new boolean polynomial ring. @@ -1016,7 +1016,7 @@ cdef class BooleanPolynomialRing(BooleanPolynomialRing_base): else: return self._zero_element - def __hash__(self): + def __hash__(self) -> int: """ Return a hash of this boolean polynomial ring. @@ -1877,7 +1877,7 @@ class BooleanMonomialMonoid(UniqueRepresentation, Monoid_class): True sage: TestSuite(M).run() """ - def __init__(self, BooleanPolynomialRing polring): + def __init__(self, BooleanPolynomialRing polring) -> None: """ Create a new boolean polynomial ring. @@ -1915,7 +1915,7 @@ class BooleanMonomialMonoid(UniqueRepresentation, Monoid_class): """ return "MonomialMonoid of %s" % (str(self._ring)) - def __hash__(self): + def __hash__(self) -> int: """ Return a hash for this monoid. @@ -2229,7 +2229,7 @@ cdef class BooleanMonomial(MonoidElement): Use the :meth:`BooleanMonomialMonoid__call__` method and not this constructor to construct these objects. """ - def __init__(self, parent): + def __init__(self, parent) -> None: """ EXAMPLES:: @@ -2363,7 +2363,7 @@ cdef class BooleanMonomial(MonoidElement): res *= d[var] return res - def __hash__(self): + def __hash__(self) -> int: """ Return a hash of this monomial. @@ -2571,7 +2571,7 @@ cdef class BooleanMonomial(MonoidElement): """ return new_BS_from_PBSet(self._pbmonom.set(), self._ring) - def __len__(BooleanMonomial self): + def __len__(BooleanMonomial self) -> int: """ Return 1. @@ -2940,7 +2940,7 @@ cdef class BooleanPolynomial(MPolynomial): Do not use this method to construct boolean polynomials, but use the appropriate ``__call__`` method in the parent. """ - def __init__(self, parent): + def __init__(self, parent) -> None: self._parent = parent self._pbpoly = PBBoolePolynomial((parent)._pbring) @@ -3487,7 +3487,7 @@ cdef class BooleanPolynomial(MPolynomial): """ return self._pbpoly.isZero() - def __bool__(self): + def __bool__(self) -> bool: r""" Check if ``self`` is not zero. @@ -3845,7 +3845,7 @@ cdef class BooleanPolynomial(MPolynomial): else: return B._base._zero_element - def __hash__(self): + def __hash__(self) -> int: r""" Return hash for ``self``. @@ -4799,7 +4799,7 @@ cdef inline BooleanPolynomialIterator new_BPI_from_BooleanPolynomial(BooleanPoly class BooleanPolynomialIdeal(MPolynomialIdeal): - def __init__(self, ring, gens=[], coerce=True): + def __init__(self, ring, gens=[], coerce=True) -> None: """ Construct an ideal in the boolean polynomial ring. @@ -5145,7 +5145,7 @@ class BooleanPolynomialIdeal(MPolynomialIdeal): """ return self.basis.reduced() - def __eq__(self, other): + def __eq__(self, other) -> bool: """ EXAMPLES:: @@ -5171,7 +5171,7 @@ class BooleanPolynomialIdeal(MPolynomialIdeal): else: return self.groebner_basis() == other.groebner_basis() - def __ne__(self, other): + def __ne__(self, other) -> bool: """ EXAMPLES:: @@ -5274,7 +5274,7 @@ cdef class BooleSet: :class:`BooleSet` prints as ``{}`` but are not Python dictionaries. """ - def __init__(self, param=None, ring=None): + def __init__(self, param=None, ring=None) -> None: cdef BooleanPolynomial p if isinstance(param, CCuddNavigator): if ring is None: @@ -5309,7 +5309,7 @@ cdef class BooleSet: self._pbset = PBBooleSet((p)._pbpoly) self._ring = detected_ring - def __repr__(self): + def __repr__(self) -> str: """ EXAMPLES:: @@ -5579,7 +5579,7 @@ cdef class BooleSet: """ return self._pbset.size() - def __hash__(self): + def __hash__(self) -> int: """ EXAMPLES:: @@ -5615,7 +5615,7 @@ cdef class BooleSet: """ return mod_mon_set(self, vs) - def __contains__(self, BooleanMonomial m): + def __contains__(self, BooleanMonomial m) -> bool: """ Return ``True`` if ``m`` is in this set. @@ -5931,7 +5931,7 @@ cdef class CCuddNavigator: def terminal_one(self): return self._pbnav.isTerminated() - def __richcmp__(CCuddNavigator self, CCuddNavigator other, int op): + def __richcmp__(CCuddNavigator self, CCuddNavigator other, int op) -> bool: """ :: @@ -5953,7 +5953,7 @@ cdef class CCuddNavigator: else: return NotImplemented - def __hash__(self): + def __hash__(self) -> int: return self._pbnav.hash() @@ -5972,7 +5972,7 @@ cdef class BooleanPolynomialVector: sage: all(vi.parent() is B for vi in v) True """ - def __init__(self, I=None): + def __init__(self, I=None) -> None: """ Create a new :class:`BooleanPolynomialVector`. @@ -6154,7 +6154,7 @@ cdef class ReductionStrategy: """ Functions and options for boolean polynomial reduction. """ - def __init__(self, ring): + def __init__(self, ring) -> None: """ EXAMPLES:: @@ -6423,7 +6423,7 @@ cdef class ReductionStrategy: cdef class BooleanPolynomialEntry: - def __init__(self, p): + def __init__(self, p) -> None: self.p = p @@ -6433,7 +6433,7 @@ cdef class FGLMStrategy: Groebner basis with respect to a term ordering A to another Groebner basis with respect to a term ordering B. """ - def __init__(self, from_ring, to_ring, BooleanPolynomialVector vec): + def __init__(self, from_ring, to_ring, BooleanPolynomialVector vec) -> None: """ Execute the FGLM algorithm. @@ -6508,7 +6508,7 @@ cdef class GroebnerStrategy: This class is mainly used internally. """ - def __init__(self, param): + def __init__(self, param) -> None: """ INPUT: @@ -7013,7 +7013,7 @@ cdef inline CCuddNavigator new_CN_from_PBNavigator(PBNavigator juice, cdef class VariableBlock: def __init__(self, int size, int start_index, int offset, bint reverse, - BooleanPolynomialRing ring): + BooleanPolynomialRing ring) -> None: self._ring = ring self._block = new PBVarBlock(size, start_index, offset, reverse, ring._pbring) @@ -7764,7 +7764,7 @@ def unpickle_BooleanPolynomialRing(n, names, order): cdef class BooleConstant: - def __init__(self, int value): + def __init__(self, int value) -> None: """ Construct a boolean constant (modulo 2) from integer value: @@ -7780,7 +7780,7 @@ cdef class BooleConstant: """ self._pbconst = PBConstant(value) - def __repr__(self): + def __repr__(self) -> str: """ EXAMPLES:: @@ -7908,7 +7908,7 @@ cdef class VariableFactory: """Implements PolyBoRi's ``Variable()`` constructor and a variable factory for given ring """ - def __init__(self, BooleanPolynomialRing ring=None): + def __init__(self, BooleanPolynomialRing ring=None) -> None: """ Initialize variable factory, if ring is given. Otherwise it initializes a plain constructor @@ -7964,7 +7964,7 @@ cdef class MonomialFactory: sage: fac = MonomialFactory() sage: fac = MonomialFactory(B) """ - def __init__(self, BooleanPolynomialRing ring=None): + def __init__(self, BooleanPolynomialRing ring=None) -> None: """ Initialized a polynomial factory of ring is given. Otherwise it initializes a plain constructor. @@ -8030,7 +8030,7 @@ cdef class PolynomialFactory: Implement PolyBoRi's ``Polynomial()`` constructor and a polynomial factory for given rings. """ - def __init__(self, BooleanPolynomialRing ring=None): + def __init__(self, BooleanPolynomialRing ring=None) -> None: """ Construct a polynomial factory if ring is given, or plain constructor otherwise. diff --git a/src/sage/rings/polynomial/polydict.pyx b/src/sage/rings/polynomial/polydict.pyx index 7d31fab7d56..6911cfa8eb8 100644 --- a/src/sage/rings/polynomial/polydict.pyx +++ b/src/sage/rings/polynomial/polydict.pyx @@ -107,7 +107,9 @@ cdef class PolyDict: can use the method :meth:`remove_zeros` which can be parametrized by a zero test. """ - def __init__(self, pdict, zero=None, remove_zero=None, force_int_exponents=None, force_etuples=None, bint check=True): + def __init__(self, pdict, zero=None, remove_zero=None, + force_int_exponents=None, force_etuples=None, + bint check=True) -> None: """ INPUT: @@ -296,7 +298,7 @@ cdef class PolyDict: deprecation(34000, 'coerce_cefficients is deprecated; use apply_map instead') self.apply_map(A.coerce) - def __hash__(self): + def __hash__(self) -> int: """ Return the hash. @@ -313,7 +315,7 @@ cdef class PolyDict: """ return hash(frozenset(self.__repn.items())) - def __bool__(self): + def __bool__(self) -> bool: """ Return whether the PolyDict is empty. @@ -326,7 +328,7 @@ cdef class PolyDict: """ return bool(self.__repn) - def __len__(self): + def __len__(self) -> int: """ Return the number of terms of this polynomial. @@ -339,7 +341,7 @@ cdef class PolyDict: """ return len(self.__repn) - def __richcmp__(PolyDict left, PolyDict right, int op): + def __richcmp__(PolyDict left, PolyDict right, int op) -> bool: """ Implement the ``__richcmp__`` protocol for `PolyDict`s. @@ -523,7 +525,7 @@ cdef class PolyDict: """ return self.__repn.get(e, default) - def __repr__(self): + def __repr__(self) -> str: r""" String representation. """ @@ -1451,7 +1453,7 @@ cdef class ETuple: x._length = self._length return x - def __init__(self, data=None, length=None): + def __init__(self, data=None, length=None) -> None: """ - ``ETuple()`` -> an empty ETuple - ``ETuple(sequence)`` -> ETuple initialized from sequence's items @@ -1521,7 +1523,7 @@ cdef class ETuple: if self._data != 0: sig_free(self._data) - def __bool__(self): + def __bool__(self) -> bool: r""" Return whether ``self`` is nonzero. @@ -1663,7 +1665,7 @@ cdef class ETuple: return self._data[2 * ind + 1] return 0 - def __hash__(self): + def __hash__(self) -> int: """ x.__hash__() <==> hash(x) """ @@ -1688,7 +1690,7 @@ cdef class ETuple: """ return self._length - def __contains__(self, elem): + def __contains__(self, elem) -> bool: """ ``x.__contains__(n) <==> n in x``. @@ -1712,7 +1714,7 @@ cdef class ETuple: return True return False - def __richcmp__(ETuple self, ETuple other, op): + def __richcmp__(ETuple self, ETuple other, op) -> bool: """ EXAMPLES:: @@ -1819,10 +1821,10 @@ cdef class ETuple: else: yield 0 - def __str__(self): + def __str__(self) -> str: return repr(self) - def __repr__(self): + def __repr__(self) -> str: r""" TESTS:: diff --git a/src/sage/rings/power_series_ring.py b/src/sage/rings/power_series_ring.py index 129477ccc8c..6730f61806a 100644 --- a/src/sage/rings/power_series_ring.py +++ b/src/sage/rings/power_series_ring.py @@ -496,7 +496,7 @@ class PowerSeriesRing_generic(UniqueRepresentation, Parent, Nonexact): """ def __init__(self, base_ring, name=None, default_prec=None, sparse=False, - implementation=None, category=None): + implementation=None, category=None) -> None: """ Initialize a power series ring. @@ -1239,7 +1239,7 @@ def random_element(self, prec=None, *args, **kwds): prec = self.default_prec() return self(self.__poly_ring.random_element(prec-1, *args, **kwds), prec) - def __contains__(self, x): + def __contains__(self, x) -> None: """ Return ``True`` if x is an element of this power series ring or canonically coerces to this ring. diff --git a/src/sage/rings/species.py b/src/sage/rings/species.py index 2e9ccf6bab2..4409a3d7de8 100644 --- a/src/sage/rings/species.py +++ b/src/sage/rings/species.py @@ -267,7 +267,7 @@ class of subgroups conjugate to ``C``, together with the lookup.append(elm) return elm - def __init__(self, parent, dis, domain_partition): + def __init__(self, parent, dis, domain_partition) -> None: r""" Initialize an atomic species. @@ -324,7 +324,7 @@ def grade(self): S = self.parent().grading_set() return S(self._mc) - def __lt__(self, other): + def __lt__(self, other) -> bool: r""" Return whether ``self`` is less than ``other``. @@ -379,7 +379,7 @@ def __lt__(self, other): H = libgap.ConjugateGroup(other._dis, conj_other) return GAP_FAIL != libgap.ContainedConjugates(S, G, H, True) - def __le__(self, other): + def __le__(self, other) -> bool: r""" Return whether ``self`` is less than or equal to ``other``. @@ -537,7 +537,7 @@ def __classcall__(cls, names): names = normalize_names(-1, names) return super().__classcall__(cls, names) - def __init__(self, names): + def __init__(self, names) -> None: r""" Initialize the class of atomic species. @@ -753,7 +753,7 @@ def _rename(self, n): _atomic_set_like_species(n, self._names) - def __contains__(self, x): + def __contains__(self, x) -> bool: r""" Return whether ``x`` is in ``self``. @@ -1030,7 +1030,7 @@ def __classcall__(cls, names): names = normalize_names(-1, names) return UniqueRepresentation.__classcall__(cls, names) - def __init__(self, names): + def __init__(self, names) -> None: r""" Initialize the monoid of molecular species. @@ -2404,7 +2404,7 @@ def __classcall__(cls, base_ring, names): names = normalize_names(-1, names) return super().__classcall__(cls, base_ring, names) - def __init__(self, base_ring, names): + def __init__(self, base_ring, names) -> None: r""" Initialize the ring of polynomial species. diff --git a/src/sage/rings/valuation/valuation_space.py b/src/sage/rings/valuation/valuation_space.py index 957a15ae488..399c8bdec22 100644 --- a/src/sage/rings/valuation/valuation_space.py +++ b/src/sage/rings/valuation/valuation_space.py @@ -100,7 +100,7 @@ class DiscretePseudoValuationSpace(UniqueRepresentation, Homset): sage: TestSuite(H).run() # long time """ - def __init__(self, domain): + def __init__(self, domain) -> None: r""" TESTS:: @@ -187,7 +187,7 @@ def _repr_(self): """ return "Discrete pseudo-valuations on %r" % (self.domain(),) - def __contains__(self, x): + def __contains__(self, x) -> bool: r""" Return whether ``x`` is a valuation in this space.