Upgrade mypy

This commit is contained in:
Anthony Sottile
2019-09-28 06:57:29 -07:00
parent acccee3760
commit 1d6d6a4883
2 changed files with 16 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3 rev: v2.3.0
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
- id: end-of-file-fixer - id: end-of-file-fixer
@@ -19,7 +19,7 @@ repos:
hooks: hooks:
- id: autopep8 - id: autopep8
- repo: https://github.com/asottile/reorder_python_imports - repo: https://github.com/asottile/reorder_python_imports
rev: v1.6.0 rev: v1.7.0
hooks: hooks:
- id: reorder-python-imports - id: reorder-python-imports
args: [--py3-plus] args: [--py3-plus]
@@ -29,11 +29,11 @@ repos:
- id: add-trailing-comma - id: add-trailing-comma
args: [--py36-plus] args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v1.21.0 rev: v1.24.0
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: [--py36-plus] args: [--py36-plus]
- repo: https://github.com/pre-commit/mirrors-mypy - repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.711 rev: v0.730
hooks: hooks:
- id: mypy - id: mypy

26
babi.py
View File

@@ -1,4 +1,3 @@
import _curses
import argparse import argparse
import collections import collections
import contextlib import contextlib
@@ -34,7 +33,7 @@ class Margin(NamedTuple):
return self.body_lines - 2 return self.body_lines - 2
@classmethod @classmethod
def from_screen(cls, screen: '_curses._CursesWindow') -> 'Margin': def from_screen(cls, screen: 'curses._CursesWindow') -> 'Margin':
if curses.LINES == 1: if curses.LINES == 1:
return cls(header=False, footer=False) return cls(header=False, footer=False)
elif curses.LINES == 2: elif curses.LINES == 2:
@@ -159,7 +158,7 @@ class Position:
def move_cursor( def move_cursor(
self, self,
stdscr: '_curses._CursesWindow', stdscr: 'curses._CursesWindow',
margin: Margin, margin: Margin,
) -> None: ) -> None:
stdscr.move(self.cursor_y(margin), self.cursor_x()) stdscr.move(self.cursor_y(margin), self.cursor_x())
@@ -180,8 +179,7 @@ del _get_color_pair_mapping
def _has_colors() -> bool: def _has_colors() -> bool:
# https://github.com/python/typeshed/pull/3115 return curses.has_colors and curses.COLORS >= 16
return curses.has_colors and curses.COLORS >= 16 # type: ignore
def _color(fg: int, bg: int) -> int: def _color(fg: int, bg: int) -> int:
@@ -197,7 +195,7 @@ def _color(fg: int, bg: int) -> int:
return curses.color_pair(0) return curses.color_pair(0)
def _init_colors(stdscr: '_curses._CursesWindow') -> None: def _init_colors(stdscr: 'curses._CursesWindow') -> None:
curses.use_default_colors() curses.use_default_colors()
if not _has_colors(): if not _has_colors():
return return
@@ -211,7 +209,7 @@ class Header:
def __init__(self, file: 'File') -> None: def __init__(self, file: 'File') -> None:
self.file = file self.file = file
def draw(self, stdscr: '_curses._CursesWindow') -> None: def draw(self, stdscr: 'curses._CursesWindow') -> None:
filename = self.file.filename or '<<new file>>' filename = self.file.filename or '<<new file>>'
if self.file.modified: if self.file.modified:
filename += ' *' filename += ' *'
@@ -233,7 +231,7 @@ class Status:
else: else:
self._action_counter = 1 self._action_counter = 1
def draw(self, stdscr: '_curses._CursesWindow', margin: Margin) -> None: def draw(self, stdscr: 'curses._CursesWindow', margin: Margin) -> None:
if margin.footer or self._status: if margin.footer or self._status:
stdscr.insstr(curses.LINES - 1, 0, ' ' * curses.COLS) stdscr.insstr(curses.LINES - 1, 0, ' ' * curses.COLS)
if self._status: if self._status:
@@ -345,7 +343,7 @@ class File:
_restore_lines_eof_invariant(self.lines) _restore_lines_eof_invariant(self.lines)
def _color_test(stdscr: '_curses._CursesWindow') -> None: def _color_test(stdscr: 'curses._CursesWindow') -> None:
Header(File('<<color test>>')).draw(stdscr) Header(File('<<color test>>')).draw(stdscr)
maxy, maxx = stdscr.getmaxyx() maxy, maxx = stdscr.getmaxyx()
@@ -367,7 +365,7 @@ def _color_test(stdscr: '_curses._CursesWindow') -> None:
def _write_lines( def _write_lines(
stdscr: '_curses._CursesWindow', stdscr: 'curses._CursesWindow',
pos: Position, pos: Position,
margin: Margin, margin: Margin,
lines: List[str], lines: List[str],
@@ -422,7 +420,7 @@ def _get_lines(sio: IO[str]) -> Tuple[List[str], str, bool]:
EditResult = enum.Enum('EditResult', 'EXIT NEXT PREV') EditResult = enum.Enum('EditResult', 'EXIT NEXT PREV')
def _edit(stdscr: '_curses._CursesWindow', file: File) -> EditResult: def _edit(stdscr: 'curses._CursesWindow', file: File) -> EditResult:
margin = Margin.from_screen(stdscr) margin = Margin.from_screen(stdscr)
status = Status() status = Status()
file.ensure_loaded(status, margin) file.ensure_loaded(status, margin)
@@ -468,7 +466,7 @@ def _edit(stdscr: '_curses._CursesWindow', file: File) -> EditResult:
status.update(f'unknown key: {keyname} ({key})', margin) status.update(f'unknown key: {keyname} ({key})', margin)
def _init_screen() -> '_curses._CursesWindow': def _init_screen() -> 'curses._CursesWindow':
stdscr = curses.initscr() stdscr = curses.initscr()
curses.noecho() curses.noecho()
curses.cbreak() curses.cbreak()
@@ -483,7 +481,7 @@ def _init_screen() -> '_curses._CursesWindow':
return stdscr return stdscr
def c_main(stdscr: '_curses._CursesWindow', args: argparse.Namespace) -> None: def c_main(stdscr: 'curses._CursesWindow', args: argparse.Namespace) -> None:
if args.color_test: if args.color_test:
return _color_test(stdscr) return _color_test(stdscr)
files = [File(filename) for filename in args.filenames or [None]] files = [File(filename) for filename in args.filenames or [None]]
@@ -503,7 +501,7 @@ def c_main(stdscr: '_curses._CursesWindow', args: argparse.Namespace) -> None:
@contextlib.contextmanager @contextlib.contextmanager
def make_stdscr() -> Generator['_curses._CursesWindow', None, None]: def make_stdscr() -> Generator['curses._CursesWindow', None, None]:
"""essentially `curses.wrapper` but split out to implement ^Z""" """essentially `curses.wrapper` but split out to implement ^Z"""
stdscr = _init_screen() stdscr = _init_screen()
try: try: