diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5242dfc06f9..0cf849f2a97 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -103,20 +103,9 @@ jobs: MAKE: make -j2 --output-sync=recurse SAGE_NUM_THREADS: 2 - - name: Set up node to install pyright - if: always() && steps.worktree.outcome == 'success' - uses: actions/setup-node@v3 - 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 pyright@1.1.232 - - name: Static code check with pyright if: always() && steps.worktree.outcome == 'success' - run: pyright + run: ./sage -tox -e pyright working-directory: ./worktree-image - name: Clean (fallback to non-incremental) diff --git a/pyrightconfig.json b/pyrightconfig.json index 643c56360c9..ebf40ea028c 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -22,4 +22,7 @@ "reportUndefinedVariable": "warning", "reportOptionalOperand": "warning", "reportMissingImports": "warning", + "reportPrivateImportUsage": "warning", + // Suppress because it flags our standard pattern @staticmethod __classcall__(cls, ...) + "reportSelfClsParameterName": "none", } diff --git a/src/sage/misc/lazy_attribute.pyi b/src/sage/misc/lazy_attribute.pyi new file mode 100644 index 00000000000..6a174a37aa2 --- /dev/null +++ b/src/sage/misc/lazy_attribute.pyi @@ -0,0 +1,9 @@ +# This type-stub file helps pyright understand the decorator @lazy_attribute. + +# Adapted from https://github.com/python/typeshed/blob/b9640005eb586afdbe0a57bac2b88a7a12465069/stdlib/builtins.pyi#L1237-L1254 +class lazy_attribute: + def __init__( + self, + f: Callable[[Any], Any] | None = ... + ) -> None: ... + def __get__(self, a: Any, cls: type) -> Any: ... diff --git a/src/sage/schemes/toric/variety.py b/src/sage/schemes/toric/variety.py index 82d2ec7769a..c2aea308b9b 100644 --- a/src/sage/schemes/toric/variety.py +++ b/src/sage/schemes/toric/variety.py @@ -2250,20 +2250,21 @@ def Todd_class(self, deg=None): 1 """ Td = QQ.one() - if self.dimension() >= 1: + dim = self.dimension() + if dim >= 1: c1 = self.Chern_class(1) Td += QQ.one() / 2 * c1 - if self.dimension() >= 2: - c2 = self.Chern_class(2) - Td += QQ.one() / 12 * (c1**2 + c2) - if self.dimension() >= 3: - Td += QQ.one() / 24 * c1*c2 - if self.dimension() >= 4: - c3 = self.Chern_class(3) - c4 = self.Chern_class(4) - Td += -QQ.one() / 720 * (c1**4 - 4*c1**2*c2 - 3*c2**2 - c1*c3 + c4) - if self.dimension() >= 5: - raise NotImplementedError('Todd class is currently only implemented up to degree 4') + if dim >= 2: + c2 = self.Chern_class(2) + Td += QQ.one() / 12 * (c1**2 + c2) + if dim >= 3: + Td += QQ.one() / 24 * c1*c2 + if dim >= 4: + c3 = self.Chern_class(3) + c4 = self.Chern_class(4) + Td += -QQ.one() / 720 * (c1**4 - 4*c1**2*c2 - 3*c2**2 - c1*c3 + c4) + if dim >= 5: + raise NotImplementedError('Todd class is currently only implemented up to degree 4') if deg is None: return Td else: diff --git a/src/tox.ini b/src/tox.ini index fea30bea362..e6c9bfccdcc 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -78,21 +78,22 @@ commands = [testenv:pyright] description = run the static typing checker pyright -deps = pyright +deps = + pyright setenv = {[sagedirect]setenv} HOME={envdir} - # Fix version, see .github/workflows/build.yml - PYRIGHT_PYTHON_FORCE_VERSION=1.1.232 + PYRIGHT_PYTHON_FORCE_VERSION=1.1.332 + PYRIGHT_PYTHON_GLOBAL_NODE=false + NODE_OPTIONS=--max-old-space-size=8192 allowlist_externals = {[sagedirect]allowlist_externals} ## We run pyright from within the sage-env so that SAGE_LOCAL is available. ## pyright is already configured via SAGE_ROOT/pyrightconfig.json to use our venv. ## -## Running pyright on the whole Sage source tree takes very long -## and may run out of memory. When no files/directories are given, just run it -## on the packages that already have typing annotations. +## Note that running pyright on the whole Sage source tree (= default) takes very long +## and may run out of memory. commands = - {env:SAGE} -sh -c 'pyright {posargs:{toxinidir}/sage/combinat {toxinidir}/sage/manifolds}' + {env:SAGE} -sh -c 'pyright {posargs:}' [testenv:pycodestyle] description =