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

Typing update #360

Merged
merged 9 commits into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 9 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# https://medium.com/@doedotdev/mypy-for-github-action-7da1ebee99e7
on:
push:
branches:
Expand All @@ -16,15 +15,15 @@ jobs:
- run: pip install -r requirements.txt -r requirements-dev.txt
- run: git submodule init && git submodule update
- run: |
mypy --platform linux --python-version 3.7 porcupine more_plugins
mypy --platform linux --python-version 3.8 porcupine more_plugins
mypy --platform linux --python-version 3.9 porcupine more_plugins
mypy --platform win32 --python-version 3.7 porcupine more_plugins
mypy --platform win32 --python-version 3.8 porcupine more_plugins
mypy --platform win32 --python-version 3.9 porcupine more_plugins
mypy --platform darwin --python-version 3.7 porcupine more_plugins
mypy --platform darwin --python-version 3.8 porcupine more_plugins
mypy --platform darwin --python-version 3.9 porcupine more_plugins
time mypy --platform linux --python-version 3.7 porcupine more_plugins
time mypy --platform linux --python-version 3.8 porcupine more_plugins
time mypy --platform linux --python-version 3.9 porcupine more_plugins
time mypy --platform win32 --python-version 3.7 porcupine more_plugins
time mypy --platform win32 --python-version 3.8 porcupine more_plugins
time mypy --platform win32 --python-version 3.9 porcupine more_plugins
time mypy --platform darwin --python-version 3.7 porcupine more_plugins
time mypy --platform darwin --python-version 3.8 porcupine more_plugins
time mypy --platform darwin --python-version 3.9 porcupine more_plugins
pytest-windows:
strategy:
matrix:
Expand Down
9 changes: 4 additions & 5 deletions porcupine/plugins/directory_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import tkinter
from functools import partial
from tkinter import ttk
from typing import Any, Dict, List, Optional, Tuple, Union, cast
from typing import Any, Dict, List, Optional, Tuple, Union

from porcupine import get_paned_window, get_tab_manager, settings, tabs, utils

Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(self, master: tkinter.Misc) -> None:
super().__init__(master, selectmode='browse', show='tree', style='DirectoryTree.Treeview')

# Needs after_idle because selection hasn't updated when binding runs
self.bind('<Button-1>', (lambda event: self.after_idle(self.on_click, event)), add=True) # type: ignore
self.bind('<Button-1>', (lambda event: self.after_idle(self.on_click, event)), add=True)

self.bind('<<TreeviewOpen>>', self.open_file_or_dir, add=True)
self.bind('<<TreeviewSelect>>', self.update_selection_color, add=True)
Expand All @@ -84,7 +84,7 @@ def on_click(self, event: tkinter.Event) -> None:
#
# To find time between the two clicks of double-click, I made a program
# that printed times when I clicked.
selection: Tuple[str, ...] = self.selection() # type: ignore
selection = self.selection()
if event.time - self._last_click_time < 500 and self._last_click_selection == selection:
# double click
self.open_file_or_dir()
Expand Down Expand Up @@ -321,8 +321,7 @@ def path_callback(junk: object = None) -> None:
tab.bind('<<PathChanged>>', tree.hide_old_projects, add=True)
tab.bind('<Destroy>', tree.hide_old_projects, add=True)

# https://github.com/python/typeshed/issues/5010
tab.bind('<<Save>>', (lambda event: cast(None, tab.after_idle(tree.refresh_everything))), add=True)
tab.bind('<<Save>>', (lambda event: tab.after_idle(tree.refresh_everything)), add=True)
tab.textwidget.bind('<FocusIn>', tree.refresh_everything, add=True)


Expand Down
6 changes: 2 additions & 4 deletions porcupine/plugins/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import threading
import time
from functools import partial
from typing import IO, Any, Dict, List, NamedTuple, Optional, Tuple, Union, cast
from typing import IO, Dict, List, NamedTuple, Optional, Tuple, Union

if sys.platform != 'win32':
import fcntl
Expand Down Expand Up @@ -100,9 +100,7 @@ def write(self, bytez: bytes) -> None:

def error_says_socket_not_connected(error: OSError) -> bool:
if sys.platform == 'win32':
# i tried socket.socket().recv(1024) on windows and this is what i got
# https://github.com/python/mypy/issues/8823
return (cast(Any, error).winerror == 10057)
return (error.winerror == 10057)
else:
return (error.errno == errno.ENOTCONN)

Expand Down
5 changes: 2 additions & 3 deletions porcupine/plugins/linenumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import tkinter.font
from typing import Optional, cast
from typing import Optional

from porcupine import get_tab_manager, tabs, textwidget, utils

Expand All @@ -22,9 +22,8 @@ def __init__(self, parent: tkinter.Misc, textwidget_of_tab: tkinter.Text) -> Non
textwidget.use_pygments_theme(self.canvas, self._set_colors)
utils.add_scroll_command(textwidget_of_tab, 'yscrollcommand', self._do_update)

# https://github.com/python/typeshed/issues/5010
textwidget_of_tab.bind('<<ContentChanged>>', (
cast(None, lambda event: textwidget_of_tab.after_idle(self._do_update))
lambda event: textwidget_of_tab.after_idle(self._do_update)
), add=True)
textwidget_of_tab.bind('<<UpdateLineNumbers>>', self._do_update, add=True) # TODO: document this?
self._do_update()
Expand Down
2 changes: 1 addition & 1 deletion porcupine/plugins/tab_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def show_menu(event: tkinter.Event[tabs.TabManager]) -> None:
menu.add_command(label="Close other tabs", command=partial(close_clicked_tab, event, what2close='others'))

menu.tk_popup(event.x_root, event.y_root)
menu.bind('<Unmap>', (lambda event: menu.after_idle(menu.destroy)), add=True) # type: ignore
menu.bind('<Unmap>', (lambda event: menu.after_idle(menu.destroy)), add=True)


# Close tab on middle-click (press down the wheel of the mouse)
Expand Down
8 changes: 3 additions & 5 deletions porcupine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import time
import tkinter.font
from tkinter import messagebox, ttk
from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, cast, overload
from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, overload

import dacite
from pygments import styles # type: ignore[import]
Expand Down Expand Up @@ -640,8 +640,7 @@ def add_label(text: str) -> ttk.Label:
label = ttk.Label(get_dialog_content(), text=text)
label.grid(column=0, columnspan=3, sticky='we', pady=10)

# https://github.com/python/typeshed/issues/5010
get_dialog_content().bind('<Configure>', (lambda event: cast(None, label.config(wraplength=event.width))), add=True)
get_dialog_content().bind('<Configure>', (lambda event: label.config(wraplength=event.width)), add=True)
return label


Expand All @@ -666,8 +665,7 @@ def panedwindow2settings(junk: object) -> None:
set_(option_name, [panedwindow.sashpos(i) for i in range(len(panedwindow.panes()) - 1)])

# don't know why after_idle is needed, but it is
# https://github.com/python/typeshed/issues/5010
panedwindow.bind('<Map>', (lambda event: cast(None, panedwindow.after_idle(settings2panedwindow))), add=True)
panedwindow.bind('<Map>', (lambda event: panedwindow.after_idle(settings2panedwindow)), add=True)
panedwindow.bind('<<DividersFromSettings>>', settings2panedwindow, add=True)
panedwindow.bind('<ButtonRelease-1>', panedwindow2settings, add=True)

Expand Down
7 changes: 6 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ pytest>=5.4.3
pytest-cov>=2.10.1
isort>=5.7.0
sphinx>=3.0.0, <4.0.0
mypy==0.790
types-toml>=0.1.1
pyflakes>=2.2.0
pycodestyle>=2.6.0
pytest-mock>=3.2.0,<4.0.0
pynsist>=2.6
pillow>=5.4.1
requests>=2.24.0, <3.0.0

# no new mypy releases with mypyc yet, mypy without mypyc is slow
# https://github.com/python/mypy/issues/10116
git+https://github.com/python/mypy.git@2738c73695e2d2f963fbe2a0056329c43a0f6e58; sys_platform != 'linux' or python_version != '3.9'
https://github.com/mypyc/mypy_mypyc-wheels/releases/download/v0.820%2Bdev.497556f466dcda90d850b23e86c55ec4082be3f5/mypy-0.820+dev.497556f466dcda90d850b23e86c55ec4082be3f5-cp39-cp39-manylinux1_x86_64.whl; sys_platform == 'linux' and python_version == '3.9'
2 changes: 1 addition & 1 deletion typeshed
Submodule typeshed updated 1412 files