Skip to content

Conversation

@grhkm21
Copy link
Contributor

@grhkm21 grhkm21 commented Jun 13, 2024

Class names should be *_generic, and indeed is the case for at least 140 classes, but PolynomialRing is incorrectly suffixed with _general. This PR fixes this problem.

📝 Checklist

  • 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.

@grhkm21
Copy link
Contributor Author

grhkm21 commented Jun 13, 2024

A note for future me and others: Most LSPs support renaming a symbol across an entire project. I use coc.nvim so just use coc-rename to all the names across Sage. (It doesn't detect comments though :( )

@mkoeppe
Copy link
Contributor

mkoeppe commented Jun 13, 2024

In a somewhat different direction, we may want to look into merging constructor functions such as PolynomialRing and the "generic" classes via classcall.

@tscrim
Copy link
Collaborator

tscrim commented Jun 13, 2024

Normally I would completely agree with @mkoeppe about having the PolynomialRing constructor go through an ABC. However, in this case, I am quite apprehensive about it as this constructor is fairly complex, as well as currently the univariate and multivariate classes that are essentially separate:

sage: R.<x,y> = QQ[]
sage: R.__class__.__mro__
(<class 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular'>,
 <class 'sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base'>,
 <class 'sage.rings.ring.CommutativeRing'>,
 <class 'sage.rings.ring.Ring'>,
 <class 'sage.structure.parent_gens.ParentWithGens'>,
 <class 'sage.structure.parent_base.ParentWithBase'>,
 <class 'sage.structure.parent_old.Parent'>,
 <class 'sage.structure.parent.Parent'>,
 <class 'sage.structure.category_object.CategoryObject'>,
 <class 'sage.structure.sage_object.SageObject'>,
 <class 'object'>)

(which doesn't even use the category framework properly too!).

@grhkm21 Just do a grep -r SAGE_ROOT/src/sage/* (possibly set to ignore generated .c files) :)

@grhkm21
Copy link
Contributor Author

grhkm21 commented Jun 13, 2024

@grhkm21 Just do a grep -r SAGE_ROOT/src/sage/* (possibly set to ignore generated .c files) :)

Yeah that finds the appearance of the class, but the LSP method I mentioned renames the class + all references to it (including imports etc). Plus if there's hundreds of references, say I want to rename Ring to Rang or something, then grep will be very inaccurate, since e.g. PolynomialRing will include the word Ring. But LSP (Language + Syntax Protocol) has the context to deduce which Ring is the Ring I'm trying to rename :D

@grhkm21
Copy link
Contributor Author

grhkm21 commented Jun 13, 2024

Re category: yes, a lot of things are not in the category framework. I plan to work on that whenever I have time during the summer. e.g. by replacing some isinstance(x, some ring base) or is_ring(x) by x in Rings() (locally, not PRing them), then fixing doctests. That worked once already (#37768) so it should be a good approach.

Re constructor/classcall thing: yes in this case I don't think it's feasible.

@mkoeppe
Copy link
Contributor

mkoeppe commented Jun 16, 2024

In a somewhat different direction, we may want to look into merging constructor functions such as PolynomialRing and the "generic" classes via classcall.

I've sketched this in #38228 (for a different class)

@mkoeppe
Copy link
Contributor

mkoeppe commented Jun 19, 2024

In light of the discussion in

... we should probably also discuss a possible direction to defining suitable abstract base classes without underscores in names.

One data point: For the elements, we have introduced an ABC CommutativePolynomial.

Should we define an ABC CommutativePolynomialRing? (But would InfinitePolynomialRing be a subclass?)

@grhkm21
Copy link
Contributor Author

grhkm21 commented Dec 2, 2024

@tscrim @kwankyu Hello, I want this PR to go through soon. IIRC both of you were fine with the current deprecation solution? Do you still think so? If both of you are okay let's just mark this as positive review and remove the deprecation warning soon. Or if you two agree we can even remove the deprecation warning now, and just rename this somewhat internal base class

@kwankyu
Copy link
Collaborator

kwankyu commented Dec 3, 2024

According to the updated rules in https://doc-release--sagemath.netlify.app/html/en/developer/coding_in_python.html#deprecation, we should first decide if PolynomialRing_general is a public class or an internal class.

I think it is internal.

@tscrim
Copy link
Collaborator

tscrim commented Dec 3, 2024

It's in our public documentation and should not be treated as internal. Moreover, it is also such an important class that we can reasonably expect people to have imported it in their local code. Hence, it should be subject to our usual deprecation policy.

I also don't really see the point/benefit of doing this...

@kwankyu
Copy link
Collaborator

kwankyu commented Dec 3, 2024

OK. Then it should be treated as a public class. The deprecation policy should be followed.

Otherwise I am positive to the PR.

@grhkm21
Copy link
Contributor Author

grhkm21 commented Dec 3, 2024

So according to the deprecation developer guideline, I should remove the

# Placeholder class for deprecation
class PolynomialRing_general(PolynomialRing_generic):
...

placeholder, and just do

class NewClass:
    ...

OldClass = NewClass   # OldClass is deprecated. See Issue 12345.

, correct? I assume I can remove it after a year as well (adds to calendar)

vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 6, 2024
<!-- ^ 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". -->

Fixes a typo in the developer guide, noted in
sagemath#38207 (comment).

### 📝 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#39074
Reported by: Kwankyu Lee
Reviewer(s): Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 8, 2024
sagemathgh-39074: Fix the issue number format in deprecation comment
    
<!-- ^ 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". -->

Fixes a typo in the developer guide, noted in
sagemath#38207 (comment).

### 📝 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#39074
Reported by: Kwankyu Lee
Reviewer(s): Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 8, 2024
sagemathgh-39074: Fix the issue number format in deprecation comment
    
<!-- ^ 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". -->

Fixes a typo in the developer guide, noted in
sagemath#38207 (comment).

### 📝 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#39074
Reported by: Kwankyu Lee
Reviewer(s): Frédéric Chapoton
vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 15, 2024
sagemathgh-38207: Rename PolynomialRing_general to PolynomialRing_generic
    
Class names should be *_generic, and indeed is the case for at least 140
classes, but PolynomialRing is incorrectly suffixed with _general. This
PR fixes this problem.

### 📝 Checklist

- [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.
- [X] I have created tests covering the changes.
- [X] I have updated the documentation and checked the documentation
preview.
    
URL: sagemath#38207
Reported by: grhkm21
Reviewer(s): grhkm21, Kwankyu Lee, Matthias Köppe, Travis Scrimshaw
Copy link
Contributor

@mantepse mantepse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mantepse
Copy link
Contributor

Since we changed isinstance(x, ...) or isinstance(x, ...) to isinstance(x, (..., ...)) in the last beta (I think), I guess it makes sense to follow that spirit here.

Replace `isinstance(X, A) or isinstance(X, B)` with `isinstance(X, (A, B))`

Co-authored-by: Martin Rubey <[email protected]>
@grhkm21
Copy link
Contributor Author

grhkm21 commented Dec 16, 2024

Thank you! I have applied the changes :)

Copy link
Contributor

@mantepse mantepse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent, thank you!

@tscrim tscrim removed the v: small label Dec 18, 2024
vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 19, 2024
sagemathgh-38207: Rename PolynomialRing_general to PolynomialRing_generic
    
Class names should be *_generic, and indeed is the case for at least 140
classes, but PolynomialRing is incorrectly suffixed with _general. This
PR fixes this problem.

### 📝 Checklist

- [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.
- [X] I have created tests covering the changes.
- [X] I have updated the documentation and checked the documentation
preview.
    
URL: sagemath#38207
Reported by: grhkm21
Reviewer(s): grhkm21, Kwankyu Lee, Martin Rubey, Matthias Köppe, Travis Scrimshaw
@vbraun vbraun merged commit 65770e4 into sagemath:develop Dec 22, 2024
20 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants