Skip to content

Commit 8885768

Browse files
committed
Massively sped up Flake tests
Removed 400+kb of type stubs
1 parent bbb257f commit 8885768

File tree

25 files changed

+177
-121365
lines changed

25 files changed

+177
-121365
lines changed

.flake8

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22
color=always
33
max-line-length=120
44
; Auto generated
5-
exclude=src/gen/
6-
; Linebreak before binary operator
7-
; Allow default value other than "..."
8-
; Allow imports at the bottom of file
9-
ignore=W503,Y015,E402
5+
exclude=src/gen/, typings/cv2-stubs/__init__.pyi
6+
ignore=
7+
W503, ; Linebreak before binary operator
8+
Y015, ; Allow default value other than "..."
9+
E402, ; Allow imports at the bottom of file
10+
Y026, ; Not using typing_extensions
1011
per-file-ignores=
12+
; ???
13+
; ???
14+
; Docstrings in type stubs
15+
; Function bodys contain other than just ... (eg: raise)
16+
; Single quote docstrings
17+
typings/cv2-stubs/__init__.pyi: Q000,N8, E704,E501, Y021,Y010,Q002
18+
1119
; Quotes
12-
__init__.pyi:Q000
20+
; Naming conventions can't be controlled for external libraries
21+
__init__.pyi: Q000,N8
1322
; PyQt methods
1423
ignore-names=closeEvent,paintEvent,keyPressEvent,mousePressEvent,mouseMoveEvent,mouseReleaseEvent
1524
; McCabe max-complexity is also taken care of by Pylint and doesn't fail teh build there

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ dist/
1919

2020
# Dev settings
2121
*.pkl
22+
settings.toml

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
"python.linting.pylintCategorySeverity.refactor": "Warning",
5959
"python.linting.flake8Enabled": true,
6060
"python.linting.flake8CategorySeverity.E": "Warning",
61+
// Pyflakes
62+
"python.linting.flake8CategorySeverity.F": "Warning",
63+
// PEP8 Naming convention
64+
"python.linting.flake8CategorySeverity.N": "Warning",
65+
// PYI
66+
"python.linting.flake8CategorySeverity.Y": "Warning",
6167
// PyRight obsoletes mypy
6268
"python.linting.mypyEnabled": false,
6369
// Is already wrapped by Flake8, prospector and pylama

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@ aggressive = 3
1515
[tool.pyright]
1616
pythonPlatform = "Windows"
1717
typeCheckingMode = "strict"
18+
# Extra strict
19+
reportImplicitStringConcatenation="error"
20+
reportCallInDefaultInitializer="error"
21+
reportMissingSuperCall="none" # False positives on base classes
22+
reportPropertyTypeMismatch="error"
23+
reportUninitializedInstanceVariable="error"
24+
reportUnnecessaryTypeIgnoreComment="error"
25+
reportUnusedCallResult="none"
1826
ignore = [
1927
# Auto generated
2028
"src/gen/",
2129
# We expect stub files to be incomplete or contain useless statements as they're external
2230
"typings/",
2331
]
24-
reportMissingTypeStubs = "information"
32+
# Type stubs may not be completable
33+
reportMissingTypeStubs = "warning"
2534
# False positives with TYPE_CHECKING
2635
reportImportCycles = "information"
2736
# PyQt .connect

scripts/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ requests
2626
bandit
2727
flake8
2828
flake8-quotes
29-
pylint
30-
pywin32-stubs
29+
pylint>=2.13
30+
git+https://github.com/Avasam/pywin32-stubs.git#egg=pywin32-stubs # https://github.com/kaluluosi/pywin32-stubs/pull/4
3131
simplejson
3232
types-simplejson>=3.17.2
3333
types-requests

src/AutoSplit.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def excepthook(exception_type: type[BaseException], exception: BaseException, _t
5959
return excepthook
6060

6161

62-
class AutoSplit(QMainWindow, design.Ui_MainWindow):
62+
class AutoSplit(QMainWindow, design.Ui_main_window):
6363
myappid = f"Toufool.AutoSplit.v{VERSION}"
6464
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
6565

@@ -224,7 +224,7 @@ def __init__(self, parent: Optional[QWidget] = None):
224224

225225
self.show()
226226

227-
# Needs to be after Ui_MainWindow.show() to be shown overtop
227+
# Needs to be after Ui_main_window.show() to be shown overtop
228228
if self.action_check_for_updates_on_open.isChecked():
229229
check_for_updates(self, check_on_open=True)
230230

@@ -796,8 +796,7 @@ def __get_capture_for_comparison(self):
796796
if capture is None:
797797
# Try to recover by using the window name
798798
self.live_image.setText("Trying to recover window...")
799-
# https://github.com/kaluluosi/pywin32-stubs/issues/7
800-
hwnd = win32gui.FindWindow(None, self.window_text) # type: ignore
799+
hwnd = win32gui.FindWindow(None, self.window_text)
801800
# Don't fallback to desktop
802801
if hwnd:
803802
self.hwnd = hwnd

src/capture_windows.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ def capture_region(hwnd: int, selection: Rect, print_window: bool):
4545
# If the window closes while it's being manipulated, it could cause a crash
4646
try:
4747
window_dc: int = win32gui.GetWindowDC(hwnd)
48-
# https://github.com/kaluluosi/pywin32-stubs/issues/6
49-
dc_object: PyCDC = win32ui.CreateDCFromHandle(window_dc) # type: ignore
48+
dc_object: PyCDC = win32ui.CreateDCFromHandle(window_dc)
5049

5150
# Causes a 10-15x performance drop. But allows recording hardware accelerated windows
5251
if print_window:

src/menu_bar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def open_about(autosplit: AutoSplit):
3636

3737

3838
class __UpdateCheckerWidget(QtWidgets.QWidget, update_checker.Ui_UpdateChecker):
39-
def __init__(self, latest_version: str, design_window: design.Ui_MainWindow, check_on_open: bool = False):
39+
def __init__(self, latest_version: str, design_window: design.Ui_main_window, check_on_open: bool = False):
4040
super().__init__()
4141
self.setupUi(self)
4242
self.current_version_number_label.setText(VERSION)

src/settings_file.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def find_class(self, module: str, name: str):
2727
raise pickle.UnpicklingError(f"'{module}.{name}' is forbidden")
2828

2929

30-
def get_save_settings_values(autosplit: AutoSplit):
30+
def get_save_settings_values(autosplit: AutoSplit) -> list[str | int]:
3131
return [
3232
autosplit.split_image_directory,
3333
autosplit.similarity_threshold_spinbox.value(),
@@ -146,14 +146,14 @@ def __load_settings_from_file(autosplit: AutoSplit, load_settings_file_path: str
146146
autosplit.force_print_window_checkbox.setChecked(settings[20])
147147

148148
if autosplit.window_text:
149-
# https://github.com/kaluluosi/pywin32-stubs/issues/7
150-
hwnd = win32gui.FindWindow(None, autosplit.window_text) # type: ignore
149+
hwnd = win32gui.FindWindow(None, autosplit.window_text)
151150
if hwnd:
152151
autosplit.hwnd = hwnd
153152
else:
154-
autosplit.live_image.setText("Reload settings after opening"
155-
f'\n"{autosplit.window_text}"'
156-
"\nto automatically load Live Capture")
153+
autosplit.live_image.setText(
154+
"Reload settings after opening"
155+
+ f'\n"{autosplit.window_text}"'
156+
+ "\nto automatically load Live Capture")
157157
return True
158158

159159

@@ -203,7 +203,7 @@ def load_check_for_updates_on_open(autosplit: AutoSplit):
203203
autosplit.action_check_for_updates_on_open.setChecked(value)
204204

205205

206-
def set_check_for_updates_on_open(design_window: design.Ui_MainWindow, value: bool):
206+
def set_check_for_updates_on_open(design_window: design.Ui_main_window, value: bool):
207207
"""
208208
Sets the "Check For Updates On Open" QSettings value and the checkbox state
209209
"""

typings/PyInstaller/utils/hooks/__init__.pyi

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
"""
1+
""" # noqa: Y021
22
This type stub file was generated by pyright.
33
"""
4-
from typing import Any, Literal, Optional, Union
5-
from collections.abc import Callable
4+
from typing import Any, Literal, Optional, Union, Callable
65

76
logger = ...
87
PY_IGNORE_EXTENSIONS: set
@@ -85,11 +84,7 @@ def is_module_or_submodule(name, mod_or_submod):
8584
...
8685

8786

88-
PY_DYLIB_PATTERNS = [
89-
"*.dll",
90-
"*.dylib",
91-
"lib*.so",
92-
]
87+
PY_DYLIB_PATTERNS: str
9388

9489

9590
def collect_dynamic_libs(package: str, destdir: Optional[str] = ...) -> list[tuple[str, str]]:

typings/imagehash/__init__.pyi

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
"""
1+
""" # noqa: Y021
22
This type stub file was generated by pyright.
33
"""
44
from __future__ import absolute_import, division, print_function, annotations
5-
from PIL import Image, ImageFilter
6-
import numpy
5+
from PIL import Image
76

8-
__version__ = ...
7+
__version__: str
98

109

1110
class ImageHash:
1211
def __init__(self, binary_array) -> None:
1312
...
1413

15-
def __str__(self) -> str:
16-
...
17-
18-
def __repr__(self) -> str:
19-
...
20-
2114
def __sub__(self, other: ImageHash) -> int:
2215
...
2316

@@ -90,13 +83,7 @@ class ImageMultiHash:
9083
def __hash__(self) -> int:
9184
...
9285

93-
def __str__(self) -> str:
94-
...
95-
96-
def __repr__(self) -> str:
97-
...
98-
99-
def hash_diff(self, other_hash, hamming_cutoff=..., bit_error_rate=...) -> tuple[int, Unknown | int]:
86+
def hash_diff(self, other_hash, hamming_cutoff=..., bit_error_rate=...) -> tuple[int, int]:
10087
...
10188

10289
def matches(self, other_hash, region_cutoff=..., hamming_cutoff=..., bit_error_rate=...):

0 commit comments

Comments
 (0)