Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5d3cbf3
Add type hints for `rings.infinity`
tobiasdiez Feb 6, 2025
023d630
Remove conditional imports in cython files
tobiasdiez Feb 11, 2025
6edecf9
Merge remote-tracking branch 'upstream/develop' into typing-infinity
tobiasdiez Feb 11, 2025
e5fb98d
Merge remote-tracking branch 'upstream/develop' into typing-infinity
tobiasdiez Mar 7, 2025
06740db
Fix typo
tobiasdiez Mar 7, 2025
9f04297
Fix linter
tobiasdiez Mar 7, 2025
cd22e43
More linter fixes
tobiasdiez Mar 7, 2025
01a65cb
Add future annotations imports
tobiasdiez Mar 8, 2025
d25f43a
Add test file to meson
tobiasdiez Mar 8, 2025
dd98025
Add '2' as option for coerced input
tobiasdiez Mar 8, 2025
a9dfe63
Merge remote-tracking branch 'upstream/develop' into typing-infinity
tobiasdiez Mar 13, 2025
1b980af
Merge branch 'develop' into typing-infinity
tobiasdiez Mar 23, 2025
77aad98
Merge branch 'develop' into typing-infinity
tobiasdiez Apr 15, 2025
7ea6887
Merge remote-tracking branch 'upstream/develop' into typing-infinity
tobiasdiez May 13, 2025
3a3e885
Merge branch 'develop' into typing-infinity
tobiasdiez Jun 4, 2025
f1c8354
Merge branch 'develop' into typing-infinity
tobiasdiez Jun 15, 2025
02b85e8
Merge branch 'develop' into typing-infinity
tobiasdiez Jun 26, 2025
2e8d8d0
Merge remote-tracking branch 'upstream/develop' into typing-infinity
tobiasdiez Jul 8, 2025
01f1d8d
Remove duplicate test functions
tobiasdiez Jul 8, 2025
fcf9967
Merge branch 'develop' into typing-infinity
tobiasdiez Jul 26, 2025
b0d02f2
Merge branch 'develop' into typing-infinity
tobiasdiez Aug 2, 2025
537c32e
Merge branch 'develop' into typing-infinity
tobiasdiez Aug 29, 2025
f9be16d
Fix tests
tobiasdiez Aug 30, 2025
e1a1704
Merge remote-tracking branch 'upstream/develop' into typing-infinity
tobiasdiez Sep 19, 2025
8583ece
Merge branch 'develop' into typing-infinity
tobiasdiez Sep 22, 2025
6fd02d3
Fix imports
tobiasdiez Sep 24, 2025
d459eeb
Add type hints for rings.infinity and migrate tests to pytest
tobiasdiez Sep 28, 2025
d1704cb
Merge branch 'develop' into typing-infinity
tobiasdiez Oct 7, 2025
2a98386
Merge branch 'develop' into typing-infinity
tobiasdiez Oct 17, 2025
719d6a9
Merge branch 'develop' into typing-infinity
tobiasdiez Oct 28, 2025
4c8181b
Merge branch 'develop' into typing-infinity
tobiasdiez Dec 18, 2025
cb34b4c
Merge branch 'develop' into typing-infinity
tobiasdiez Dec 29, 2025
c7fa944
Merge branch 'typing-infinity' of https://github.com/tobiasdiez/sage …
tobiasdiez Jan 15, 2026
19dd450
Merge remote-tracking branch 'origin/develop' into typing-infinity
tobiasdiez Jan 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/sage/geometry/cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import annotations

from collections.abc import Hashable, Iterable, Container
from copy import copy
from typing import TYPE_CHECKING, Literal
from warnings import warn

from sage.misc.lazy_import import lazy_import
Expand Down Expand Up @@ -241,6 +243,9 @@
lazy_import('ppl', ['ray', 'point'], as_=['PPL_ray', 'PPL_point'],
feature=PythonModule("ppl", spkg='pplpy', type='standard'))

if TYPE_CHECKING:
from sage.misc.sage_input import SageInputBuilder, SageInputExpression


def Cone(rays, lattice=None, check=True, normalize=True):
r"""
Expand Down Expand Up @@ -1481,7 +1486,7 @@ def __init__(self, rays=None, lattice=None,
if PPL is not None:
self._PPL_C_Polyhedron = PPL

def _sage_input_(self, sib, coerced):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
"""
Return Sage command to reconstruct ``self``.

Expand Down
7 changes: 6 additions & 1 deletion src/sage/geometry/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,11 @@
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import annotations

from collections.abc import Callable, Container
from copy import copy
from typing import TYPE_CHECKING, Literal
from warnings import warn

import sage.geometry.abc
Expand All @@ -262,6 +264,9 @@
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ

if TYPE_CHECKING:
from sage.misc.sage_input import SageInputBuilder, SageInputExpression


def Fan(cones, rays=None, lattice=None, check=True, normalize=True,
is_complete=None, virtual_rays=None, discard_faces=False,
Expand Down Expand Up @@ -1187,7 +1192,7 @@ def __init__(self, cones, rays, lattice,
if virtual_rays is not None:
self._virtual_rays = PointCollection(virtual_rays, self.lattice())

def _sage_input_(self, sib, coerced):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
"""
Return Sage command to reconstruct ``self``.

Expand Down
59 changes: 44 additions & 15 deletions src/sage/geometry/lattice_polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,42 +120,43 @@
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import annotations

import os
import shlex
from collections.abc import Hashable
from copyreg import constructor as copyreg_constructor
from functools import reduce
from io import IOBase, StringIO
from subprocess import Popen, PIPE
from warnings import warn
import os
import shlex
from subprocess import PIPE, Popen
from typing import Literal

import sage.geometry.abc
from sage.arith.misc import GCD as gcd
from sage.categories.monoids import Monoids
from sage.features import PythonModule
from sage.features.palp import PalpExecutable
from sage.features.databases import DatabaseReflexivePolytopes
from sage.features.palp import PalpExecutable
from sage.geometry.cone import _ambient_space_point, integral_length
from sage.geometry.point_collection import (PointCollection,
read_palp_point_collection)
from sage.geometry.toric_lattice import ToricLattice, ToricLattice_generic
from sage.geometry.convex_set import ConvexSet_compact
from sage.geometry.point_collection import PointCollection, read_palp_point_collection
from sage.geometry.toric_lattice import ToricLattice, ToricLattice_generic
from sage.matrix.constructor import matrix
from sage.misc.cachefunc import cached_method
from sage.misc.flatten import flatten
from sage.misc.lazy_import import lazy_import
from sage.misc.sage_input import SageInputBuilder, SageInputExpression

Check failure on line 148 in src/sage/geometry/lattice_polytope.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (TC001)

src/sage/geometry/lattice_polytope.py:148:52: TC001 Move application import `sage.misc.sage_input.SageInputExpression` into a type-checking block

Check failure on line 148 in src/sage/geometry/lattice_polytope.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (TC001)

src/sage/geometry/lattice_polytope.py:148:34: TC001 Move application import `sage.misc.sage_input.SageInputBuilder` into a type-checking block
from sage.misc.temporary_file import tmp_filename
from sage.modules.free_module_element import vector
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.structure.element import Matrix, Element
from sage.structure.richcmp import richcmp_method, richcmp
from sage.structure.parent import Parent
from sage.structure.element import Element, Matrix
from sage.structure.parent import Parent, Set_generic
from sage.structure.richcmp import richcmp, richcmp_method
from sage.structure.sage_object import SageObject
from sage.structure.sequence import Sequence
from sage.structure.unique_representation import UniqueRepresentation
import sage.geometry.abc


lazy_import("sage.combinat.posets.posets", 'FinitePoset')
lazy_import("sage.geometry.hasse_diagram", 'lattice_from_incidences')
Expand All @@ -170,6 +171,34 @@
feature=PythonModule("ppl", spkg='pplpy', type='standard'))


class SetOfAllLatticePolytopesClass(Set_generic):
def _repr_(self) -> str:
r"""
Return a string representation.

TESTS::

sage: lattice_polytope.SetOfAllLatticePolytopesClass()._repr_()
'Set of all Lattice Polytopes'
"""
return "Set of all Lattice Polytopes"

def __call__(self, x):
r"""
TESTS::

sage: o = lattice_polytope.cross_polytope(3)
sage: lattice_polytope.SetOfAllLatticePolytopesClass().__call__(o)
3-d reflexive polytope in 3-d lattice M
"""
if isinstance(x, LatticePolytopeClass):
return x
raise TypeError


SetOfAllLatticePolytopes = SetOfAllLatticePolytopesClass()


def LatticePolytope(data, compute_vertices=True, n=0, lattice=None):
r"""
Construct a lattice polytope.
Expand Down Expand Up @@ -517,7 +546,7 @@
self._vertices = ambient.vertices(self._ambient_vertex_indices)
Element.__init__(self, parent)

def _sage_input_(self, sib, coerced):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
"""
Return Sage command to reconstruct ``self``.

Expand Down Expand Up @@ -4469,7 +4498,7 @@
pass
return result

def _sage_input_(self, sib, coerced):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool) -> SageInputExpression:
"""
Return Sage command to reconstruct ``self``.

Expand Down
4 changes: 3 additions & 1 deletion src/sage/geometry/point_collection.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ from sage.geometry.toric_lattice import ToricLattice
from sage.matrix.constructor import matrix
from sage.misc.latex import latex

from sage.misc.sage_input import SageInputBuilder, SageInputExpression


def is_PointCollection(x):
r"""
Expand Down Expand Up @@ -172,7 +174,7 @@ cdef class PointCollection(SageObject):
self._points = tuple(points)
self._module = self._points[0].parent() if module is None else module

def _sage_input_(self, sib, coerced):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
r"""
Return Sage command to reconstruct ``self``.

Expand Down
7 changes: 6 additions & 1 deletion src/sage/geometry/polyhedron/base0.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import annotations

from typing import TYPE_CHECKING, Literal
from sage.misc.cachefunc import cached_method
from sage.misc.abstract_method import abstract_method
from sage.structure.element import Element
import sage.geometry.abc

if TYPE_CHECKING:
from sage.misc.sage_input import SageInputBuilder, SageInputExpression


class Polyhedron_base0(Element, sage.geometry.abc.Polyhedron):
"""
Expand Down Expand Up @@ -296,7 +301,7 @@ def _delete(self):
"""
self.parent().recycle(self)

def _sage_input_(self, sib, coerced):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
"""
Return Sage command to reconstruct ``self``.

Expand Down
7 changes: 6 additions & 1 deletion src/sage/geometry/toric_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@
#
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import annotations

from typing import TYPE_CHECKING, Literal
from sage.geometry.toric_lattice_element import ToricLatticeElement
from sage.misc.lazy_import import lazy_import
lazy_import('sage.geometry.toric_plotter', 'ToricPlotter')
Expand All @@ -162,6 +164,9 @@
from sage.rings.rational_field import QQ
from sage.structure.factory import UniqueFactory

if TYPE_CHECKING:
from sage.misc.sage_input import SageInputBuilder, SageInputExpression


class ToricLatticeFactory(UniqueFactory):
r"""
Expand Down Expand Up @@ -825,7 +830,7 @@ def __init__(self, rank, name, dual_name, latex_name, latex_dual_name):
self._latex_name = latex_name
self._latex_dual_name = latex_dual_name

def _sage_input_(self, sib, coerced):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
r"""
Return Sage command to reconstruct ``self``.

Expand Down
3 changes: 2 additions & 1 deletion src/sage/matrix/matrix1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ from cpython.sequence cimport PySequence_Fast
import sage.modules.free_module
from sage.structure.coerce cimport coercion_model

from sage.misc.sage_input import SageInputBuilder, SageInputExpression

cdef class Matrix(Matrix0):
###################################################
Expand Down Expand Up @@ -622,7 +623,7 @@ cdef class Matrix(Matrix0):
matrix._sage_object = self
return matrix

def _sage_input_(self, sib, coerce):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
r"""
Produce an expression which will reproduce this value when evaluated.

Expand Down
8 changes: 6 additions & 2 deletions src/sage/misc/explain_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@
# (at your option) any later version.
# http://www.gnu.org/licenses/
# *****************************************************************************

from __future__ import annotations

import pickletools
import re
import sys
import types

from typing import TYPE_CHECKING, Literal
import zlib as comp
import bz2 as comp_other

Expand All @@ -169,6 +170,9 @@
from sage.misc.persist import (unpickle_override, unpickle_global, dumps,
register_unpickle_override, SageUnpickler)

if TYPE_CHECKING:
from sage.misc.sage_input import SageInputBuilder, SageInputExpression

Check failure on line 174 in src/sage/misc/explain_pickle.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (TC004)

src/sage/misc/explain_pickle.py:174:56: TC004 Move import `sage.misc.sage_input.SageInputExpression` out of type-checking block. Import is used for more than type hinting.

Check failure on line 174 in src/sage/misc/explain_pickle.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (TC004)

src/sage/misc/explain_pickle.py:174:38: TC004 Move import `sage.misc.sage_input.SageInputBuilder` out of type-checking block. Import is used for more than type hinting.


# Python 3 does not have a "ClassType". Instead, we ensure that
# isinstance(foo, ClassType) will always return False.
Expand Down Expand Up @@ -358,7 +362,7 @@
self.expression = expression
self.immutable = False

def _sage_input_(self, sib, coerced):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
r"""
Extracts the expression from a PickleObject, and sets the immutable
flag.
Expand Down
8 changes: 6 additions & 2 deletions src/sage/misc/sage_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

from __future__ import annotations
from typing import Literal

from sage.misc.lazy_import import lazy_import

lazy_import('sage.rings.real_mpfi', 'RealIntervalFieldElement')
Expand Down Expand Up @@ -342,7 +345,7 @@ def __init__(self, allow_locals=False, preparse=True):
self._next_local = 1
self._locals = {}

def __call__(self, x, coerced=False):
def __call__(self, x, coerced: bool | Literal[2] = False):
r"""
Try to convert an arbitrary value ``x`` into a
:class:`SageInputExpression` (an SIE).
Expand Down Expand Up @@ -460,6 +463,7 @@ def __call__(self, x, coerced=False):
return x

if hasattr(x, '_sage_input_'):
#print(coerced, type(coerced))
return x._sage_input_(self, coerced)

if x is None:
Expand Down Expand Up @@ -592,7 +596,7 @@ def float_str(self, n):
"""
return SIE_literal_stringrep(self, n)

def name(self, n):
def name(self, n) -> SageInputExpression:
r"""
Given a string representing a Python name,
produces a :class:`SageInputExpression` for that name.
Expand Down
3 changes: 2 additions & 1 deletion src/sage/modules/free_module_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ from sage.rings.abc import RealDoubleField, ComplexDoubleField

from sage.rings.integer cimport Integer, smallInteger
from sage.arith.numerical_approx cimport digits_to_bits
from sage.misc.sage_input import SageInputBuilder, SageInputExpression

# For the norm function, we cache Sage integers 1 and 2
__one__ = smallInteger(1)
Expand Down Expand Up @@ -1259,7 +1260,7 @@ cdef class FreeModuleElement(Vector): # abstract base class
return self
return self.change_ring(R)

def _sage_input_(self, sib, coerce):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
r"""
Produce an expression which will reproduce this value when evaluated.

Expand Down
3 changes: 2 additions & 1 deletion src/sage/rings/complex_interval.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ from sage.libs.flint.fmpz cimport *
from sage.libs.mpfr cimport MPFR_RNDU
from sage.arith.constants cimport LOG_TEN_TWO_PLUS_EPSILON

from sage.misc.sage_input import SageInputBuilder, SageInputExpression
from sage.structure.element cimport FieldElement
from sage.structure.parent cimport Parent
from sage.rings.complex_mpfr cimport ComplexNumber
Expand Down Expand Up @@ -1002,7 +1003,7 @@ cdef class ComplexIntervalFieldElement(FieldElement):
"""
raise TypeError

def _sage_input_(self, sib, coerce):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
r"""
Produce an expression which will reproduce this value when evaluated.

Expand Down
8 changes: 6 additions & 2 deletions src/sage/rings/complex_interval_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import annotations


from typing import TYPE_CHECKING, Literal
import weakref

import sage.rings.abc
Expand All @@ -48,6 +49,9 @@
from sage.rings.ring import Field
from sage.structure.parent import Parent

if TYPE_CHECKING:
from sage.misc.sage_input import SageInputBuilder, SageInputExpression

cache = {}


Expand Down Expand Up @@ -295,7 +299,7 @@ def _magma_init_(self, magma):
"""
return "ComplexField(%s : Bits := true)" % self.prec()

def _sage_input_(self, sib, coerce):
def _sage_input_(self, sib: SageInputBuilder, coerced: bool | Literal[2]) -> SageInputExpression:
r"""
Produce an expression which will reproduce this value when evaluated.

Expand Down
Loading
Loading