Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/doc/en/thematic_tutorials/coercion_and_categories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@

as this base class still provides a few more methods than a general parent::

sage: [p for p in dir(Field) if p not in dir(Parent)]

Check failure on line 107 in src/doc/en/thematic_tutorials/coercion_and_categories.rst

View workflow job for this annotation

GitHub Actions / test-long (src/doc src/sage_docbuild src/sage_setup)

Failed example:

Failed example:: Got: ['_CommutativeRing__fraction_field', '__iter__', '__len__', '__rxor__', '__xor__', '_coerce_', '_coerce_c', '_coerce_impl', '_default_category', '_gens', '_latex_names', '_list', '_one_element', '_zero_element', 'base_extend', 'extension', 'fraction_field', 'gen', 'gens', 'ngens', 'one', 'order', 'zero']

Check failure on line 107 in src/doc/en/thematic_tutorials/coercion_and_categories.rst

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Got: ['_CommutativeRing__fraction_field', '__iter__', '__len__', '__rxor__', '__xor__', '_coerce_', '_coerce_c', '_coerce_impl', '_default_category', '_gens', '_latex_names', '_list', '_one_element', '_zero_element', 'base_extend', 'extension', 'fraction_field', 'gen', 'gens', 'ngens', 'one', 'order', 'zero']

Check failure on line 107 in src/doc/en/thematic_tutorials/coercion_and_categories.rst

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Got: ['_CommutativeRing__fraction_field', '__iter__', '__len__', '__rxor__', '__xor__', '_coerce_', '_coerce_c', '_coerce_impl', '_default_category', '_gens', '_latex_names', '_list', '_one_element', '_zero_element', 'base_extend', 'extension', 'fraction_field', 'gen', 'gens', 'ngens', 'one', 'order', 'zero']

Check failure on line 107 in src/doc/en/thematic_tutorials/coercion_and_categories.rst

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.11, all)

Failed example:

Failed example:: Got: ['_CommutativeRing__fraction_field', '__iter__', '__len__', '__rxor__', '__xor__', '_coerce_', '_coerce_c', '_coerce_impl', '_default_category', '_gens', '_latex_names', '_list', '_one_element', '_zero_element', 'base_extend', 'extension', 'fraction_field', 'gen', 'gens', 'ngens', 'one', 'order', 'zero']

Check failure on line 107 in src/doc/en/thematic_tutorials/coercion_and_categories.rst

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.11, all)

Failed example:

Failed example:: Got: ['_CommutativeRing__fraction_field', '__iter__', '__len__', '__rxor__', '__xor__', '_coerce_', '_coerce_c', '_coerce_impl', '_default_category', '_gens', '_latex_names', '_list', '_one_element', '_zero_element', 'base_extend', 'extension', 'fraction_field', 'gen', 'gens', 'ngens', 'one', 'order', 'zero']

Check failure on line 107 in src/doc/en/thematic_tutorials/coercion_and_categories.rst

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Got: ['_CommutativeRing__fraction_field', '__iter__', '__len__', '__rxor__', '__xor__', '_coerce_', '_coerce_c', '_coerce_impl', '_default_category', '_gens', '_latex_names', '_list', '_one_element', '_zero_element', 'base_extend', 'extension', 'fraction_field', 'gen', 'gens', 'ngens', 'one', 'order', 'zero']
['_CommutativeRing__fraction_field',
'__iter__',
'__len__',
'__rxor__',
'__xor__',
Expand Down
15 changes: 13 additions & 2 deletions src/sage/algebras/yokonuma_hecke_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,20 @@ def __init__(self, d, ct, q, R):
EXAMPLES::

sage: Y = algebras.YokonumaHecke(2, ['F',4])
sage: TestSuite(Y).run()

TESTS:

Run test suites. Note that ``simple_element`` is used instead of just
``Y.an_element()`` because after :issue:`39399`, ``Y.an_element()``
returns a complex object which makes the test suite very slow.
We can change ``simple_element`` back to ``Y.an_element()`` if
the implementation becomes faster.

sage: simple_element = Y.monomial(Y.basis().keys().an_element())
sage: TestSuite(Y).run(elements=[simple_element])
sage: Y = algebras.YokonumaHecke(3, ['G',2])
sage: elts = list(Y.gens()) + [Y.an_element()] + [sum(Y.gens())]
sage: simple_element = Y.monomial(Y.basis().keys().an_element())
sage: elts = list(Y.gens()) + [simple_element] + [sum(Y.gens())]
sage: TestSuite(Y).run(elements=elts) # long time
"""
from sage.categories.sets_cat import cartesian_product
Expand Down
6 changes: 5 additions & 1 deletion src/sage/categories/enumerated_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,11 @@ def _unrank_from_iterator(self, r):
raise ValueError("the rank must be greater than or equal to 0")
if r not in ZZ:
raise ValueError(f"{r=} must be an integer")
for counter, u in enumerate(self):
# we do the below instead of just enumerate(self)
# so that if __iter__ is not available, it raises an error
# instead of fallback to __getitem__, which might call this method,
# leads to infinite recursion
for counter, u in enumerate(self.__iter__()):
if counter == r:
return u
raise ValueError("the rank must be in the range from %s to %s" % (0,counter))
Expand Down
105 changes: 100 additions & 5 deletions src/sage/categories/modules_with_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,20 +1056,20 @@
1
"""
from sage.rings.infinity import Infinity
b = self.base_ring().cardinality()
if b.is_one():
return b
if self.dimension() == Infinity:
return Infinity
if self.dimension() == 0:
from sage.rings.integer_ring import ZZ
return ZZ.one()
return self.base_ring().cardinality() ** self.dimension()
return b ** self.dimension()

def is_finite(self):
r"""
Return whether ``self`` is finite.

This is true if and only if ``self.basis().keys()`` and
``self.base_ring()`` are both finite.

EXAMPLES::

sage: GroupAlgebra(SymmetricGroup(2), IntegerModRing(10)).is_finite() # needs sage.combinat sage.groups sage.modules
Expand All @@ -1079,7 +1079,8 @@
sage: GroupAlgebra(AbelianGroup(1), IntegerModRing(10)).is_finite() # needs sage.groups sage.modules
False
"""
return (self.base_ring().is_finite() and self.basis().keys().is_finite())
R = self.base_ring()
return R.is_zero() or (R.is_finite() and self.basis().is_finite())

def monomial(self, i):
"""
Expand Down Expand Up @@ -1438,6 +1439,100 @@
self.base_ring().random_element())
return a

def __iter__(self):
r"""
Return iterator over the elements of this free module.
The base ring must be countable and the basis must be countable.

EXAMPLES::

sage: from itertools import islice
sage: R.<x> = GF(3)[]
sage: list(islice(iter(R), 10))

Check failure on line 1451 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[2]>", line 1, in <module> list(islice(iter(R), Integer(10))) ^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__'

Check failure on line 1451 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[2]>", line 1, in <module> list(islice(iter(R), Integer(10))) ^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__'

Check failure on line 1451 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[2]>", line 1, in <module> list(islice(iter(R), Integer(10))) ^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__'

Check failure on line 1451 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.11, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/usr/share/miniconda/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[2]>", line 1, in <module> list(islice(iter(R), Integer(10))) ^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__'

Check failure on line 1451 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[a-f]*)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/sage/src/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[2]>", line 1, in <module> list(islice(iter(R), Integer(10))) ^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__'

Check failure on line 1451 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.11, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[2]>", line 1, in <module> list(islice(iter(R), Integer(10))) ^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__'

Check failure on line 1451 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[2]>", line 1, in <module> list(islice(iter(R), Integer(10))) ^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__'
[0, 1, 2, x, x + 1, x + 2, 2*x, 2*x + 1, 2*x + 2, x^2]

TESTS::

sage: R.<x> = Integers(1)[]
sage: [*R]

Check failure on line 1457 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[4]>", line 1, in <module> [*R] File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_commutative_with_category' object has no attribute '__iter__'

Check failure on line 1457 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[4]>", line 1, in <module> [*R] File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_commutative_with_category' object has no attribute '__iter__'

Check failure on line 1457 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[4]>", line 1, in <module> [*R] File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_commutative_with_category' object has no attribute '__iter__'

Check failure on line 1457 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.11, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/usr/share/miniconda/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[4]>", line 1, in <module> [*R] File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_commutative_with_category' object has no attribute '__iter__'

Check failure on line 1457 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[a-f]*)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/sage/src/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[4]>", line 1, in <module> [*R] File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_commutative_with_category' object has no attribute '__iter__'

Check failure on line 1457 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.11, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[4]>", line 1, in <module> [*R] File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_commutative_with_category' object has no attribute '__iter__'

Check failure on line 1457 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[4]>", line 1, in <module> [*R] File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_commutative_with_category' object has no attribute '__iter__'
[0]
sage: R.<x> = LaurentPolynomialRing(Zmod(4))
sage: list(islice(iter(R), 20))
[0, 1, 2, 3, x, 1 + x, 2 + x, 3 + x, 2*x, 1 + 2*x, 2 + 2*x, 3 + 2*x,
3*x, 1 + 3*x, 2 + 3*x, 3 + 3*x, x^-1, x^-1 + 1, x^-1 + 2, x^-1 + 3]
sage: list(islice(iter(QQ^2), 20))
[(0, 0), (1, 0), (0, 1), (-1, 0), (1, 1), (0, -1), (1/2, 0), (-1, 1), (1, -1), (0, 1/2),
(-1/2, 0), (1/2, 1), (-1, -1), (1, 1/2), (0, -1/2), (2, 0), (-1/2, 1), (1/2, -1), (-1, 1/2), (1, -1/2)]
sage: list(islice(iter(QQ[x]), 20))

Check failure on line 1466 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[8]>", line 1, in <module> list(islice(iter(QQ[x]), Integer(20))) ^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_field_with_category' object has no attribute '__iter__'

Check failure on line 1466 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[8]>", line 1, in <module> list(islice(iter(QQ[x]), Integer(20))) ^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_field_with_category' object has no attribute '__iter__'

Check failure on line 1466 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[8]>", line 1, in <module> list(islice(iter(QQ[x]), Integer(20))) ^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_field_with_category' object has no attribute '__iter__'

Check failure on line 1466 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.11, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/usr/share/miniconda/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[8]>", line 1, in <module> list(islice(iter(QQ[x]), Integer(20))) ^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_field_with_category' object has no attribute '__iter__'

Check failure on line 1466 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[a-f]*)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/sage/src/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[8]>", line 1, in <module> list(islice(iter(QQ[x]), Integer(20))) ^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_field_with_category' object has no attribute '__iter__'

Check failure on line 1466 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.11, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.11/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[8]>", line 1, in <module> list(islice(iter(QQ[x]), Integer(20))) ^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_field_with_category' object has no attribute '__iter__'

Check failure on line 1466 in src/sage/categories/modules_with_basis.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 733, in _run self.compile_and_execute(example, compiler, test.globs) File "/Users/runner/miniconda3/envs/sage-dev/lib/python3.12/site-packages/sage/doctest/forker.py", line 1157, in compile_and_execute exec(compiled, globs) File "<doctest sage.categories.modules_with_basis.ModulesWithBasis.ParentMethods.__iter__[8]>", line 1, in <module> list(islice(iter(QQ[x]), Integer(20))) ^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_field_with_category' object has no attribute '__iter__'
[1, -1, x, 1/2, x + 1, x^2, -1/2, -x, x^2 + 1, x^3,
2, x - 1, x^2 + x, x^3 + 1, x^4, -2, -x + 1, -x^2, x^3 + x, x^4 + 1]
"""
from sage.rings.infinity import Infinity
R = self.base_ring()
zero = R.zero()
if R.cardinality() == Infinity:
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
from sage.sets.family import Family
from sage.sets.set import Set
R_nonzero = Set(R) - Set([zero])
basis = self.basis()
from sage.structure.sequence import Sequence_generic
if isinstance(basis, (list, tuple, Sequence_generic)):
basis_elements = basis
basis_iter = None
else:
basis_elements = []
basis_iter = iter(basis)

def _g(coefficients):
nonlocal self, basis_elements, basis_iter
while len(basis_elements) < len(coefficients):
x = next(basis_iter)
basis_elements.append(x)
return self.sum([coefficient * basis_element for coefficient, basis_element
in zip(coefficients, basis_elements)])
from .cartesian_product import cartesian_product
if isinstance(basis, (list, tuple)) or basis.is_finite():
yield from Family(cartesian_product([R] * len(basis)), _g)
# alternatively: yield from DisjointUnionEnumeratedSets(Family(range(len(basis)), _f))
else:
def _f(d):
nonlocal self, R, R_nonzero, _g
return Family(cartesian_product([R] * d + [R_nonzero]), _g, lazy=True)
from sage.rings.semirings.non_negative_integer_semiring import NN
yield from DisjointUnionEnumeratedSets(Family(NN, _f))
assert False, "this should not be reached"
iters = []
v = []
n = 0
yield self.zero()
if R.is_zero():
return
basis_elements = []
basis_iter = iter(self.basis())
while True:
if n == len(iters):
iters.append(iter(R))
v.append(next(iters[n]))
assert v[n] == zero, ("first element of iteration must be zero otherwise result "
"of this and free module __iter__ will be incorrect")
try:
basis_elements.append(next(basis_iter))
except StopIteration:
return
try:
v[n] = next(iters[n])
# yield self(v) # works and is faster with e.g. polynomial ring or FreeModule_generic, but
# fails with e.g. Laurent polynomial ring
yield self.sum([coefficient * basis_element for coefficient, basis_element
in zip(v, basis_elements)])
n = 0
except StopIteration:
iters[n] = iter(R)
v[n] = next(iters[n])
assert v[n] == zero
n += 1

class ElementMethods:
# TODO: Define the appropriate element methods here (instead of in
# subclasses). These methods should be consistent with those on
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ class naming and introspection. Sage currently works around the
Let us now look at the categories of ``C``::

sage: C.categories() # needs sage.combinat sage.groups sage.modules
[Category of finite dimensional Cartesian products of algebras with basis over Rational Field, ...
[Category of Cartesian products of algebras with basis over Rational Field, ...
Category of Cartesian products of algebras over Rational Field, ...
Category of Cartesian products of semigroups, Category of semigroups, ...
Category of Cartesian products of magmas, ..., Category of magmas, ...
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/cartesian_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self, *iters):
category = EnumeratedSets()
try:
category = category.Finite() if self.is_finite() else category.Infinite()
except ValueError: # Unable to determine if it is finite or not
except (ValueError, NotImplementedError): # Unable to determine if it is finite or not
pass

def iterfunc():
Expand Down
5 changes: 2 additions & 3 deletions src/sage/combinat/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,8 @@ def _an_element_(self):
except Exception:
pass
try:
g = iter(self.basis().keys())
for c in range(1, 4):
x = x + self.term(next(g), R(c))
for c, gi in zip(range(1, 4), I):
x = x + self.term(gi, R(c))
except Exception:
pass
return x
Expand Down
26 changes: 4 additions & 22 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2479,9 +2479,9 @@ def __iter__(self):
sage: [sum(o <= b and m <= b for o,m in norms) for b in range(8)] # did not miss any
[1, 11, 61, 231, 681, 1683, 3653, 7183]
"""
G = self.gens()
if not G:
yield self(0)
n = self.rank()
if n == 0:
yield self.zero()
return

R = self.base_ring()
Expand All @@ -2507,32 +2507,14 @@ def aux(length, norm, max_):
norm - max_ - lnorm, rmax):
for mid in (+max_, -max_):
yield left + (mid,) + right
n = len(G)
for norm in itertools.count(0):
mm = (norm + n - 1) // n
for max_ in range(mm, norm + 1):
for vec in aux(n, norm, max_):
yield self.linear_combination_of_basis(vec)
assert False # should loop forever

iters = [iter(R) for _ in range(len(G))]
for x in iters:
next(x) # put at 0
zero = R.zero()
v = [zero for _ in range(len(G))]
n = 0
z = self(0)
yield z
while n < len(G):
try:
v[n] = next(iters[n])
yield self.linear_combination_of_basis(v)
n = 0
except StopIteration:
iters[n] = iter(R) # reset
next(iters[n]) # put at 0
v[n] = zero
n += 1
yield from super().__iter__()

def cardinality(self):
r"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/lazy_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@

sage: L = LazyLaurentSeriesRing(ZZ['x, y'], 't')
sage: TestSuite(L).run() # needs sage.libs.singular
sage: L.category()

Check failure on line 1905 in src/sage/rings/lazy_series_ring.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Category of infinite commutative no zero divisors algebras over (unique factorization domains and algebras with basis over (Dedekind domains and euclidean domains and noetherian rings and infinite enumerated sets and metric spaces) and commutative algebras over (Dedekind domains and euclidean domains and noetherian rings and infinite enumerated sets and metric spaces) and infinite enumerated sets)
Category of infinite commutative no zero divisors algebras over
(unique factorization domains and algebras with basis over
(Dedekind domains and euclidean domains
Expand Down Expand Up @@ -2065,15 +2065,15 @@
sage: L.some_elements()[:7]
[0, 1, z,
z^-4 + z^-3 + z^2 + z^3,
z^-2,
0,
1 + z + z^3 + z^4 + z^6 + O(z^7),
z^-1 + z + z^3 + O(z^5)]

sage: L = LazyLaurentSeriesRing(GF(3), 'z')
sage: L.some_elements()[:7]
[0, 1, z,
z^-3 + z^-1 + 2 + z + z^2 + z^3,
z^-2,
0,
z^-3 + z^-2 + z^-1 + 2 + 2*z + 2*z^2 + O(z^3),
z^-2 + z^-1 + z + z^2 + z^4 + O(z^5)]
"""
Expand Down Expand Up @@ -2754,7 +2754,7 @@
sage: L = LazyPowerSeriesRing(Zmod(6), 't')
sage: TestSuite(L).run(skip=['_test_revert'])
sage: L = LazyPowerSeriesRing(Zmod(6), 's, t')
sage: TestSuite(L).run(skip=['_test_revert'])

Check warning on line 2757 in src/sage/rings/lazy_series_ring.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.11, all)

Warning: slow doctest:

slow doctest:: Test ran for 6.11s cpu, 12.36s wall Check ran for 0.00s cpu, 0.00s wall

Check warning on line 2757 in src/sage/rings/lazy_series_ring.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Warning: slow doctest:

slow doctest:: Test ran for 6.03s cpu, 11.07s wall Check ran for 0.00s cpu, 0.00s wall

sage: L = LazyPowerSeriesRing(QQ['q'], 't')
sage: TestSuite(L).run(skip='_test_fraction_field')
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/laurent_polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,10 @@
TESTS::

sage: TestSuite(LaurentPolynomialRing(Zmod(2), 'y')).run()
sage: TestSuite(LaurentPolynomialRing(Zmod(4), 'y')).run()
sage: TestSuite(LaurentPolynomialRing(Zmod(4), 'y')).run(skip=['_test_divides']) # issue 40372
sage: TestSuite(LaurentPolynomialRing(ZZ, 'u')).run()
sage: TestSuite(LaurentPolynomialRing(Zmod(2)['T'], 'u')).run()

Check failure on line 447 in src/sage/rings/polynomial/laurent_polynomial_ring.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Failure in _test_additive_associativity: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/additive_semigroups.py", line 84, in _test_additive_associativity S = tester.some_elements() ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 576, in some_elements return list(some_tuples(S, repeat, self._max_runs, self._max_samples)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/enumerated_sets.py", line 937, in _some_elements_from_iterator for i in self: ^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/modules_with_basis.py", line 1503, in __iter__ yield from DisjointUnionEnumeratedSets(Family(NN, _f)) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/sets/disjoint_union_enumerated_sets.py", line 550, in __iter__ el = next(el_iter) ^^^^^^^^^^^^^ File "sage/sets/family.pyx", line 1148, in __iter__ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/sets_cat.py", line 2331, in __iter__ digits = [next(it) for it in wheels] ^^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/sets/set.py", line 1878, in __iter__ for x in self._X: ^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/sets/set.py", line 580, in __iter__ return iter(self.__object) ^^^^^^^^^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__' ------------------------------------------------------------ Failure in _test_associativity: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/semigroups.py", line 118, in _test_associativity S = tester.some_elements() ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 576, in some_elements return list(some_tuples(S, repeat, self._max_runs, self._max_samples)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/enumerated_sets.py", line 937, in _some_elements_from_iterator for i in self: ^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/modules_with_basis.py", line 1503, in __iter__ yield from DisjointUnionEnumeratedSets(Family(NN, _f)) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/sets/disjoint_union_enumerated_sets.py", line 550, in __iter__ el = next(el_iter) ^^^^^^^^^^^^^

Check failure on line 447 in src/sage/rings/polynomial/laurent_polynomial_ring.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Failure in _test_additive_associativity: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/additive_semigroups.py", line 84, in _test_additive_associativity S = tester.some_elements() ^^^^^^^^^^^^^^^^^^^^^^ File "/sage/src/sage/misc/sage_unittest.py", line 576, in some_elements return list(some_tuples(S, repeat, self._max_runs, self._max_samples)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/sage/src/sage/categories/enumerated_sets.py", line 937, in _some_elements_from_iterator for i in self: File "/sage/src/sage/categories/modules_with_basis.py", line 1503, in __iter__ yield from DisjointUnionEnumeratedSets(Family(NN, _f)) File "/sage/src/sage/sets/disjoint_union_enumerated_sets.py", line 550, in __iter__ el = next(el_iter) ^^^^^^^^^^^^^ File "sage/sets/family.pyx", line 1148, in __iter__ File "/sage/src/sage/categories/sets_cat.py", line 2331, in __iter__ digits = [next(it) for it in wheels] ^^^^^^^^ File "/sage/src/sage/sets/set.py", line 1878, in __iter__ for x in self._X: File "/sage/src/sage/sets/set.py", line 580, in __iter__ return iter(self.__object) ^^^^^^^^^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__' ------------------------------------------------------------ Failure in _test_associativity: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/semigroups.py", line 118, in _test_associativity S = tester.some_elements() ^^^^^^^^^^^^^^^^^^^^^^ File "/sage/src/sage/misc/sage_unittest.py", line 576, in some_elements return list(some_tuples(S, repeat, self._max_runs, self._max_samples)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/sage/src/sage/categories/enumerated_sets.py", line 937, in _some_elements_from_iterator for i in self: File "/sage/src/sage/categories/modules_with_basis.py", line 1503, in __iter__ yield from DisjointUnionEnumeratedSets(Family(NN, _f)) File "/sage/src/sage/sets/disjoint_union_enumerated_sets.py", line 550, in __iter__ el = next(el_iter) ^^^^^^^^^^^^^ File "sage/sets/family.pyx", line 1148, in __iter__ File "/sage/src/sage/categories/sets_cat.py", line 2331, in __iter__ digits = [next(it) for it in wheels] ^^^^^^^^ File "/sage/src/sage/sets/set.py", line 1878, in __iter__ for x in self._X: File "/sage/src/sage/sets/set.py", line 580, in __iter__ return iter(self.__object) ^^^^^^^^^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__' ------------------------------------------------------------ Failure in _test_distribut
sage: TestSuite(LaurentPolynomialRing(Zmod(4)['T'], 'u')).run()

Check failure on line 448 in src/sage/rings/polynomial/laurent_polynomial_ring.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Failure in _test_additive_associativity: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/additive_semigroups.py", line 84, in _test_additive_associativity S = tester.some_elements() ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 576, in some_elements return list(some_tuples(S, repeat, self._max_runs, self._max_samples)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/enumerated_sets.py", line 937, in _some_elements_from_iterator for i in self: ^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/modules_with_basis.py", line 1503, in __iter__ yield from DisjointUnionEnumeratedSets(Family(NN, _f)) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/sets/disjoint_union_enumerated_sets.py", line 550, in __iter__ el = next(el_iter) ^^^^^^^^^^^^^ File "sage/sets/family.pyx", line 1148, in __iter__ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/sets_cat.py", line 2331, in __iter__ digits = [next(it) for it in wheels] ^^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/sets/set.py", line 1878, in __iter__ for x in self._X: ^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/sets/set.py", line 580, in __iter__ return iter(self.__object) ^^^^^^^^^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_n_with_category' object has no attribute '__iter__' ------------------------------------------------------------ Failure in _test_associativity: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/semigroups.py", line 118, in _test_associativity S = tester.some_elements() ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 576, in some_elements return list(some_tuples(S, repeat, self._max_runs, self._max_samples)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/enumerated_sets.py", line 937, in _some_elements_from_iterator for i in self: ^^^^ File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/modules_with_basis.py", line 1503, in __iter__ yield from DisjointUnionEnumeratedSets(Family(NN, _f)) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/sets/disjoint_union_enumerated_sets.py", line 550, in __iter__ el = next(el_iter) ^^^^^^^^^^^^^

Check failure on line 448 in src/sage/rings/polynomial/laurent_polynomial_ring.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Failure in _test_additive_associativity: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/additive_semigroups.py", line 84, in _test_additive_associativity S = tester.some_elements() ^^^^^^^^^^^^^^^^^^^^^^ File "/sage/src/sage/misc/sage_unittest.py", line 576, in some_elements return list(some_tuples(S, repeat, self._max_runs, self._max_samples)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/sage/src/sage/categories/enumerated_sets.py", line 937, in _some_elements_from_iterator for i in self: File "/sage/src/sage/categories/modules_with_basis.py", line 1503, in __iter__ yield from DisjointUnionEnumeratedSets(Family(NN, _f)) File "/sage/src/sage/sets/disjoint_union_enumerated_sets.py", line 550, in __iter__ el = next(el_iter) ^^^^^^^^^^^^^ File "sage/sets/family.pyx", line 1148, in __iter__ File "/sage/src/sage/categories/sets_cat.py", line 2331, in __iter__ digits = [next(it) for it in wheels] ^^^^^^^^ File "/sage/src/sage/sets/set.py", line 1878, in __iter__ for x in self._X: File "/sage/src/sage/sets/set.py", line 580, in __iter__ return iter(self.__object) ^^^^^^^^^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_n_with_category' object has no attribute '__iter__' ------------------------------------------------------------ Failure in _test_associativity: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/semigroups.py", line 118, in _test_associativity S = tester.some_elements() ^^^^^^^^^^^^^^^^^^^^^^ File "/sage/src/sage/misc/sage_unittest.py", line 576, in some_elements return list(some_tuples(S, repeat, self._max_runs, self._max_samples)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/sage/src/sage/categories/enumerated_sets.py", line 937, in _some_elements_from_iterator for i in self: File "/sage/src/sage/categories/modules_with_basis.py", line 1503, in __iter__ yield from DisjointUnionEnumeratedSets(Family(NN, _f)) File "/sage/src/sage/sets/disjoint_union_enumerated_sets.py", line 550, in __iter__ el = next(el_iter) ^^^^^^^^^^^^^ File "sage/sets/family.pyx", line 1148, in __iter__ File "/sage/src/sage/categories/sets_cat.py", line 2331, in __iter__ digits = [next(it) for it in wheels] ^^^^^^^^ File "/sage/src/sage/sets/set.py", line 1878, in __iter__ for x in self._X: File "/sage/src/sage/sets/set.py", line 580, in __iter__ return iter(self.__object) ^^^^^^^^^^^^^^^^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_n_with_category' object has no attribute '__iter__' ------------------------------------------------------------ Failure in _test_distribut
"""
if R.ngens() != 1:
raise ValueError("must be 1 generator")
Expand Down
28 changes: 18 additions & 10 deletions src/sage/rings/polynomial/polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
sage: (x - 2/3)*(x^2 - 8*x + 16)
x^3 - 26/3*x^2 + 64/3*x - 32/3

sage: category(ZZ['x'])

Check failure on line 256 in src/sage/rings/polynomial/polynomial_ring.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Join of Category of unique factorization domains and Category of algebras with basis over (Dedekind domains and euclidean domains and noetherian rings and infinite enumerated sets and metric spaces) and Category of commutative algebras over (Dedekind domains and euclidean domains and noetherian rings and infinite enumerated sets and metric spaces) and Category of infinite enumerated sets
Join of Category of unique factorization domains
and Category of algebras with basis over
(Dedekind domains and euclidean domains
Expand All @@ -266,14 +266,10 @@
and Category of infinite sets

sage: category(GF(7)['x'])
Join of Category of euclidean domains
and Category of algebras with basis over
(finite enumerated fields and subquotients of monoids
and quotients of semigroups)
and Category of commutative algebras over
(finite enumerated fields and subquotients of monoids
and quotients of semigroups)
and Category of infinite sets
Join of Category of euclidean domains and Category of algebras with basis over
(finite enumerated fields and subquotients of monoids and quotients of semigroups) and
Category of commutative algebras over (finite enumerated fields and subquotients of monoids
and quotients of semigroups) and Category of infinite enumerated sets

TESTS:

Expand All @@ -286,7 +282,9 @@
Check that category for zero ring::

sage: PolynomialRing(Zmod(1), 'x').category()
Category of finite commutative rings
Category of finite enumerated commutative algebras with basis over
(finite commutative rings and subquotients of monoids and
quotients of semigroups and finite enumerated sets)

Check ``is_finite`` inherited from category (:issue:`24432`)::

Expand All @@ -305,7 +303,7 @@
# We trust that, if category is given, it is useful and does not need to be joined
# with the default category
if base_ring.is_zero():
category = categories.rings.Rings().Commutative().Finite()
category = categories.rings.Rings().Commutative().Finite().Enumerated() & categories.algebras.Algebras(base_ring.category()).WithBasis()
else:
defaultcat = polynomial_default_category(base_ring.category(), 1)
category = check_default_category(defaultcat, category)
Expand Down Expand Up @@ -1050,6 +1048,16 @@
h = self._cached_hash = hash((self.base_ring(),self.variable_name()))
return h

def _an_element_(self):
"""
Return an arbitrary element of this polynomial ring.

Strictly speaking this is not necessary because it is already provided by the category
framework, but before :issue:`39399` this returns the generator, we keep the behavior
because it is more convenient.
"""
return self.gen()

def _repr_(self):
try:
return self._cached_repr
Expand Down
3 changes: 3 additions & 0 deletions src/sage/rings/polynomial/polynomial_ring_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,12 @@

The generic implementation is different in some cases::

sage: R = PolynomialRing(GF(2), 'j', implementation='generic'); TestSuite(R).run(skip=['_test_construction', '_test_pickling']); type(R)

Check failure on line 441 in src/sage/rings/polynomial/polynomial_ring_constructor.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: ^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_field_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains <class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category'>

Check failure on line 441 in src/sage/rings/polynomial/polynomial_ring_constructor.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_field_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains <class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category'>
<class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category'>
sage: S = PolynomialRing(GF(2), 'j'); TestSuite(S).run(); type(S)

Check failure on line 443 in src/sage/rings/polynomial/polynomial_ring_constructor.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: ^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains <class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_mod_p_with_category'>

Check failure on line 443 in src/sage/rings/polynomial/polynomial_ring_constructor.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains <class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_mod_p_with_category'>
<class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_mod_p_with_category'>

sage: R = PolynomialRing(ZZ, 'x,y', implementation='generic'); TestSuite(R).run(skip=['_test_elements', '_test_elements_eq_transitive']); type(R)

Check failure on line 446 in src/sage/rings/polynomial/polynomial_ring_constructor.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: ^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'MPolynomialRing_polydict_domain_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains <class 'sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_domain_with_category'>

Check failure on line 446 in src/sage/rings/polynomial/polynomial_ring_constructor.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'MPolynomialRing_polydict_domain_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains <class 'sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_domain_with_category'>
<class 'sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_domain_with_category'>
sage: S = PolynomialRing(ZZ, 'x,y'); TestSuite(S).run(skip='_test_elements'); type(S) # needs sage.libs.singular
<class 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular'>
Expand All @@ -451,9 +451,9 @@
Sparse univariate polynomials only support a generic
implementation::

sage: R = PolynomialRing(ZZ, 'j', sparse=True); TestSuite(R).run(); type(R)

Check failure on line 454 in src/sage/rings/polynomial/polynomial_ring_constructor.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_integral_domain_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains <class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_integral_domain_with_category'>
<class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_integral_domain_with_category'>
sage: R = PolynomialRing(GF(49), 'j', sparse=True); TestSuite(R).run(); type(R) # needs sage.rings.finite_rings

Check failure on line 456 in src/sage/rings/polynomial/polynomial_ring_constructor.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_field_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains <class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category'>
<class 'sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category'>

If the requested implementation is not known or not supported for
Expand Down Expand Up @@ -577,9 +577,9 @@

We run the testsuite for various polynomial rings, skipping tests that currently fail::

sage: R.<w> = PolynomialRing(PolynomialRing(GF(7),'k')); TestSuite(R).run(); R

Check failure on line 580 in src/sage/rings/polynomial/polynomial_ring_constructor.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_integral_domain_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains Univariate Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7
Univariate Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7
sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); TestSuite(ZxNTL).run(skip='_test_pickling'); ZxNTL # needs sage.libs.ntl

Check failure on line 582 in src/sage/rings/polynomial/polynomial_ring_constructor.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sage/src/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/sage/src/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_integral_domain_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains Univariate Polynomial Ring in x over Integer Ring (using NTL)
Univariate Polynomial Ring in x over Integer Ring (using NTL)
sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); TestSuite(ZxFLINT).run(); ZxFLINT
Univariate Polynomial Ring in x over Integer Ring
Expand Down Expand Up @@ -899,6 +899,7 @@
from sage.categories.algebras import Algebras
# Some fixed categories, in order to avoid the function call overhead
_FiniteSets = categories.sets_cat.Sets().Finite()
_EnumeratedSets = categories.sets_cat.Sets().Enumerated()
_InfiniteSets = categories.sets_cat.Sets().Infinite()
_EuclideanDomains = categories.euclidean_domains.EuclideanDomains()
_UniqueFactorizationDomains = categories.unique_factorization_domains.UniqueFactorizationDomains()
Expand Down Expand Up @@ -950,6 +951,8 @@
if n_variables:
# here we assume the base ring to be nonzero
category = category.Infinite()
if base_ring_category.is_subcategory(_EnumeratedSets):
category = category.Enumerated()
else:
if base_ring_category.is_subcategory(_Fields):
category = category & _Fields
Expand Down
25 changes: 15 additions & 10 deletions src/sage/rings/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

from sage.structure.coerce cimport coercion_model
from sage.structure.parent cimport Parent
from sage.structure.category_object cimport check_default_category
from sage.structure.category_object cimport CategoryObject, check_default_category
from sage.categories.rings import Rings
from sage.categories.algebras import Algebras
from sage.categories.commutative_algebras import CommutativeAlgebras
Expand Down Expand Up @@ -179,7 +179,7 @@
running ._test_zero_divisors() . . . pass
sage: TestSuite(QQ['x','y']).run(skip='_test_elements') # needs sage.libs.singular
sage: TestSuite(ZZ['x','y']).run(skip='_test_elements') # needs sage.libs.singular
sage: TestSuite(ZZ['x','y']['t']).run()

Check failure on line 182 in src/sage/rings/ring.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Failure in _test_enumerated_set_contains: Traceback (most recent call last): File "sage/structure/category_object.pyx", line 857, in sage.structure.category_object.CategoryObject.getattr_from_category KeyError: '__iter__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 298, in run test_method(tester=tester) File "/usr/share/miniconda/envs/sage-dev/lib/python3.12/site-packages/sage/categories/enumerated_sets.py", line 1053, in _test_enumerated_set_contains for w in self: ^^^^ File "sage/rings/ring.pyx", line 279, in sage.rings.ring.Ring.__iter__ File "sage/structure/category_object.pyx", line 866, in sage.structure.category_object.CategoryObject.getattr_from_category File "sage/cpython/getattr.pyx", line 358, in sage.cpython.getattr.getattr_from_other_class AttributeError: 'PolynomialRing_integral_domain_with_category' object has no attribute '__iter__' ------------------------------------------------------------ The following tests failed: _test_enumerated_set_contains

Test against another bug fixed in :issue:`9944`::

Expand Down Expand Up @@ -260,18 +260,23 @@
category=category)

def __iter__(self):
r"""
Return an iterator through the elements of ``self``.
Not implemented in general.
"""
This method is provided so that if ``ParentMethods`` or ``ElementMethods``
provides ``__iter__``, it is usable from ``iter()``.
To avoid metaclass confusion, Python only lookups special methods
from type objects.

EXAMPLES::
This should be in ``CategoryObject``, but it does not work for unknown reasons.

sage: sage.rings.ring.Ring.__iter__(ZZ)
Traceback (most recent call last):
...
NotImplementedError: object does not support iteration
TESTS::

sage: R.<x,y> = ZZ[]
sage: next(iter(R))
1
"""
raise NotImplementedError("object does not support iteration")
cdef CategoryObject c = <CategoryObject?>self
if c:
return self.getattr_from_category('__iter__')()

def __len__(self):
r"""
Expand Down
Loading
Loading