Skip to content

Commit

Permalink
QuaternionAlgebra: Use __classcall_private__
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Jun 16, 2024
1 parent 31e2166 commit 6e8d71f
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/sage/algebras/quatalg/quaternion_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
kronecker as kronecker_symbol,
prime_divisors,
valuation)
from sage.misc.classcall_metaclass import ClasscallMetaclass
from sage.rings.real_mpfr import RR
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
Expand Down Expand Up @@ -232,7 +233,8 @@ def create_key(self, arg0, arg1=None, arg2=None, names='i,j,k'):
TESTS::
sage: QuaternionAlgebra.create_key(-1,-1)
sage: from sage.algebras.quaternion_algebra import _QuaternionAlgebra

Check failure on line 236 in src/sage/algebras/quatalg/quaternion_algebra.py

View workflow job for this annotation

GitHub Actions / test-new

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "/sage/src/sage/doctest/forker.py", line 715, in _run self.compile_and_execute(example, compiler, test.globs) File "/sage/src/sage/doctest/forker.py", line 1147, in compile_and_execute exec(compiled, globs) File "<doctest sage.algebras.quatalg.quaternion_algebra.QuaternionAlgebraFactory.create_key[0]>", line 1, in <module> from sage.algebras.quaternion_algebra import _QuaternionAlgebra ImportError: cannot import name '_QuaternionAlgebra' from 'sage.algebras.quaternion_algebra' (/sage/src/sage/algebras/quaternion_algebra.py)
sage: _QuaternionAlgebra.create_key(-1,-1)

Check failure on line 237 in src/sage/algebras/quatalg/quaternion_algebra.py

View workflow job for this annotation

GitHub Actions / test-new

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "/sage/src/sage/doctest/forker.py", line 715, in _run self.compile_and_execute(example, compiler, test.globs) File "/sage/src/sage/doctest/forker.py", line 1147, in compile_and_execute exec(compiled, globs) File "<doctest sage.algebras.quatalg.quaternion_algebra.QuaternionAlgebraFactory.create_key[1]>", line 1, in <module> _QuaternionAlgebra.create_key(-Integer(1),-Integer(1)) NameError: name '_QuaternionAlgebra' is not defined
(Rational Field, -1, -1, ('i', 'j', 'k'))
"""
# QuaternionAlgebra(D)
Expand Down Expand Up @@ -285,15 +287,16 @@ def create_object(self, version, key, **extra_args):
TESTS::
sage: QuaternionAlgebra.create_object("6.0", (QQ, -1, -1, ('i', 'j', 'k')))
sage: from sage.algebras.quaternion_algebra import _QuaternionAlgebra

Check failure on line 290 in src/sage/algebras/quatalg/quaternion_algebra.py

View workflow job for this annotation

GitHub Actions / test-new

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "/sage/src/sage/doctest/forker.py", line 715, in _run self.compile_and_execute(example, compiler, test.globs) File "/sage/src/sage/doctest/forker.py", line 1147, in compile_and_execute exec(compiled, globs) File "<doctest sage.algebras.quatalg.quaternion_algebra.QuaternionAlgebraFactory.create_object[0]>", line 1, in <module> from sage.algebras.quaternion_algebra import _QuaternionAlgebra ImportError: cannot import name '_QuaternionAlgebra' from 'sage.algebras.quaternion_algebra' (/sage/src/sage/algebras/quaternion_algebra.py)
sage: _QuaternionAlgebra.create_object("6.0", (QQ, -1, -1, ('i', 'j', 'k')))

Check failure on line 291 in src/sage/algebras/quatalg/quaternion_algebra.py

View workflow job for this annotation

GitHub Actions / test-new

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "/sage/src/sage/doctest/forker.py", line 715, in _run self.compile_and_execute(example, compiler, test.globs) File "/sage/src/sage/doctest/forker.py", line 1147, in compile_and_execute exec(compiled, globs) File "<doctest sage.algebras.quatalg.quaternion_algebra.QuaternionAlgebraFactory.create_object[1]>", line 1, in <module> _QuaternionAlgebra.create_object("6.0", (QQ, -Integer(1), -Integer(1), ('i', 'j', 'k'))) NameError: name '_QuaternionAlgebra' is not defined
Quaternion Algebra (-1, -1) with base ring Rational Field
"""
K, a, b, names = key
return QuaternionAlgebra_ab(K, a, b, names=names)


QuaternionAlgebra = QuaternionAlgebraFactory("QuaternionAlgebra")
_QuaternionAlgebra = QuaternionAlgebraFactory("QuaternionAlgebra")

########################################################
# Classes
Expand All @@ -309,26 +312,22 @@ def is_QuaternionAlgebra(A):
sage: sage.algebras.quatalg.quaternion_algebra.is_QuaternionAlgebra(QuaternionAlgebra(QQ,-1,-1))
doctest:warning...
DeprecationWarning: the function is_QuaternionAlgebra is deprecated;
use 'isinstance(..., QuaternionAlgebra_abstract)' instead
use 'isinstance(..., QuaternionAlgebra)' instead
See https://github.com/sagemath/sage/issues/37896 for details.
True
sage: sage.algebras.quatalg.quaternion_algebra.is_QuaternionAlgebra(ZZ)
False
"""
from sage.misc.superseded import deprecation
deprecation(37896, "the function is_QuaternionAlgebra is deprecated; use 'isinstance(..., QuaternionAlgebra_abstract)' instead")
return isinstance(A, QuaternionAlgebra_abstract)
deprecation(37896, "the function is_QuaternionAlgebra is deprecated; use 'isinstance(..., QuaternionAlgebra)' instead")
return isinstance(A, QuaternionAlgebra)


class QuaternionAlgebra_abstract(Parent):
def _repr_(self):
"""
EXAMPLES::
class QuaternionAlgebra(Parent, metaclass=ClasscallMetaclass):

sage: sage.algebras.quatalg.quaternion_algebra.QuaternionAlgebra_abstract(QQ)._repr_()
'Quaternion Algebra with base ring Rational Field'
"""
return "Quaternion Algebra with base ring %s" % self.base_ring()
@staticmethod
def __classcall_private__(cls, *args, **kwds):
return _QuaternionAlgebra(*args, **kwds)

def ngens(self):
"""
Expand Down Expand Up @@ -620,7 +619,10 @@ def vector_space(self):
return self.free_module()


class QuaternionAlgebra_ab(QuaternionAlgebra_abstract):
QuaternionAlgebra_abstract = QuaternionAlgebra # deprecated alias


class QuaternionAlgebra_ab(QuaternionAlgebra):
"""
A quaternion algebra of the form `(a, b)_K`.
Expand Down

0 comments on commit 6e8d71f

Please sign in to comment.