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.
This commit is contained in:
Damien Elmes 2021-03-17 14:54:06 +10:00
parent 0c59c8b591
commit 7d6fd48a6f
3 changed files with 15 additions and 3 deletions

View file

@ -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)

View file

@ -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)
)
):

View file

@ -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)