Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable strict_optional in aqt/. and aqt/browser #3486

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7de5aa1
Boolean naming convention
bpnguyen107 Oct 7, 2024
04c84f7
Rename no_strict_optional -> strict_optional
bpnguyen107 Oct 7, 2024
28da550
Update CONTRIBUTORS
bpnguyen107 Oct 7, 2024
f48d20c
Enable strict optional for aqt module
bpnguyen107 Oct 7, 2024
3a0b56a
Fix errors
bpnguyen107 Oct 7, 2024
3864061
Enable strict optional for aqt browser
bpnguyen107 Oct 7, 2024
7aeedf1
Fix layout.py errors
bpnguyen107 Oct 7, 2024
ffd4d74
Fix find_duplicates.py errors
bpnguyen107 Oct 7, 2024
5d2b473
Fix browser.py errors
bpnguyen107 Oct 7, 2024
38b16b5
Revert a0 a1 names
bpnguyen107 Oct 7, 2024
e3f745f
Fix tree.py errors
bpnguyen107 Oct 7, 2024
439454f
Fix previewer.py errors
bpnguyen107 Oct 7, 2024
eb66b20
Fix model.py errors
bpnguyen107 Oct 7, 2024
d46297e
Fix find_and_replace.py errors
bpnguyen107 Oct 7, 2024
2abdb8b
Fix item.py errors
bpnguyen107 Oct 7, 2024
182d01e
Fix toolbar.py errors
bpnguyen107 Oct 7, 2024
330544a
Fix table/__init__.py errors
bpnguyen107 Oct 7, 2024
0047146
Fix model.py errors
bpnguyen107 Oct 8, 2024
e2506a7
Fix state.py errors
bpnguyen107 Oct 8, 2024
59e6a11
Fix table.py errors
bpnguyen107 Oct 8, 2024
9fe51a9
Fix errors in card_info.py
bpnguyen107 Oct 8, 2024
7da7dba
Fix searchbar.py errors
bpnguyen107 Oct 8, 2024
bdc0956
Fix name
bpnguyen107 Oct 8, 2024
d97399d
Fix assert in browser.py
bpnguyen107 Oct 9, 2024
f9b6d66
Formatting
bpnguyen107 Oct 9, 2024
d8c5300
Fix assert vh
bpnguyen107 Oct 9, 2024
b39de45
assert is not None instead of truthy
bpnguyen107 Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[mypy]
python_version = 3.9
pretty = false
no_strict_optional = true
show_error_codes = true
check_untyped_defs = true
pretty = False
strict_optional = False
show_error_codes = True
check_untyped_defs = True
disallow_untyped_decorators = True
warn_redundant_casts = True
warn_unused_configs = True
strict_equality = true
namespace_packages = true
explicit_package_bases = true
strict_equality = True
namespace_packages = True
explicit_package_bases = True
mypy_path =
pylib,
out/pylib,
Expand All @@ -26,21 +26,25 @@ disallow_untyped_defs = True
disallow_untyped_defs = False
[mypy-anki.exporting]
disallow_untyped_defs = False
[mypy-aqt]
strict_optional = True
[mypy-aqt.browser.*]
strict_optional = True
[mypy-aqt.operations.*]
no_strict_optional = false
strict_optional = True
[mypy-anki.scheduler.base]
no_strict_optional = false
strict_optional = True
[mypy-anki._backend.rsbridge]
ignore_missing_imports = True
[mypy-anki._vendor.stringcase]
disallow_untyped_defs = False
[mypy-stringcase]
ignore_missing_imports = True
[mypy-aqt.mpv]
disallow_untyped_defs=false
ignore_errors=true
disallow_untyped_defs=False
ignore_errors=True
[mypy-aqt.winpaths]
disallow_untyped_defs=false
disallow_untyped_defs=False

[mypy-win32file]
ignore_missing_imports = True
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Christian Donat <https://github.com/cdonat2>
Asuka Minato <https://asukaminato.eu.org>
Dillon Baldwin <https://github.com/DillBal>
Voczi <https://github.com/voczi>
Ben Nguyen <[email protected]>
Ben Nguyen <[email protected]>
Themis Demetriades <[email protected]>
Luke Bartholomew <[email protected]>
Gregory Abrasaldo <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion pylib/anki/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def update_image_occlusion_note(
# Object helpers
##########################################################################

def get_card(self, id: CardId) -> Card:
def get_card(self, id: CardId | None) -> Card:
return Card(self, id)

def update_cards(
Expand Down
21 changes: 17 additions & 4 deletions qt/aqt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ def fn_ngettext(a, b, c) -> None: # type: ignore
if _qtrans.load(f"qtbase_{qt_lang}", qt_dir):
app.installTranslator(_qtrans)

return anki.lang.current_i18n
backend = anki.lang.current_i18n
assert backend is not None

return backend


# App initialisation
Expand All @@ -291,11 +294,13 @@ class NativeEventFilter(QAbstractNativeEventFilter):
def nativeEventFilter(
self, eventType: Any, message: Any
) -> tuple[bool, sip.voidptr | None]:

if eventType == "windows_generic_MSG":
import ctypes
import ctypes.wintypes

msg = ctypes.wintypes.MSG.from_address(int(message))
if msg.message == 17: # WM_QUERYENDSESSION
assert mw is not None
if mw.can_auto_sync():
mw.app._set_windows_shutdown_block_reason(tr.sync_syncing())
mw.progress.single_shot(100, mw.unloadProfileAndExit)
Expand Down Expand Up @@ -325,6 +330,7 @@ def _set_windows_shutdown_block_reason(self, reason: str) -> None:
import ctypes
from ctypes import windll, wintypes # type: ignore

assert mw is not None
windll.user32.ShutdownBlockReasonCreate(
wintypes.HWND.from_param(int(mw.effectiveWinId())),
ctypes.c_wchar_p(reason),
Expand All @@ -334,6 +340,7 @@ def _unset_windows_shutdown_block_reason(self) -> None:
if is_win:
from ctypes import windll, wintypes # type: ignore

assert mw is not None
windll.user32.ShutdownBlockReasonDestroy(
wintypes.HWND.from_param(int(mw.effectiveWinId())),
)
Expand Down Expand Up @@ -388,7 +395,9 @@ def onRecv(self) -> None:
# OS X file/url handler
##################################################

def event(self, evt: QEvent) -> bool:
def event(self, evt: QEvent | None) -> bool:
assert evt is not None

if evt.type() == QEvent.Type.FileOpen:
self.appMsg.emit(evt.file() or "raise") # type: ignore
return True
Expand All @@ -397,7 +406,9 @@ def event(self, evt: QEvent) -> bool:
# Global cursor: pointer for Qt buttons
##################################################

def eventFilter(self, src: Any, evt: QEvent) -> bool:
def eventFilter(self, src: Any, evt: QEvent | None) -> bool:
assert evt is not None

pointer_classes = (
QPushButton,
QCheckBox,
Expand Down Expand Up @@ -547,6 +558,8 @@ def msgHandler(category: Any, ctx: Any, msg: Any) -> None:


def write_profile_results() -> None:
assert profiler is not None

profiler.disable()
profile = "out/anki.prof"
profiler.dump_stats(profile)
Expand Down
Loading