From 0a4e61edf5db1886484ce257cf154c5b5fe85cdd Mon Sep 17 00:00:00 2001 From: Andrew Senetar Date: Sat, 30 Apr 2022 05:16:46 -0500 Subject: [PATCH] Additional cleanup per mypy - Add Callable type to hasher (should realy be more specific...) - Add type hint to COLUMNS in qtlib/table.py - Use Qt.ItemFlag.ItemIsEnabled instead of Qt.itemIsEnabled in qtlib/table.py --- core/fs.py | 19 ++++++++++--------- core/tests/fs_test.py | 18 ++++++++++-------- qtlib/table.py | 7 ++++--- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/core/fs.py b/core/fs.py index d006611f..7d9003bb 100644 --- a/core/fs.py +++ b/core/fs.py @@ -13,6 +13,16 @@ import os +from math import floor +import logging +import sqlite3 +from threading import Lock +from typing import Any, AnyStr, Union, Callable + +from pathlib import Path +from hscommon.util import nonone, get_file_ext + +hasher: Callable try: import xxhash @@ -22,15 +32,6 @@ except ImportError: hasher = hashlib.md5 -from math import floor -import logging -import sqlite3 -from threading import Lock -from typing import Any, AnyStr, Union - -from pathlib import Path -from hscommon.util import nonone, get_file_ext - __all__ = [ "File", "Folder", diff --git a/core/tests/fs_test.py b/core/tests/fs_test.py index 47fb9b3c..b2e2815c 100644 --- a/core/tests/fs_test.py +++ b/core/tests/fs_test.py @@ -6,6 +6,16 @@ # which should be included with this package. The terms are also available at # http://www.gnu.org/licenses/gpl-3.0.html +import typing +from os import urandom + +from pathlib import Path +from hscommon.testutil import eq_ +from core.tests.directories_test import create_fake_fs + +from .. import fs + +hasher: typing.Callable try: import xxhash @@ -15,14 +25,6 @@ except ImportError: hasher = hashlib.md5 -from os import urandom - -from pathlib import Path -from hscommon.testutil import eq_ -from core.tests.directories_test import create_fake_fs - -from .. import fs - def create_fake_fs_with_random_data(rootpath): rootpath = rootpath.joinpath("fs") diff --git a/qtlib/table.py b/qtlib/table.py index 399db13e..881e7b4d 100644 --- a/qtlib/table.py +++ b/qtlib/table.py @@ -6,6 +6,7 @@ # which should be included with this package. The terms are also available at # http://www.gnu.org/licenses/gpl-3.0.html +import typing from PyQt5.QtCore import ( Qt, QAbstractTableModel, @@ -14,13 +15,13 @@ from PyQt5.QtCore import ( QItemSelection, ) -from .column import Columns +from .column import Columns, Column class Table(QAbstractTableModel): # Flags you want when index.isValid() is False. In those cases, _getFlags() is never called. - INVALID_INDEX_FLAGS = Qt.ItemIsEnabled - COLUMNS = [] + INVALID_INDEX_FLAGS = Qt.ItemFlag.ItemIsEnabled + COLUMNS: typing.List[Column] = [] def __init__(self, model, view, **kwargs): super().__init__(**kwargs)