Skip to content

Commit a27f935

Browse files
committed
Add mypy config for optional support.
1 parent 248da34 commit a27f935

File tree

7 files changed

+48
-14
lines changed

7 files changed

+48
-14
lines changed

.github/workflows/lint-and-build.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ jobs:
4848
cache-dependency-path: "scripts/requirements*.txt"
4949
- run: scripts/install.ps1
5050
shell: pwsh
51-
- run: (Get-Command pyuic6).Source
52-
shell: pwsh
53-
- name: Analysing the code with add-trailing-comma
51+
- name: Analysing the code with isort
5452
run: isort src/ typings/ --check-only
5553
add-trailing-comma:
5654
runs-on: windows-latest

.vscode/settings.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@
4343
]
4444
},
4545
"files.associations": {
46-
"*.json": "json",
47-
"extensions.json": "jsonc",
48-
"settings.json": "jsonc",
46+
".flake8": "properties",
4947
"*.qrc": "xml",
5048
"*.ui": "xml"
5149
},
@@ -57,11 +55,10 @@
5755
"**/.DS_Store": true,
5856
"**/Thumbs.db": true,
5957
"build": true,
60-
".mypy_cache": true,
58+
"**/.mypy_cache": true,
6159
"**/__pycache__": true,
6260
},
6361
"search.exclude": {
64-
"**/bower_components": true,
6562
"**/*.code-search": true,
6663
"*.lock": true,
6764
},
@@ -77,8 +74,10 @@
7774
120, // Our hard rule
7875
],
7976
},
80-
"python.formatting.provider": "autopep8",
77+
// Important to follow the config in pyrightconfig.json
78+
"python.analysis.useLibraryCodeForTypes": false,
8179
"python.analysis.diagnosticMode": "workspace",
80+
"python.formatting.provider": "autopep8",
8281
"isort.check": true,
8382
"isort.importStrategy": "fromEnvironment",
8483
"python.linting.enabled": true,

mypy.ini

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; We don't run mypy in the CI. This is just to help anyone who would like to use it manually.
2+
; Namely, the mypy_primer tool.
3+
[mypy]
4+
strict=true
5+
; Implicit return types !
6+
disallow_untyped_calls=false
7+
disallow_untyped_defs=false
8+
disallow_incomplete_defs=false
9+
10+
; Of course my stubs are going to be incomplete. Otherwise they'd be on typeshed!
11+
; Mypy becomes really whack with its errors inside these stubs though
12+
mypy_path=typings,src
13+
; exclude doesn't work with strict=true Why?
14+
exclude=.*(typings|gen)/.*
15+
16+
[mypy-gen.*,cv2.*,]
17+
; strict=false ; Doesn't work in overrides
18+
follow_imports=skip
19+
implicit_reexport=true
20+
strict_optional=false
21+
disable_error_code=attr-defined, misc, name-defined

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ max-branches = 15
105105
# https://github.com/PyCQA/pep8-naming/issues/164
106106
# OR doesn't fit CaptureMethodMeta
107107
valid-classmethod-first-arg = "self"
108-
# https://pylint.pycqa.org/en/latest/user_guide/options.html#naming-styles
109-
module-naming-style = "any"
110108
disable = [
111109
# No need to mention the fixmes
112110
"fixme",
@@ -122,8 +120,6 @@ disable = [
122120
"unused-argument",
123121
# Only reports a single instance. Pyright does a better job anyway
124122
"cyclic-import",
125-
# Doesn't work with local imports
126-
"import-error",
127123
# Similar lines in 2 files, doesn't really work
128124
"R0801",
129125
]

scripts/requirements-dev.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ qt6-applications
3030
# Types
3131
types-d3dshot
3232
types-keyboard
33+
types-Pillow
34+
types-psutil
35+
types-PyAutoGUI
3336
types-pyinstaller
3437
types-pywin32
38+
types-requests
39+
types-toml
3540
typing-extensions

src/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def get_window_bounds(hwnd: int) -> tuple[int, int, int, int]:
8181
return window_left_bounds, window_top_bounds, window_width, window_height
8282

8383

84-
def open_file(file_path: str):
84+
def open_file(file_path: str | bytes | os.PathLike[str] | os.PathLike[bytes]):
8585
os.startfile(file_path) # nosec B606
8686

8787

typings/cv2/gapi/streaming.pyi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from cv2.cv2 import GMat, GOpaqueT, gapi_streaming_queue_capacity
2+
3+
SYNC_POLICY_DONT_SYNC: int
4+
SYNC_POLICY_DROP: int
5+
sync_policy_dont_sync: int
6+
sync_policy_drop: int
7+
8+
queue_capacity = gapi_streaming_queue_capacity
9+
10+
11+
def desync(g: GMat) -> GMat: ...
12+
def seqNo(arg1: GMat) -> GOpaqueT: ...
13+
def seq_id(arg1: GMat) -> GOpaqueT: ...
14+
def size(src: GMat) -> GOpaqueT: ...
15+
def timestamp(arg1: GMat) -> GOpaqueT: ...

0 commit comments

Comments
 (0)