From 7d6fd48a6fb8f3e2fb2f2374c2279e3e5b997e7b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 17 Mar 2021 14:54:06 +1000 Subject: [PATCH] fix mypy treating Qt objects as inheriting from Any Before this change, mypy would fail to catch mistakes like mw.does_not_exist(). Also fix a couple of bugs this has uncovered. --- pip/pyqt5/install_pyqt5.py | 10 ++++++++++ qt/aqt/browser.py | 4 ++-- qt/aqt/sidebar.py | 4 +++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pip/pyqt5/install_pyqt5.py b/pip/pyqt5/install_pyqt5.py index 13f3234af..05186160f 100644 --- a/pip/pyqt5/install_pyqt5.py +++ b/pip/pyqt5/install_pyqt5.py @@ -91,7 +91,17 @@ def copy_and_fix_pyi(source, dest): with open(source) as input_file: with open(dest, "w") as output_file: for line in input_file.readlines(): + # assigning to None is a syntax error line = fix_none.sub(r"\1_ =", line) + # inheriting from the missing sip.sipwrapper definition + # causes missing attributes not to be detected, as it's treating + # the class as inheriting from Any + line = line.replace("sip.simplewrapper", "object") + line = line.replace("sip.wrapper", "object") + # remove blanket getattr in QObject which also causes missing + # attributes not to be detected + if "def __getattr__(self, name: str) -> typing.Any" in line: + continue output_file.write(line) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index acd7aa26a..d6e8ec212 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -1219,7 +1219,7 @@ where id in %s""" ) -> None: "Shows prompt if tags not provided." if not ( - tags := self.maybe_prompt_for_tags(tags, tr(TR.BROWSING_ENTER_TAGS_TO_ADD)) + tags := self._maybe_prompt_for_tags(tags, tr(TR.BROWSING_ENTER_TAGS_TO_ADD)) ): return add_tags(mw=self.mw, note_ids=self.selectedNotes(), space_separated_tags=tags) @@ -1228,7 +1228,7 @@ where id in %s""" def remove_tags_from_selected_notes(self, tags: Optional[str] = None) -> None: "Shows prompt if tags not provided." if not ( - tags := self.maybe_prompt_for_tags( + tags := self._maybe_prompt_for_tags( tags, tr(TR.BROWSING_ENTER_TAGS_TO_DELETE) ) ): diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index b4311c736..7aa53479b 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -716,7 +716,9 @@ class SidebarTreeView(QTreeView): for stage in SidebarStage: if stage == SidebarStage.ROOT: root = SidebarItem("", "", item_type=SidebarItemType.ROOT) - handled = gui_hooks.browser_will_build_tree(False, root, stage, self) + handled = gui_hooks.browser_will_build_tree( + False, root, stage, self.browser + ) if not handled: self._build_stage(root, stage)