-
-
Notifications
You must be signed in to change notification settings - Fork 655
Description
git grep 'import.* is_[A-Z]'
(or git grep 'import.*is_[A-Z]' | grep -E -v 'is_(Ring|Matrix)[^A-Z]' | grep -v 'sage:'
) reveals a common pattern in our code: We import a module just to check whether a user-provided object belongs to a class defined by that module.
This pattern is an obstacle to modularization.
The ongoing effort (#12824, https://groups.google.com/g/sage-devel/c/wEzb0awmyN0, #13370, #14329, #15076, #15098, #15333, #18173, #24443, #24525, #27593, #28470, #32347) to replace this pattern by importing the class and isinstance
does not help in this regard by itself:
The module providing the class must be installed so that the import does not fail.
This can of course be worked around by try... except
around import
, as done for example in #32455, but we should avoid cluttering the code with this type of workaround.
Instead we propose to create stub classes (abstract base classes) in sage.structure.element
, sage.structure.parent
, and/or sage.PAC.KAGE.abc
, and make the actual implementation classes subclasses (mostly, unique direct subclasses). This pattern already exists in the Sage code for a few existing classes:
sage.structure.element
defines a base classMatrix
(for purposes of the coercion system) and a functionis_Matrix
(see deprecate some is_*** functions #32347)sage.structure.parent
defines a base classSet_generic
; using it withisinstance
has replaced use of the earlieris_Set
function (Replace is_Set() usage #24443, remove deprecated is_Set #28470)
We add the following new classes:
- sage.rings.abc #32566/Deprecate is_RealField, is_ComplexField, is_RealDoubleField, is_ComplexDoubleField #32610/sage.rings.abc.{Real,Complex}{Interval,Ball}Field; deprecate is_{Real,Complex}IntervalField #32612:
sage.rings.abc
defines base classRealDoubleField
forsage.rings.real_double.RealDoubleField_class
etc. - Replace is_IntegerModRing by isinstance with new class sage.rings.abc.IntegerModRing #32606
- Add sage.rings.abc.{AlgebraicField,...,NumberField_quadratic}, deprecate is_AlgebraicField, ..., is_CyclotomicField, is_QuadraticField #32660
- sage.rings.abc: Add pAdicRing, pAdicField; deprecate is_pAdic... #32750
- sage.structure.element: Add abc Expression; deprecate is_Expression etc. #32638/Deprecate is_[Callable]SymbolicExpressionRing, remove use of is_Symbolic{Equation,Variable}, is_CallableSymbolicExpression #32665: in
sage.structure.element
, a classExpression
- the existing class
sage.symbolic.expression.Expression
will be its only subclass - deprecate
is_Expression
,is_SymbolicEquation
,is_CallableSymbolicExpression
,is_SymbolicVariable
; replace uses byisinstance(x, Expression)
and a method call (may need a new methodis_callable
)
- the existing class
- Add sage.geometry.abc; remove uses of is_Polyhedron, is_LatticePolytope, is_Cone outside of sage.geometry #32637: in
sage.geometry.abc
, a classPolyhedron
Polyhedron_base
will be its only direct subclass
- Add ABCs CommutativePolynomial, MPolynomial_libsingular, InfinitePolynomial; deprecate is_Polynomial, is_MPolynomial #32709
- Deprecate sage.interfaces is_...Element functions #34804
- Deprecate is_FiniteField etc., make sage.rings.finite_rings a namespace package #32664
- New ABC sage.structure.element.NumberFieldElement, deprecate is_NumberFieldElement #34931
- deprecate is_RealNumber, is_AlgebraicNumber, is_RealIntervalFieldElement, ... #24525
Technical limitation: If a sage.PAC.KAGE.abc
module is intended to provide the new classes, then sage.PAC.KAGE
must be prepared to become a native namespace package. (See Meta-ticket #32501: Clear out __init__.py
files in preparation for namespace packages)
As of this ticket, each of the new abstract base classes is intended to have a unique direct implementation subclass. #32637 adds doctests to document and enforce this design. Attempting to define new hierarchies of abstract base classes is beyond the scope of this ticket. Also, the new classes do not define any methods.
Tickets not needed for modularization, but removing is_
functions in favor of isinstance
for uniformity of the codebase:
- Deprecate is_Algebra, is_CommutativeAlgebra, is_FreeAlgebra, is_QuaternionAlgebra, is_SymmetricFunctionAlgebra #32738
- Deprecate is_Polyhedron, is_Cone, is_LatticePolytope #34307
sage.modular.hecke
: Deprecateis_Hecke...
functions #37895- Deprecate
is_FreeAlgebra
,is_QuaternionAlgebra
,is_SymmetricFunctionAlgebra
#37896 - Deprecate
is_Monoid
,is_FreeMonoid
,is_FreeAbelianMonoid
#37897 - Deprecate
is_AbelianGroup
,is_DualAbelianGroup
,is_MatrixGroup
#37898 - Deprecate
is_Category
,is_Endset
,is_Homset
,is_Parent
,is_RingHomset
,is_SimplicialComplexHomset
#37922 - Deprecate
is_FGP_Module
,is_FilteredVectorSpace
,is_FreeQuadraticModule
,is_FreeModule
,is_FreeModuleHomspace
,is_MatrixSpace
,is_Module
,is_VectorSpace
,is_VectorSpaceHomspace
#37924 sage.schemes
: Deprecateis_...
functions #38022sage.combinat.finite_state_machine
: Deprecateis_...
functions #38032sage.modular
: Deprecateis_...
functions #38035- Deprecate
is_Element
, ... #38077 - Deprecate
is_Map
,is_...Morphism
#38103 - Deprecate
is_NumberFieldOrder
,is_AbsoluteNumberField
,is_RelativeNumberField
,is_NumberFieldIdeal
,is_NumberFieldFractionalIdeal
,is_NumberFieldFractionalIdeal_rel
#38124 - Deprecate
is_MutablePoset
#38125 - Deprecate
is_Fan
,is_NefPartition
,is_PointCollection
,is_ToricLattice
,is_ToricLatticeElement
,is_ToricLatticeQuotient
#38126 - Deprecate
is_AlgebraicNumber
,is_AlgebraicReal
,is_ComplexDoubleElement
,is_ComplexIntervalFieldElement
,is_ComplexNumber
,is_FractionField
,is_FractionFieldElement
,is_Integer
,is_IntegerMod
,is_IntegerRing
,is_Rational
,is_RationalField
,is_RealDoubleElement
,is_RealIntervalField
,is_RealIntervalFieldElement
,is_RealNumber
#38128 - Deprecate
is_FreeAlgebraQuotientElement
, ... #38184 - Deprecate
is_Ideal
,is_LaurentSeries
,is_MPolynomialIdeal
,is_MPolynomialRing
,is_MPowerSeries
,is_PolynomialQuotientRing
,is_PolynomialRing
,is_PolynomialSequence
,is_PowerSeries
,is_QuotientRing
#38266 - to be done: see https://groups.google.com/g/sage-devel/c/6MJHDicPYWs/m/RBxTi4TGAwAJ
Functions that look like is_Class
:
Related:
Part of:
CC: @tscrim @fchapoton @kliem
Component: refactoring
Issue created by migration from https://trac.sagemath.org/ticket/32414