Skip to content

Enable use of from __future__ import annotations for ruff diagnostics - #42996

Merged
vbraun merged 3 commits into
sagemath:developfrom
vincentmacri:future_import
Oct 22, 2026
Merged

vbraun merged 3 commits into
sagemath:developfrom
vincentmacri:future_import

Conversation

@vincentmacri

@vincentmacri vincentmacri commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Enable a setting for ruff to add from __future__ import annotations where doing so would simplify/improve code, and fix the new resulting linter violations.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

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

@vbraun

vbraun commented Oct 17, 2026

Copy link
Copy Markdown
Member
src/bin/sage -t --long --warn-long 30.0 --random-seed=123 src/sage/rings/finite_rings/finite_field_constructor.py
**********************************************************************
File "src/sage/rings/finite_rings/finite_field_constructor.py", line 530, in sage.rings.finite_rings.finite_field_constructor.FiniteFieldFactory
Failed example:
    typing.get_origin(ann) == collections.abc.Callable
Expected:
    True
Got:
    False
**********************************************************************
File "src/sage/rings/finite_rings/finite_field_constructor.py", line 532, in sage.rings.finite_rings.finite_field_constructor.FiniteFieldFactory
Failed example:
    typing.get_type_hints(FiniteFieldFactory)['__call__'] == collections.abc.Callable[..., FiniteField]
Exception raised:
    Traceback (most recent call last):
      File "/home/release/Sage/src/sage/doctest/forker.py", line 732, in _run
        self.compile_and_execute(example, compiler, test.globs)
        ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/release/Sage/src/sage/doctest/forker.py", line 1154, in compile_and_execute
        exec(compiled, globs)
        ~~~~^^^^^^^^^^^^^^^^^
      File "<doctest sage.rings.finite_rings.finite_field_constructor.FiniteFieldFactory[87]>", line 1, in <module>
        typing.get_type_hints(FiniteFieldFactory)['__call__'] == collections.abc.Callable[Ellipsis, FiniteField]
        ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib64/python3.14/typing.py", line 2399, in get_type_hints
        value = _eval_type(value, base_globals, base_locals, (),
                           format=format, owner=obj, prefer_fwd_module=True)
      File "/usr/lib64/python3.14/typing.py", line 461, in _eval_type
        return evaluate_forward_ref(t, globals=globalns, locals=localns,
                                    type_params=type_params, owner=owner,
                                    _recursive_guard=recursive_guard, format=format)
      File "/usr/lib64/python3.14/typing.py", line 1003, in evaluate_forward_ref
        value = forward_ref.evaluate(globals=globals, locals=locals,
                                     type_params=type_params, owner=owner, format=format)
      File "/usr/lib64/python3.14/annotationlib.py", line 207, in evaluate
        return eval(code, globals=globals, locals=locals)
      File "<string>", line 1, in <module>
    NameError: name 'Callable' is not defined. Did you mean: 'callable'?
**********************************************************************
1 item had failures:
   2 of  89 in sage.rings.finite_rings.finite_field_constructor.FiniteFieldFactory
    [157 tests, 2 failures, 1.40s wall]
----------------------------------------------------------------------
src/bin/sage -t --long --warn-long 30.0 --random-seed=123 src/sage/rings/finite_rings/finite_field_constructor.py  # 2 doctests failed
----------------------------------------------------------------------

@vincentmacri
vincentmacri marked this pull request as ready for review October 19, 2026 17:49
@vbraun
vbraun merged commit ab09d70 into sagemath:develop Oct 22, 2026
26 checks passed
starnotes-xj added a commit to starnotes-xj/sage that referenced this pull request Oct 29, 2026
The Lint job (ruff with --preview) flags the annotation-only
CategoryObject import, and PlusInfinity has become an unused import.
Enable module-level postponed annotations (per sagemathgh-42996, which enabled
them for ruff diagnostics), move CategoryObject into the TYPE_CHECKING
block, and drop the orphaned PlusInfinity import.  The probe still
executes cleanly.
starnotes-xj added a commit to starnotes-xj/sage that referenced this pull request Nov 10, 2026
The Lint job (ruff with --preview) flags the annotation-only
CategoryObject import, and PlusInfinity has become an unused import.
Enable module-level postponed annotations (per sagemathgh-42996, which enabled
them for ruff diagnostics), move CategoryObject into the TYPE_CHECKING
block, and drop the orphaned PlusInfinity import.  The probe still
executes cleanly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants