Skip to content

Commit 112eb4b

Browse files
committed
Upgrade mypy 2.0 and Ruff 0.15.4
1 parent 22bd1f1 commit 112eb4b

19 files changed

Lines changed: 210 additions & 128 deletions

mypy.ini

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,39 @@
55
# https://github.com/BesLogic/shared-configs/blob/main/mypy.ini
66
# Modifications to this file that are not project-specific should also be done upstream.
77

8+
# This config file assumes Mypy 2.0+
9+
810
# https://mypy.readthedocs.io/en/stable/config_file.html
911
[mypy]
1012
###
1113
# General settings
1214
###
13-
fixed_format_cache = true
1415
show_column_numbers = true
15-
strict = true
16-
strict_equality_for_none = true
17-
report_deprecated_as_note = true
18-
follow_untyped_imports = true
19-
allow_redefinition_new = true
20-
local_partial_types = true
2116

17+
###
18+
# Strictness flags
2219
# All below are rules and codes not enabled by default even with strict=true
20+
###
21+
strict = true
22+
strict_equality_for_none = true
23+
warn_unreachable = true
2324
; <removed section from upstream>
2425
; We don't run mypy in the CI. This is just to help anyone who would like to use it manually.
2526
; Namely, the mypy_primer tool.
2627

28+
###
29+
# Reduced strictness, where flexibility is preferred
30+
###
31+
allow_redefinition = true
32+
report_deprecated_as_note = true
33+
# Disable this if you want to ensure all your dependencies are typed
34+
follow_untyped_imports = true
35+
2736
# Implicit return types using pyright ! (mypy doesn't do implicit return types)
2837
# Note: mypy still has issues with some boolean inferred returns:
2938
# https://github.com/python/mypy/issues/4409
3039
# https://github.com/python/mypy/issues/10149
31-
# Comment out if not using pyright or implicit types
40+
# Comment out/remove if not using pyright or implicit types (like for a library)
3241
check_untyped_defs = true
3342
disallow_untyped_calls = false
3443
disallow_untyped_defs = false

pyproject.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ dev = [
5252
"qt6-applications >=6.5.0",
5353
#
5454
# Linters & Formatters
55-
"dprint-py>=0.50.0.0",
56-
"mypy >=1.19",
55+
"dprint-py >=0.50.0.0",
56+
"mypy >=2.1",
5757
"pyright[nodejs] >=1.1.400", # reportPrivateImportUsage behaviour change
5858
{ include-group = "ruff" },
5959
#
@@ -76,6 +76,9 @@ dependency-metadata = [
7676
{ name = "PyAutoGUI", requires-dist = [] },
7777
{ name = "types-PyAutoGUI", requires-dist = [] },
7878
]
79+
exclude-newer = "1 week"
80+
[tool.uv.exclude-newer-package]
81+
ruff = "4 days" # Needs 0.15.4
7982

8083
[tool.uv.sources] # Development channels
8184
beslogic-ruff-config = { git = "https://github.com/Beslogic/Beslogic-Ruff-Config" }
@@ -111,8 +114,8 @@ enableExperimentalFeatures = true
111114
reportCallInDefaultInitializer = "error"
112115
reportImplicitOverride = "error"
113116
reportImplicitStringConcatenation = "error"
114-
# False positives with TYPE_CHECKING
115-
reportImportCycles = "information"
117+
# False positives with TYPE_CHECKING, mostly covered by Ruff TCH00
118+
reportImportCycles = "none"
116119
# Too strict. False positives on base classes
117120
reportMissingSuperCall = "none"
118121
reportPropertyTypeMismatch = "error"

ruff.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,8 @@ ignore = [
1919
###
2020
"PTH", # flake8-use-pathlib
2121
"RUF028", # invalid-formatter-suppression-comment, Is meant for the formatter, but false-positives
22-
# Disabled until https://github.com/astral-sh/ruff/issues/23185 is fixed
23-
"TC00",
2422
]
2523

26-
# https://docs.astral.sh/ruff/settings/#isort
27-
[lint.isort]
28-
# The src-based layout detection can differ on CI
29-
# TODO: Check if this has been fixed in Ruff 0.13
30-
known-third-party = ["gen"]
31-
3224
[lint.per-file-ignores]
3325
"src/d3d11.py" = [
3426
# Following windows API/ctypes like naming conventions

src/AutoSplit.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ def do_nothing(*_): ...
3232
from copy import deepcopy
3333
from time import time
3434
from types import FunctionType
35-
from typing import NoReturn, override
35+
from typing import TYPE_CHECKING, NoReturn, override
3636

3737
import cv2
38-
from cv2.typing import MatLike
39-
from gen import about, design, settings, update_checker
4038
from PySide6 import QtCore, QtGui
4139
from PySide6.QtTest import QTest
4240
from PySide6.QtWidgets import QApplication, QFileDialog, QLabel, QMainWindow, QMessageBox
@@ -45,7 +43,9 @@ def do_nothing(*_): ...
4543
import user_profile
4644
from AutoControlledThread import AutoControlledThread
4745
from AutoSplitImage import START_KEYWORD, AutoSplitImage, ImageType
48-
from capture_method import CaptureMethodBase, CaptureMethodEnum
46+
from capture_method import CaptureMethodEnum
47+
from capture_method.CaptureMethodBase import CaptureMethodBase
48+
from gen import about, design, settings, update_checker
4949
from hotkeys import (
5050
HOTKEYS,
5151
KEYBOARD_GROUPS_ISSUE,
@@ -87,6 +87,9 @@ def do_nothing(*_): ...
8787
open_file,
8888
)
8989

90+
if TYPE_CHECKING:
91+
from cv2.typing import MatLike
92+
9093
CHECK_FPS_ITERATIONS = 10
9194

9295

@@ -1073,7 +1076,7 @@ def main():
10731076
QApplication.setStyle("fusion")
10741077
# Call to QApplication outside the try-except so we can show error messages
10751078
app = QApplication(sys.argv)
1076-
try:
1079+
try: # noqa: PLW0717 # We really want to catch everything here
10771080
if sys.platform == "win32":
10781081
myappid = f"Toufool.AutoSplit.v{AUTOSPLIT_VERSION}"
10791082
shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

src/AutoSplitImage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import cv2
1010
import numpy as np
11-
from cv2.typing import MatLike
1211

1312
import error_messages
1413
from compare import (
@@ -27,6 +26,8 @@
2726
)
2827

2928
if TYPE_CHECKING:
29+
from cv2.typing import MatLike
30+
3031
from AutoSplit import AutoSplit
3132

3233

src/capture_method/BitBltCaptureMethod.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
if sys.platform != "win32":
44
raise OSError
55
import ctypes
6-
from typing import override
6+
from typing import TYPE_CHECKING, override
77

88
import numpy as np
99
import pywintypes
1010
import win32con
1111
import win32gui
1212
import win32ui
13-
from cv2.typing import MatLike
1413

1514
from capture_method.CaptureMethodBase import CaptureMethodBase
1615
from utils import BGRA_CHANNEL_COUNT, get_window_bounds, is_valid_hwnd, try_delete_dc
1716

17+
if TYPE_CHECKING:
18+
from cv2.typing import MatLike
19+
1820
# This is an undocumented nFlag value for PrintWindow
1921
PW_RENDERFULLCONTENT = 0x00000002
2022

@@ -48,7 +50,7 @@ def get_frame(self) -> MatLike | None:
4850
return None
4951

5052
# If the window closes while it's being manipulated, it could cause a crash
51-
try:
53+
try: # noqa: PLW0717
5254
window_dc = win32gui.GetWindowDC(hwnd)
5355
dc_object = win32ui.CreateDCFromHandle(window_dc)
5456

src/capture_method/CaptureMethodBase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
from typing import TYPE_CHECKING
44

5-
from cv2.typing import MatLike
6-
75
from utils import is_valid_hwnd
86

97
if TYPE_CHECKING:
8+
from cv2.typing import MatLike
9+
1010
from AutoSplit import AutoSplit
1111

1212

src/capture_method/Screenshot using QT attempt.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
if sys.platform != "linux":
44
raise OSError
5-
from typing import cast, override
5+
from typing import TYPE_CHECKING, cast, override
66

77
import numpy as np
8-
from cv2.typing import MatLike
98
from PySide6.QtCore import QBuffer, QIODeviceBase
109
from PySide6.QtGui import QGuiApplication
1110

1211
from capture_method.CaptureMethodBase import CaptureMethodBase
1312

13+
if TYPE_CHECKING:
14+
from cv2.typing import MatLike
15+
1416

1517
class QtCaptureMethod(CaptureMethodBase):
1618
_render_full_content = False
@@ -28,7 +30,7 @@ def get_frame(self):
2830
b = image.bits()
2931
# sip.voidptr must know size to support python buffer interface
3032
# b.setsize(200 * 200 * 3)
31-
frame = np.frombuffer(cast(MatLike, b), np.uint8).reshape((200, 200, 3))
33+
frame = np.frombuffer(cast("MatLike", b), np.uint8).reshape((200, 200, 3))
3234

3335
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
3436
return frame # noqa: RET504

src/capture_method/ScrotCaptureMethod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _scrot_screenshot(x: int, y: int, width: int, height: int):
2828
screenshot_file = os.path.join(tmp, "autosplit")
2929
try:
3030
subprocess.check_call(( # noqa: S603 # Not user input
31-
"scrot",
31+
"/usr/bin/scrot",
3232
"-a",
3333
f"{x},{y},{width},{height}",
3434
"-z",

src/capture_method/VideoCaptureDeviceCaptureMethod.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import cv2
77
import cv2.Error
88
import numpy as np
9-
from cv2.typing import MatLike
109

1110
from capture_method.CaptureMethodBase import CaptureMethodBase
1211
from error_messages import CREATE_NEW_ISSUE_MESSAGE, exception_traceback
1312
from utils import ImageShape, get_input_device_resolution, is_valid_image
1413

1514
if TYPE_CHECKING:
15+
from cv2.typing import MatLike
16+
1617
from AutoSplit import AutoSplit
1718

1819
OBS_VIRTUALCAM_PLUGIN_BLANK_PIXEL = (127, 129, 128)
@@ -48,7 +49,7 @@ class VideoCaptureDeviceCaptureMethod(CaptureMethodBase):
4849
is_old_image = False
4950

5051
def __read_loop(self):
51-
try:
52+
try: # noqa: PLW0717 # We really want to catch everything here
5253
while not self.stop_thread.is_set():
5354
try:
5455
result, image = self.capture_device.read()

0 commit comments

Comments
 (0)