As discussed in #7589, `slotscheck` can prevent slots-related mistakes from creeping back in.
Plan for now is to have slotscheck part of the "lint" tests
(renamed from pep8) that will run for CI and github actions.
To support slotscheck's runtime nature, slotscheck is
run twice, first with cython exts enabled and then
with them disabled via new environment variable.
Also added sqlalchemy[mypy] dependency to support slots
checking the mypy plugin.
Found and fixed one more `__slots__` issue by disabling C
exts.
Closes: #7670
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7670
Pull-request-sha:
3e77fe5449615a3c7c61ce9a1e4e79cd6636a89a
Change-Id: I90cdd284cdcee316a38856ba94d72ffc98947c5a
- name: Run tests
run: tox -e mypy ${{ matrix.pytest-args }}
- run-pep8:
- name: pep8-${{ matrix.python-version }}
+ run-lint:
+ name: lint-${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
# run this job using this matrix, excluding some combinations below.
pip list
- name: Run tests
- run: tox -e pep8
+ run: tox -e lint
# Arm emulation is quite slow (~20min) so for now just run it when merging to main
# run-test-arm64:
- name: Run tests
run: tox -e mypy ${{ matrix.pytest-args }}
- run-pep8:
- name: pep8-${{ matrix.python-version }}
+ run-lint:
+ name: lint-${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
# run this job using this matrix, excluding some combinations below.
pip list
- name: Run tests
- run: tox -e pep8
+ run: tox -e lint
run-pep484:
name: pep484-${{ matrix.python-version }}
+import os
import typing
if not typing.TYPE_CHECKING:
- try:
- from ..cyextension import util # noqa
- except ImportError:
+ if os.environ.get("DISABLE_SQLALCHEMY_CEXT_RUNTIME"):
HAS_CYEXTENSION = False
else:
- HAS_CYEXTENSION = True
+ try:
+ from ..cyextension import util # noqa
+ except ImportError:
+ HAS_CYEXTENSION = False
+ else:
+ HAS_CYEXTENSION = True
else:
HAS_CYEXTENSION = False
class ImmutableContainer:
+ __slots__ = ()
+
def _immutable(self, *arg: Any, **kw: Any) -> NoReturn:
raise TypeError("%s object is immutable" % self.__class__.__name__)
line-length = 79
target-version = ['py37']
+[tool.slotscheck]
+exclude-modules = '^sqlalchemy\.testing'
+
[tool.pytest.ini_options]
addopts = "--tb native -v -r sfxX --maxfail=250 -p warnings -p logging --strict-markers"
pytest -m mypy {posargs}
# thanks to https://julien.danjou.info/the-best-flake8-extensions/
-[testenv:pep8]
+[testenv:lint]
basepython = python3
deps=
flake8
pydocstyle
pygments
black==21.12b0
+ slotscheck>=0.12,<0.13
+
+ # this is to satisfy the mypy plugin dependency
+ # when slotscheck imports sqlalchemy.mypy modules
+ sqlalchemy[mypy]
+allowlist_externals =
+ env
commands =
flake8 ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py {posargs}
black --check ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py
+ # test with cython and without cython exts running
+ slotscheck -m sqlalchemy
+ env DISABLE_SQLALCHEMY_CEXT_RUNTIME=1 slotscheck -m sqlalchemy
+
+
+# "pep8" env was renamed to "lint".
+# Kept for backwards compatibility until rename is completed elsewhere.
+[testenv:pep8]
+basepython = {[testenv:lint]basepython}
+deps = {[testenv:lint]deps}
+allowlist_externals = {[testenv:lint]allowlist_externals}
+commands = {[testenv:lint]commands}
# command run in the github action when cext are active.