Skip to content

Commit e716501

Browse files
author
Release Manager
committed
gh-36403: Fix AttributeError doctests when output includes a suggestion (part of python 3.12 support) In python 3.12, attribute errors add a suggestion at the end of the usual error message ("Did you mean ...?"). We add ... at the end of these doctest outputs to fix it. This PR is split in two commits: - The bulk of the changes, in the first commit, was obtained automatically with: ``` git grep -l "AttributeError:" src | xargs sed -ie \ 's/^ *\(AttributeError: .*\)\?has no attribute.*$/&.../' ``` - The second commit includes 3 changes not catched by the sed pattern above. Since this changes a lot of files and is bound to get old, I'd appreciate a quick review + merge to avoid trouble (the PR is long but almost trivial and the review should be easy). I'll soon make a separate PR (on top of this one) with the rest of the support python 3.12 changes, which are maybe not so trivial but much shorter than this one. Related: #36181 @mkoeppe 🙏 URL: #36403 Reported by: Gonzalo Tornaría Reviewer(s): Matthias Köppe
2 parents 293e4db + 5e34da9 commit e716501

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+116
-116
lines changed

src/doc/en/thematic_tutorials/coercion_and_categories.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ However, only "elementary" construction functors have a rank::
12231223
sage: (Fract*Poly).rank
12241224
Traceback (most recent call last):
12251225
...
1226-
AttributeError: 'CompositeConstructionFunctor' object has no attribute 'rank'
1226+
AttributeError: 'CompositeConstructionFunctor' object has no attribute 'rank'...
12271227

12281228
.. end of output
12291229

src/doc/en/thematic_tutorials/tutorial-objects-and-classes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,15 @@ http://docs.python.org/library/ for a complete list. ::
318318
sage: e.__dict__
319319
Traceback (most recent call last):
320320
...
321-
AttributeError: 'sage.rings.integer.Integer' object has no attribute '__dict__'
321+
AttributeError: 'sage.rings.integer.Integer' object has no attribute '__dict__'...
322322

323323
sage: id4 = SymmetricGroup(4).one()
324324
sage: type(id4)
325325
<class 'sage.groups.perm_gps.permgroup_element.SymmetricGroupElement'>
326326
sage: id4.__dict__
327327
Traceback (most recent call last):
328328
...
329-
AttributeError: 'sage.groups.perm_gps.permgroup_element.SymmetricGroupElement' object has no attribute '__dict__'
329+
AttributeError: 'sage.groups.perm_gps.permgroup_element.SymmetricGroupElement' object has no attribute '__dict__'...
330330

331331
.. note::
332332

src/sage/algebras/cluster_algebra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
sage: (t*s).g_vector()
168168
Traceback (most recent call last):
169169
...
170-
AttributeError: 'ClusterAlgebra_with_category.element_class' object has no attribute 'g_vector'
170+
AttributeError: 'ClusterAlgebra_with_category.element_class' object has no attribute 'g_vector'...
171171
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True)
172172
sage: A.explore_to_depth(infinity)
173173
sage: s = A.cluster_variable((0, -1)); s

src/sage/algebras/lie_conformal_algebras/weyl_lie_conformal_algebra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class WeylLieConformalAlgebra(LieConformalAlgebraWithStructureCoefficients):
109109
sage: alpha0.degree()
110110
Traceback (most recent call last):
111111
...
112-
AttributeError: 'WeylLieConformalAlgebra_with_category.element_class' object has no attribute 'degree'
112+
AttributeError: 'WeylLieConformalAlgebra_with_category.element_class' object has no attribute 'degree'...
113113
114114
TESTS::
115115

src/sage/algebras/steenrod/steenrod_algebra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ def homogeneous_component(self, n):
10801080
sage: a.antipode() # not defined
10811081
Traceback (most recent call last):
10821082
...
1083-
AttributeError: 'CombinatorialFreeModule_with_category.element_class' object has no attribute 'antipode'
1083+
AttributeError: 'CombinatorialFreeModule_with_category.element_class' object has no attribute 'antipode'...
10841084
sage: A(a).antipode() # convert to elt of A, then compute antipode
10851085
Sq(2,1) + Sq(5)
10861086

src/sage/categories/category.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ def _with_axioms(self, axioms):
21292129
sage: Semigroups().Inverse()
21302130
Traceback (most recent call last):
21312131
...
2132-
AttributeError: 'Semigroups_with_category' object has no attribute 'Inverse'
2132+
AttributeError: 'Semigroups_with_category' object has no attribute 'Inverse'...
21332133
sage: Semigroups()._with_axioms(["Inverse"])
21342134
Category of semigroups
21352135

src/sage/categories/category_with_axiom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ class from the base category class::
554554
sage: Magmas.Unital.Associative
555555
Traceback (most recent call last):
556556
...
557-
AttributeError: type object 'Magmas.Unital' has no attribute 'Associative'
557+
AttributeError: type object 'Magmas.Unital' has no attribute 'Associative'...
558558
559559
The purpose of this section is to explain the design of the code
560560
layout and the rationale for this mismatch.
@@ -769,7 +769,7 @@ def _(): return LazyImport('sage.categories.rngs', 'Rngs', at_startup=True)
769769
sage: Semirings().NoZeroDivisors()
770770
Traceback (most recent call last):
771771
...
772-
AttributeError: 'Semirings_with_category' object has no attribute 'NoZeroDivisors'
772+
AttributeError: 'Semirings_with_category' object has no attribute 'NoZeroDivisors'...
773773
774774
Concretely, this is to be implemented by defining the new axiom in the
775775
(``SubcategoryMethods`` nested class of the) appropriate category with

src/sage/categories/enumerated_sets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def _list_from_iterator(self):
610610
sage: (QQ^2).list() # indirect test # needs sage.modules
611611
Traceback (most recent call last):
612612
...
613-
AttributeError: 'FreeModule_ambient_field_with_category' object has no attribute 'list'
613+
AttributeError: 'FreeModule_ambient_field_with_category' object has no attribute 'list'...
614614
615615
Here we test that for an object that does not know whether it
616616
is finite or not. Calling ``x.list()`` simply tries to create
@@ -622,11 +622,11 @@ def _list_from_iterator(self):
622622
sage: Q.is_finite()
623623
Traceback (most recent call last):
624624
...
625-
AttributeError: 'QuotientRing_generic_with_category' object has no attribute 'is_finite'
625+
AttributeError: 'QuotientRing_generic_with_category' object has no attribute 'is_finite'...
626626
sage: Q.list() # indirect test
627627
Traceback (most recent call last):
628628
...
629-
AttributeError: 'QuotientRing_generic_with_category' object has no attribute 'list'
629+
AttributeError: 'QuotientRing_generic_with_category' object has no attribute 'list'...
630630
631631
Here is another example. We artificially create a version of
632632
the ring of integers that does not know whether it is finite

src/sage/categories/examples/sets_cat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ class PrimeNumbers_Facade(PrimeNumbers_Abstract):
619619
sage: pf.next()
620620
Traceback (most recent call last):
621621
...
622-
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'next'
622+
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'next'...
623623
624624
unlike in the other implementations::
625625

src/sage/categories/homset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def __init__(self, X, Y, category=None, base=None, check=True):
632632
sage: H = MyHomset(X, Y, category=1, base = ZZ, check = False)
633633
Traceback (most recent call last):
634634
...
635-
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'Homsets'
635+
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'Homsets'...
636636
sage: P.<t> = ZZ[]
637637
sage: f = P.hom([1/2*t])
638638
sage: f.parent().domain()

0 commit comments

Comments
 (0)