Skip to content

Commit

Permalink
更改mypy的错误提示
Browse files Browse the repository at this point in the history
Signed-off-by: guoyanfeng <guo.yanfeng@dataeveryday.com>
  • Loading branch information
guoyanfeng committed Sep 3, 2020
1 parent 19a27ce commit 6065f7e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions fessql/_alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

import uuid
from typing import Dict, MutableMapping, Sequence
from typing import ClassVar, Dict, MutableMapping, Sequence

import sqlalchemy as sa
from sqlalchemy.ext.declarative import DeclarativeMeta, declarative_base
Expand All @@ -25,7 +25,7 @@ class AlchemyMixIn(object):
base alchemy
"""

Model = declarative_base()
Model: ClassVar[DeclarativeMeta] = declarative_base()

# noinspection PyUnresolvedReferences
def _verify_sanic_app(self, ):
Expand Down
2 changes: 1 addition & 1 deletion fessql/_cachelru.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
try:
from threading import RLock
except ImportError:
class RLock(object):
class RLock(object): # type: ignore
"""Dummy reentrant lock for builds without threads"""

def __enter__(self):
Expand Down
3 changes: 1 addition & 2 deletions fessql/dbalchemy/dbalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,7 @@ def paginate(self, page: int = 1, per_page: int = 20, max_per_page: int = None,
# 前提是默认id是主键,因为不排序会有混乱数据,所以从中间件直接解决,业务层不需要关心了
# 如果业务层有排序了,则此处不再提供排序功能
# 如果遇到大数据量的分页查询问题时,建议关闭此处,然后再基于已有的索引分页
# noinspection Mypy
if self._order_by is False or self._order_by is None:
if self._order_by is False or self._order_by is None: # type: ignore
select_model = getattr(self._primary_entity, "selectable", None)

if isinstance(select_model, Table) and getattr(select_model.columns, "id", None) is not None:
Expand Down
11 changes: 5 additions & 6 deletions fessql/tinymysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def close(self, ):
"""
self.conn.close()

# noinspection Mypy
def execute_many(self, sql: str, args_data: List[Tuple]) -> int:
"""
批量插入数据
Expand All @@ -102,7 +101,7 @@ def execute_many(self, sql: str, args_data: List[Tuple]) -> int:
count: int = 0
try:
with self.conn.cursor() as cursor:
count = cursor.executemany(sql, args_data)
count = cursor.executemany(sql, args_data) # type: ignore
except pymysql.Error as e:
self.conn.rollback()
aelog.exception(e)
Expand Down Expand Up @@ -142,7 +141,6 @@ def execute(self, sql: str, args_data: Tuple = None) -> int:
self.conn.commit()
return count

# noinspection Mypy
def find_one(self, sql: str, args: Tuple = None) -> Optional[Dict]:
"""
查询单条记录
Expand All @@ -158,10 +156,10 @@ def find_one(self, sql: str, args: Tuple = None) -> Optional[Dict]:
cursor.execute(sql, args)
except pymysql.Error as e:
aelog.exception(e)
return None
else:
return cursor.fetchone()
return cursor.fetchone() # type: ignore

# noinspection Mypy
def find_data(self, sql: str, args: Tuple = None, size: int = None) -> List[Dict]:
"""
查询指定行数的数据
Expand All @@ -178,5 +176,6 @@ def find_data(self, sql: str, args: Tuple = None, size: int = None) -> List[Dict
cursor.execute(sql, args)
except pymysql.Error as e:
aelog.exception(e)
return []
else:
return cursor.fetchall() if not size else cursor.fetchmany(size)
return cursor.fetchall() if not size else cursor.fetchmany(size) # type: ignore
7 changes: 3 additions & 4 deletions tests/verify_gen_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
import sqlalchemy as sa
from fesutils import objectid

from fessql import AIOMySQL
from fessql.aioalchemy import AIOMySQL

mysql_db = AIOMySQL()


# noinspection Mypy
class MessageDisplayModel(mysql_db.Model):
class MessageDisplayModel(mysql_db.Model): # type:ignore
"""
消息展示
"""
Expand Down Expand Up @@ -105,4 +104,4 @@ def test_paginate_sql(self, ):


if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(TestSQL)
unittest.TextTestRunner(verbosity=2).run(TestSQL())

0 comments on commit 6065f7e

Please sign in to comment.