diff --git a/.mypy.ini b/.mypy.ini new file mode 100644 index 0000000000000000000000000000000000000000..d2d948d56e88e15857e27a2ca87ff71078e55633 --- /dev/null +++ b/.mypy.ini @@ -0,0 +1,2 @@ +[mypy] +plugins=sqlmypy diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..a771a7a681a222dd46101a8367c757dfa179470e --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1,13 @@ +# Development tools +python-language-server +mypy +sqlalchemy-stubs +pyls-mypy +pycodestyle +pyflakes +pylint +rope +future +autopep8 +pydocstyle +yapf diff --git a/test.py b/test.py index 52de5fae4eaa722f915968f37acea2c1af90cbb2..c1118768f009192246b6afbbc017552e24b72a22 100755 --- a/test.py +++ b/test.py @@ -1,12 +1,23 @@ #!/usr/bin/env python3 -from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, Enum +from sqlalchemy import create_engine, Column, Integer, String, ForeignKey from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship, sessionmaker +from typing import List, TYPE_CHECKING, TypeVar, Type, Any import sqlalchemy.engine.url import config import enum +# HACK: Work-around for https://github.com/dropbox/sqlalchemy-stubs/issues/114 +if TYPE_CHECKING: + from sqlalchemy.sql.type_api import TypeEngine + T = TypeVar('T') + class Enum(TypeEngine[T]): + def __init__(self, enum: Type[T], **kwargs: Any) -> None: ... +else: + from sqlalchemy import Enum + + engine_url = sqlalchemy.engine.url.URL( drivername='postgresql', username=config.DB_USER, @@ -19,11 +30,13 @@ engine = create_engine(engine_url, echo=True) Base = declarative_base() + class PlaceType(enum.Enum): region = 1 school = 2 site = 3 + class Place(Base): __tablename__ = 'places' @@ -37,13 +50,14 @@ class Place(Base): children = relationship('Place') + Session = sessionmaker(bind=engine) session = Session() session.query(Place).delete() with open('db/regions') as reg_list: - stack = [] + stack: List[Place] = [] for line in reg_list: line = line.rstrip() cols = line.split('\t') @@ -65,4 +79,5 @@ with open('db/regions') as reg_list: session.flush() stack.append(place) + session.commit()