Best practice for using Sage with type hinting

71 views
Skip to first unread message

Michel VAN DEN BERGH

unread,
Apr 10, 2026, 2:07:53 AMApr 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 PMApr 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 PMApr 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,
Apr 12, 2026, 5:42:20 AMApr 12
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?

Dima Pasechnik

unread,
Apr 13, 2026, 11:14:26 AMApr 13
to sage-s...@googlegroups.com
On Sun, Apr 12, 2026 at 4:42 AM 'Michel VAN DEN BERGH' via sage-support <sage-s...@googlegroups.com> wrote:
Unfortunately "import_statements" does not seem to give enough information
for sage to work correctly.

usually it does, but in this particular case one apparently needs

from sage.rings.polynomial.plural import NCPolynomialRing_plural
from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence_generic
# now the following works 
from sage.combinat.root_system.weyl_group import WeylGroup


 
--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sage-support/b5a15df6-17da-419f-bcc4-ad098845723cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages