Skip to content

Consolidate most 32- and 64-bit special cases in the doctests#41468

Merged
vbraun merged 8 commits intosagemath:developfrom
orlitzky:32bit-workarounds
Jan 25, 2026
Merged

Consolidate most 32- and 64-bit special cases in the doctests#41468
vbraun merged 8 commits intosagemath:developfrom
orlitzky:32bit-workarounds

Conversation

@orlitzky
Copy link
Copy Markdown
Contributor

Pytest does not support the # 32-bit and # 64-bit tags that we apply to platform-dependent output, so in the long run it is desirable to eliminate them. Fortunately most instances are easy to handle simultaneously; this PR begins by tacking the easy ones.

Pytest doesn't support the 32- and 64-bit comment tags that we use to
distinguish the hash() output on machines of differing bitness. In
this case there are however only two expected integer answers, so
it is easy to check for them both without the conditional tags.
In many cases, we have 32- and 64-bit comment tags to differentiate
between output that merely carries more precision in the 64-bit case.
Pytest does not support such tags on the output, so to minimize the
barrier to switching in the future, we use ellipses to indicate that
more digits may appear.
We don't really need to verify the upper limit that was exceeded.
Replacing it with ellipses allows us to combine the 32- and 64-bit
cases.
When there are two possible answers and they are easy to compare with
equality (e.g. integers), we can put them both in a list and use list
membership instead of separate 32- and 64-bit outputs.
Printing the _info() for one of these lists always includes the
sys.maxsize, and its value depends on whether the machine is 32- or
64-bit. To handle both cases with one test, we omit that part of the
output with ellipses.
Rather than list two separate outputs for 32- and 64-bit systems that
differ by 1e-13, we can increase the tolerance a bit and support both.
Printing a numpy array is platform-dependent, because the default
dtype (which is platform-dependent) will not be shown:

  numpy/numpy#25787

We have two instances in our test suite where special comment tags are
used to work around this. This commit passes in dtype="int8" instead,
because int8 is not default on any platform, and therefore makes the
output consistent.
@orlitzky orlitzky marked this pull request as draft January 17, 2026 18:17
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 17, 2026

Documentation preview for this PR (built with commit 5f238bb; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@orlitzky orlitzky marked this pull request as ready for review January 17, 2026 20:13
@orlitzky orlitzky requested review from tobiasdiez and vbraun January 17, 2026 20:14
@orlitzky
Copy link
Copy Markdown
Contributor Author

This fixes most of the easy cases that #40238 wants to remove. The others can surely be worked around too, but I grouped together the ones that are trivial to review.

Note: I don't have a 32-bit machine to run the tests on, so they haven't been run.

Copy link
Copy Markdown
Contributor

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a good solution as well.

Copy link
Copy Markdown
Collaborator

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 19, 2026
sagemathgh-41468: Consolidate most 32- and 64-bit special cases in the doctests
    
Pytest does not support the `# 32-bit` and `# 64-bit` tags that we apply
to platform-dependent output, so in the long run it is desirable to
eliminate them. Fortunately most instances are easy to handle
simultaneously; this PR begins by tacking the easy ones.
    
URL: sagemath#41468
Reported by: Michael Orlitzky
Reviewer(s): David Coudert, Michael Orlitzky, Tobias Diez
@vbraun vbraun merged commit a6e4821 into sagemath:develop Jan 25, 2026
27 of 28 checks passed
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 5, 2026
sagemathgh-41540: Eliminate remaining 32- and 64-bit doctest output tags
    
Our `# 32-bit` and `# 64bit` tags, namely that they must annotate the
output lines and not the input line, are non-standard. We have
replacements that work on the input lines in `# needs 32_bit` or `#
needs !32_bit`, but in some cases we can handle both cases
simultaneously (which is preferable, in my opinion).

This PR replaces all uses of the old tags, updates the documentation to
suggest `# needs 32_bit`, and removes support for the old tags from the
doctest runner. The latter is a backwards-incompatible change, but it
cannot break user code, only custom tests. If we were to make the old-
style tags raise deprecation warnings, exactly the same tests would
break, so it does not seem worthwhile to deprecate and remove later.

This is a follow-up to sagemath#41468, and
supersedes sagemath#40238.

The tests pass for me on a 64-bit system, but I don't have a 32-bit one
to try with.
    
URL: sagemath#41540
Reported by: Michael Orlitzky
Reviewer(s): Chenxin Zhong, Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 7, 2026
sagemathgh-41540: Eliminate remaining 32- and 64-bit doctest output tags
    
Our `# 32-bit` and `# 64bit` tags, namely that they must annotate the
output lines and not the input line, are non-standard. We have
replacements that work on the input lines in `# needs 32_bit` or `#
needs !32_bit`, but in some cases we can handle both cases
simultaneously (which is preferable, in my opinion).

This PR replaces all uses of the old tags, updates the documentation to
suggest `# needs 32_bit`, and removes support for the old tags from the
doctest runner. The latter is a backwards-incompatible change, but it
cannot break user code, only custom tests. If we were to make the old-
style tags raise deprecation warnings, exactly the same tests would
break, so it does not seem worthwhile to deprecate and remove later.

This is a follow-up to sagemath#41468, and
supersedes sagemath#40238.

The tests pass for me on a 64-bit system, but I don't have a 32-bit one
to try with.
    
URL: sagemath#41540
Reported by: Michael Orlitzky
Reviewer(s): Chenxin Zhong, Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 10, 2026
sagemathgh-41540: Eliminate remaining 32- and 64-bit doctest output tags
    
Our `# 32-bit` and `# 64bit` tags, namely that they must annotate the
output lines and not the input line, are non-standard. We have
replacements that work on the input lines in `# needs 32_bit` or `#
needs !32_bit`, but in some cases we can handle both cases
simultaneously (which is preferable, in my opinion).

This PR replaces all uses of the old tags, updates the documentation to
suggest `# needs 32_bit`, and removes support for the old tags from the
doctest runner. The latter is a backwards-incompatible change, but it
cannot break user code, only custom tests. If we were to make the old-
style tags raise deprecation warnings, exactly the same tests would
break, so it does not seem worthwhile to deprecate and remove later.

This is a follow-up to sagemath#41468, and
supersedes sagemath#40238.

The tests pass for me on a 64-bit system, but I don't have a 32-bit one
to try with.
    
URL: sagemath#41540
Reported by: Michael Orlitzky
Reviewer(s): Chenxin Zhong, Tobias Diez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants