Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
gh-36510: Add pyright ci annotations
    
<!-- ^^^^^
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"
-->
<!-- Describe your changes here in detail -->

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes #12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->
We use the [pyright-action](https://github.com/jakebailey/pyright-
action) to install and run pyright in the ci. This action is also used
by https://github.com/python/typeshed (among others) and has the
advantage that we can easily add annotations to surface typing errors.
Due to the limited typing info currently in the sage repo, we only add
these annotations for errors and not warnings.

![image](https://github.com/sagemath/sage/assets/5037600/12ed6be1-68d5-
496d-b77b-0eff750ef530)

Also fix one import that was complained about by the new pyright
version.

### 📝 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! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [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
- #12345: short description why this is a dependency
- #34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: #36510
Reported by: Tobias Diez
Reviewer(s): Matthias Köppe
  • Loading branch information
Release Manager committed Oct 29, 2023
2 parents 97b06bd + 01eed98 commit 0a0f141
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
33 changes: 21 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,30 @@ jobs:
MAKE: make -j2 --output-sync=recurse
SAGE_NUM_THREADS: 2

- name: Set up node to install pyright
- name: Static code check with pyright
if: always() && steps.worktree.outcome == 'success'
uses: actions/setup-node@v3
uses: jakebailey/pyright-action@v1
with:
node-version: '12'

- name: Install pyright
if: always() && steps.worktree.outcome == 'success'
# Fix to v232 due to bug https://github.com/microsoft/pyright/issues/3239
run: npm install -g [email protected]

- name: Static code check with pyright
version: 1.1.332
# Many warnings issued by pyright are not yet helpful because there is not yet enough type information.
no-comments: true
working-directory: ./worktree-image
env:
# To avoid out of memory errors
NODE_OPTIONS: --max-old-space-size=8192

- name: Static code check with pyright (annotated)
if: always() && steps.worktree.outcome == 'success'
run: pyright
working-directory: ./worktree-image
uses: jakebailey/pyright-action@v1
with:
version: 1.1.332
# Issue errors
no-comments: false
level: error
working-directory: ./worktree-image
env:
# To avoid out of memory errors
NODE_OPTIONS: --max-old-space-size=8192

- name: Clean (fallback to non-incremental)
id: clean
Expand Down
5 changes: 4 additions & 1 deletion src/doc/en/developer/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ Pyright

- Tox: Run ``./sage -tox -e pyright path/to/the/file.py``

- Manual: Run ``pyright path/to/the/file.py``
- Manual: Run ``pyright path/to/the/file.py``. If you want to check the whole Sage library, you most likely run out of memory with the default settings.
You can use the following command to check the whole library::

NODE_OPTIONS="--max-old-space-size=8192" pyright

- VS Code: Install the `Pylance <https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance>`__ extension.

Expand Down
2 changes: 1 addition & 1 deletion src/sage/functions/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -2209,7 +2209,7 @@ def _evalf_(self, poly, index, parent=None, algorithm=None):
sage: complex_root_of(x^8 - 1, 7).n(20) # needs sage.symbolic
0.70711 + 0.70711*I
"""
from sympy.core.evalf import prec_to_dps
from mpmath.libmp import prec_to_dps
from sympy.polys import CRootOf, Poly
try:
prec = parent.precision()
Expand Down

0 comments on commit 0a0f141

Please sign in to comment.