Skip to content

Commit c6c4b5d

Browse files
author
Thomas Preud'homme
committed
Teach Mypy about sqlalchemy's declarative_base()
Mypy complains about alias for sqlalchemy.ext.declarative.declarative_base() and everywhere where it is used. SQLAlchemy has a stubs to tell Mypy about those which gets rid of lots of Mypy warnings. Reviewed By: PrzemekWirkus Differential Revision: https://reviews.llvm.org/D94664
1 parent f98bc1b commit c6c4b5d

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

lnt/server/db/migrations/upgrade_0_to_1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# versioning.
55

66
import sqlalchemy
7+
from sqlalchemy.ext.declarative import declarative_base
78
from sqlalchemy import Float, String, Integer, Column, ForeignKey, Binary, DateTime
89
from sqlalchemy.orm import relation
9-
from sqlalchemy.ext.declarative import declarative_base
1010

11-
Base = declarative_base() # type: sqlalchemy.ext.declarative.api.DeclarativeMeta
11+
Base = declarative_base()
1212

1313
###
1414
# Core Schema

lnt/server/db/migrations/upgrade_12_to_13.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Adds new table to store jsonschema previously used to construct testsuite.
22
import sqlalchemy
3+
from sqlalchemy.ext.declarative import declarative_base
34
from sqlalchemy import Column, String, Binary
45

5-
Base = sqlalchemy.ext.declarative.declarative_base()
6+
Base = declarative_base()
67

78

89
class TestSuiteJSONSchema(Base):

mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mypy]
2+
plugins = sqlmypy

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ basepython = python3
2929
skip_install = true
3030
deps =
3131
mypy
32+
sqlalchemy-stubs
3233
commands =
3334
# No where close to passing yet, but nice to have.
3435
- mypy --junit-xml=junit-{envname}.xml --py2 --ignore-missing-imports lnt
@@ -52,4 +53,4 @@ deps =
5253
sphinx_bootstrap_theme
5354

5455
commands =
55-
make -C {toxinidir}/docs/ html
56+
make -C {toxinidir}/docs/ html

0 commit comments

Comments
 (0)