Best practice for using Sage with type hinting

39 views
Skip to first unread message

Michel VAN DEN BERGH

unread,
Apr 10, 2026, 2:07:53 AM (2 days ago) Apr 10
to sage-support
When I write a Sage script, I start with

from sage.all import A, B, C (whatever I need from Sage)

However when I type check that code with

~/sage/sage --python -m ty check  --extra-search-path ~/sage/src <scripts>

I get error messages

Module `sage.all` has no member A
Module `sage.all` has no member B
Module `sage.all` has no member C
etc...

and of course the type checking is useless after this.

I suppose sage.all is some kind of virtual module. Is there a way to make sure the type checker finds what it needs?


Dima Pasechnik

unread,
Apr 10, 2026, 1:05:21 PM (2 days ago) Apr 10
to sage-s...@googlegroups.com
Do you run "ty" on Python files (I guess it won't work on .sage files)

What if you replaced "sage.all" with whatever is printed by
"import_statements('A')", etc ?

Michel VAN DEN BERGH

unread,
Apr 10, 2026, 2:26:54 PM (2 days ago) Apr 10
to sage-support
I didn't know that command. 

I suppose it will work. I'll try it and report back.

Michel VAN DEN BERGH

unread,
5:42 AM (3 hours ago) 5:42 AM
to sage-support
Unfortunately "import_statements" does not seem to give enough information
for sage to work correctly.

E.g. using

from sage.combinat.root_system.weyl_group import WeylGroup

inside a script yields

  File "<..>/sage/src/sage/combinat/root_system/weyl_group.py", line 43, in <module>
    from sage.groups.matrix_gps.finitely_generated_gap import FinitelyGeneratedMatrixGroup_gap
  File "<..>/sage/src/sage/groups/matrix_gps/finitely_generated_gap.py", line 36, in <module>
    from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
  File "<..>/sage/src/sage/rings/polynomial/multi_polynomial_sequence.py", line 173, in <module>
    from sage.rings.polynomial.plural import NCPolynomialRing_plural
  File "sage/rings/polynomial/plural.pyx", line 1, in init sage.rings.polynomial.plural
  File "sage/rings/polynomial/multi_polynomial_libsingular.pyx", line 1, in init sage.rings.polynomial.multi_polynomial_libsingular
  File "sage/libs/singular/function.pyx", line 95, in init sage.libs.singular.function
ImportError: cannot import name PolynomialSequence_generic

It does work interactively so there must be some difference between invoking sage interactively and non interactively...

I assume a bunch of environment variables must be set correctly. Is there a good way to do this?
Reply all
Reply to author
Forward
0 new messages