-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meta-ticket: Replace is_Class
functions, create abstract base classes to enable modularization
#32414
Comments
comment:1
I find this in general bothering that there are tons of modules etc. being imported (even at startup), just because some
Apparently its a slow down of about 50 percent, when the import is found, otherwise much more.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:6
Thanks for these thoughts and experiments. I also prefer the approach using new base classes; and also I have learned more about the multiyear effort to get rid of |
This comment has been minimized.
This comment has been minimized.
Commit: |
Author: Matthias Koeppe, ... |
comment:12
For getting the docstring I have tried to make |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:14
I think I'll need some help from Cython experts here... |
comment:15
I think you're running into the fact that the Python special double underscore methods are handled in a special way. I don't know too much about how that's done, but that that is my recollection. |
comment:16
A different approach would be to keep the base class / constructor in |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Changed commit from |
Changed author from Matthias Koeppe, ... to none |
Changed branch from u/mkoeppe/replace_some_is_____functions_by_isinstance_with_new_base_classes_to_enable_modularization to none |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Introducing a module `sage.interfaces.abc` with abstract base classes for `isinstance` testing (see https://doc.sagemath.org/html/en/developer/packaging_sage_library.html #module-level-runtime-dependencies) Part of sagemath#32414 URL: https://trac.sagemath.org/34804 Reported by: mkoeppe Ticket author(s): Matthias Koeppe, Dima Pasechnik Reviewer(s): Dima Pasechnik
….*.all for namespace packages Using `./sage -fiximports` from #34945. Also remove trailing whitespace in the affected files. Part of Meta-ticket #32414 URL: https://trac.sagemath.org/34947 Reported by: mkoeppe Ticket author(s): Alex Chandler Reviewer(s): Travis Scrimshaw, Matthias Koeppe
…ce packages Using `./sage -fiximports` from #34945. Also remove trailing whitespace in the affected files. Part of Meta-ticket #32414 URL: https://trac.sagemath.org/34952 Reported by: mkoeppe Ticket author(s): Alex Chandler Reviewer(s): David Coudert
…l for namespace packages Using `./sage -fiximports` from #34945. Also remove trailing whitespace in the affected files. Part of Meta-ticket #32414 URL: https://trac.sagemath.org/34956 Reported by: mkoeppe Ticket author(s): Alex Chandler, Matthias Koeppe Reviewer(s): Travis Scrimshaw
… out from `.laurent_polynomial_ring` <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> ### 📚 Description We move the abstract base class `LaurentPolynomialRing_generic` to a separate module. This is for modularization purposes (meta-ticket #32414). We also deprecate the function `is_LaurentPolynomialRing` and replace the (few) uses by `isinstance`. <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [x] I have linked an issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35229 Reported by: Matthias Köppe Reviewer(s): Matthias Köppe, Travis Scrimshaw
<!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> ### 📚 Description The new ABC `sage.rings.polynomial.multi_polynomial_ring_base.BooleanPol ynomialRing_base` can be imported for `isinstance` tests, without a compile time dependency on `brial`. This is a step towards a modularized distribution **sagemath-brial**. Part of: - #32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [x] I have linked an issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35240 Reported by: Matthias Köppe Reviewer(s): François Bissey, Matthias Köppe
<!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> ### 📚 Description Part of - #32738 - #32414 <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [x] I have linked an issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35253 Reported by: Matthias Köppe Reviewer(s): Travis Scrimshaw
…ants to category <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> We move the methods `charpoly`, `det`, `fcp`, `trace` from `MatrixMorphism_abstract` to the `Homsets.Endset.ElementMethods` of the category `FiniteDimensionalModulesWithBasis`. Likewise, we move the method `minpoly` there from `FreeModuleMorphism`. This makes them also available to endomorphisms of `CombinatorialFreeModule`. We also deprecate the functions `is_MatrixMorphism`, `is_FreeModuleMorphism`, `is_VectorSpaceMorphism` (as part of sagemath#32414); they were almost unused. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] 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 accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#37731 Reported by: Matthias Köppe Reviewer(s): Matthias Köppe, Travis Scrimshaw
is_Class
functions, create abstract base classes to enable modularization
…_Divisor`, `is_ToricDivisor` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> - Part of sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#38277 Reported by: Matthias Köppe Reviewer(s): Travis Scrimshaw
<!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of: - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#38278 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
<!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of: - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [ ] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#38279 Reported by: Matthias Köppe Reviewer(s): Travis Scrimshaw
<!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> The current message is referring to a class that does not exist. - Part of sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#38286 Reported by: Matthias Köppe Reviewer(s): Travis Scrimshaw
<!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Unused in the Sage library. - Part of sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#38288 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
…nomialIdeal`, `is_MPolynomialRing`, `is_MPowerSeries`, `is_PolynomialQuotientRing`, `is_PolynomialRing`, `is_PolynomialSequence`, `is_PowerSeries`, `is_QuotientRing` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of: - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> - Depends on sagemath#38151 (merged here) URL: sagemath#38266 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
…nomialIdeal`, `is_MPolynomialRing`, `is_MPowerSeries`, `is_PolynomialQuotientRing`, `is_PolynomialRing`, `is_PolynomialSequence`, `is_PowerSeries`, `is_QuotientRing` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of: - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> - Depends on sagemath#38151 (merged here) URL: sagemath#38266 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
…nomialIdeal`, `is_MPolynomialRing`, `is_MPowerSeries`, `is_PolynomialQuotientRing`, `is_PolynomialRing`, `is_PolynomialSequence`, `is_PowerSeries`, `is_QuotientRing` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of: - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> - Depends on sagemath#38151 (merged here) URL: sagemath#38266 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
…eldElement` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of: - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#38289 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
…ing`, `is_PowerSeriesRing` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> - Depends on sagemath#38266 (merged here) URL: sagemath#38290 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
…nomialIdeal`, `is_MPolynomialRing`, `is_MPowerSeries`, `is_PolynomialQuotientRing`, `is_PolynomialRing`, `is_PolynomialSequence`, `is_PowerSeries`, `is_QuotientRing` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of: - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> - Depends on sagemath#38151 (merged here) URL: sagemath#38266 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
…eldElement` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of: - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#38289 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
…ing`, `is_PowerSeriesRing` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> - Depends on sagemath#38266 (merged here) URL: sagemath#38290 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
…lPoint` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of: - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#38296 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
…lPoint` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Part of: - sagemath#32414 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [x] 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 <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#38296 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee
git grep 'import.* is_[A-Z]'
(orgit 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
aroundimport
, 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/orsage.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
defines base classRealDoubleField
forsage.rings.real_double.RealDoubleField_class
etc.sage.structure.element
, a classExpression
sage.symbolic.expression.Expression
will be its only subclassis_Expression
,is_SymbolicEquation
,is_CallableSymbolicExpression
,is_SymbolicVariable
; replace uses byisinstance(x, Expression)
and a method call (may need a new methodis_callable
)sage.geometry.abc
, a classPolyhedron
Polyhedron_base
will be its only direct subclassTechnical limitation: If a
sage.PAC.KAGE.abc
module is intended to provide the new classes, thensage.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 ofisinstance
for uniformity of the codebase:sage.modular.hecke
: Deprecateis_Hecke...
functions #37895is_FreeAlgebra
,is_QuaternionAlgebra
,is_SymmetricFunctionAlgebra
#37896is_Monoid
,is_FreeMonoid
,is_FreeAbelianMonoid
#37897is_AbelianGroup
,is_DualAbelianGroup
,is_MatrixGroup
#37898is_Category
,is_Endset
,is_Homset
,is_Parent
,is_RingHomset
,is_SimplicialComplexHomset
#37922is_FGP_Module
,is_FilteredVectorSpace
,is_FreeQuadraticModule
,is_FreeModule
,is_FreeModuleHomspace
,is_MatrixSpace
,is_Module
,is_VectorSpace
,is_VectorSpaceHomspace
#37924sage.schemes
: Deprecateis_...
functions #38022sage.combinat.finite_state_machine
: Deprecateis_...
functions #38032sage.modular
: Deprecateis_...
functions #38035is_Element
, ... #38077is_Map
,is_...Morphism
#38103is_NumberFieldOrder
,is_AbsoluteNumberField
,is_RelativeNumberField
,is_NumberFieldIdeal
,is_NumberFieldFractionalIdeal
,is_NumberFieldFractionalIdeal_rel
#38124is_MutablePoset
#38125is_Fan
,is_NefPartition
,is_PointCollection
,is_ToricLattice
,is_ToricLatticeElement
,is_ToricLatticeQuotient
#38126is_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
#38128is_FreeAlgebraQuotientElement
, ... #38184is_Ideal
,is_LaurentSeries
,is_MPolynomialIdeal
,is_MPolynomialRing
,is_MPowerSeries
,is_PolynomialQuotientRing
,is_PolynomialRing
,is_PolynomialSequence
,is_PowerSeries
,is_QuotientRing
#38266Functions that look like
is_Class
:is_GlobalGenus
,Genus_Symbol_p_adic_ring
#38287is_NumberFieldHomsetCodomain
#38297Related:
QuaternionAlgebra
: Unify ABC and factory #38228FreeAlgebra
: Unify ABC and factory #38240Part of:
CC: @tscrim @fchapoton @kliem
Component: refactoring
Issue created by migration from https://trac.sagemath.org/ticket/32414
The text was updated successfully, but these errors were encountered: