Skip to content
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

sage.sets: Doctest cosmetics #37713

Merged
merged 2 commits into from
May 12, 2024

Conversation

mkoeppe
Copy link
Contributor

@mkoeppe mkoeppe commented Apr 1, 2024

Cherry-picked from #35095.

📝 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 accordingly.

⌛ Dependencies

@mantepse
Copy link
Collaborator

mantepse commented Apr 1, 2024

I am against replacing short lambda expressions with two line def in docstrings: they are a pain to copy into the repl.

Copy link

github-actions bot commented Apr 1, 2024

Documentation preview for this PR (built with commit 5ef67f5; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 1, 2024

I am against replacing short lambda expressions with two line def in docstrings: they are a pain to copy into the repl.

Are you referring to copying from the source code or from the formatted HTML documentation? Where exactly does it hurt?

@mkoeppe mkoeppe requested a review from fchapoton April 1, 2024 17:45
@mantepse
Copy link
Collaborator

mantepse commented Apr 1, 2024

I am against replacing short lambda expressions with two line def in docstrings: they are a pain to copy into the repl.

Are you referring to copying from the source code or from the formatted HTML documentation? Where exactly does it hurt?

Copying from source code. It does work, but it is a painful. For example, modifying does not work as well, and also emacs doesn't offer autocompletion for functions defined in this way.

Also, I don't see a good reason for the replacement. What is the purpose?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 1, 2024

What is the purpose?

Coding style. In library code, such lambda assignments are flagged by pycodestyle, and they have been replaced already. Best to use a consistent style also in code examples.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 1, 2024

Copying from source code.

You know that you can copy the whole lines including prompts, yes?

@mantepse
Copy link
Collaborator

mantepse commented Apr 1, 2024

What is the purpose?

Coding style. In library code, such lambda assignments are flagged by pycodestyle, and they have been replaced already. Best to use a consistent style also in code examples.

I would agree that in very many cases the assignment is unnecessary, and could simply be inlined.

Otherwise, you could simply use the one-line form of def:

def f(x): return 2*x 

works just fine.

Copying from source code.

You know that you can copy the whole lines including prompts, yes?

Is there an editor that would not let you copy full lines?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 1, 2024

We appear to be miscommunicating. What's the exact problem that you are facing when copying multi-line definitions?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 1, 2024

use the one-line form of def:

def f(x): return 2*x 

Codestyle linters also don't like that

@mantepse
Copy link
Collaborator

mantepse commented Apr 2, 2024

It is a bit hard to explain if you do not use emacs.

I can go to the first line of the test in the documentation buffer, and press C-d, to run the snippet in the attached sage session. It will look as follows:

sage: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:def rotate_permutation(p):
:    cycle = Permutation(tuple(range(1, len(p)+1)))
:    return Permutation([cycle.inverse()(p(cycle(i))) for i in range(1, len(p)+1)])
:--

If I do it this way (rather than copy-pasting), I at least get tab completion. However, if I now want to modify the definition slightly, it gets a bit cumbersome, at least for me.

I also find that the increased verbosity is another drawback.

I do see the point of using pycodestyle, but I would rather turn off that particular recommendation for doctests, or relax it to allow single line def statements.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 3, 2024

Is this sage-shell-mode?

@mantepse
Copy link
Collaborator

mantepse commented Apr 3, 2024

Yes

@mkoeppe mkoeppe force-pushed the sage_sets_doctest_cosmetics branch from 74aaf15 to 55a6b57 Compare April 27, 2024 17:32
@mkoeppe mkoeppe force-pushed the sage_sets_doctest_cosmetics branch from 55a6b57 to 5ef67f5 Compare May 8, 2024 05:19
@mkoeppe
Copy link
Contributor Author

mkoeppe commented May 8, 2024

I've reduced this PR to the subset of the changes that do not involve changing lambda assignments to defs.

Copy link
Collaborator

@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, thank you!

@mkoeppe
Copy link
Contributor Author

mkoeppe commented May 8, 2024

Thanks.

vbraun pushed a commit to vbraun/sage that referenced this pull request May 9, 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". -->

Cherry-picked from sagemath#35095.

### 📝 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 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#37713
Reported by: Matthias Köppe
Reviewer(s): Martin Rubey
vbraun pushed a commit to vbraun/sage that referenced this pull request May 11, 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". -->

Cherry-picked from sagemath#35095.

### 📝 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 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#37713
Reported by: Matthias Köppe
Reviewer(s): Martin Rubey
vbraun pushed a commit to vbraun/sage that referenced this pull request May 12, 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". -->

Cherry-picked from sagemath#35095.

### 📝 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 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#37713
Reported by: Matthias Köppe
Reviewer(s): Martin Rubey
@vbraun vbraun merged commit d32de45 into sagemath:develop May 12, 2024
16 checks passed
@mkoeppe mkoeppe added this to the sage-10.4 milestone May 12, 2024
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.

3 participants