Various fixes for mypy 0.920

This commit is contained in:
Kovid Goyal 2021-12-17 05:41:27 +05:30
parent 6a657eec33
commit 8f0825bc5c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 24 additions and 17 deletions

View File

@ -389,7 +389,8 @@ def detect_support(wait_for: float = 10, silent: bool = False) -> bool:
return 1 not in responses or 2 not in responses
with NamedTemporaryFile() as f:
f.write(b'abcd'), f.flush()
f.write(b'abcd')
f.flush()
gc = GraphicsCommand()
gc.a = 'q'
gc.s = gc.v = gc.i = 1
@ -455,7 +456,8 @@ def process_single_item(
try:
if isinstance(item, bytes):
tf = NamedTemporaryFile(prefix='stdin-image-data-', delete=False)
tf.write(item), tf.close()
tf.write(item)
tf.close()
item = tf.name
is_tempfile = True
if url_pat is not None and url_pat.match(item) is not None:

View File

@ -113,7 +113,7 @@ class PatchFile(StreamingJob):
self.overwrite_src = not output_path
self.src_file = open(src_path, 'rb')
if self.overwrite_src:
self.dest_file = tempfile.NamedTemporaryFile(mode='wb', dir=os.path.dirname(os.path.abspath(os.path.realpath(src_path))), delete=False)
self.dest_file: IO[bytes] = tempfile.NamedTemporaryFile(mode='wb', dir=os.path.dirname(os.path.abspath(os.path.realpath(src_path))), delete=False)
else:
self.dest_file = open(output_path, 'wb')
job = begin_patch(self.read_from_src)

View File

@ -10,7 +10,7 @@ from functools import partial
from gettext import gettext as _
from typing import (
Any, Callable, Container, Dict, Iterable, Iterator, List, Optional, Tuple,
Union, cast
Union
)
from weakref import WeakValueDictionary
@ -518,9 +518,8 @@ class Boss:
opts, items = parse_subcommand_cli(c, items)
payload = c.message_to_kitty(global_opts, opts, items)
import types
if isinstance(cast(types.GeneratorType, payload), types.GeneratorType):
payloads = cast(types.GeneratorType, payload)
for x in payloads:
if isinstance(payload, types.GeneratorType):
for x in payload:
c.response_from_kitty(self, self.active_window, PayloadGetter(c, x if isinstance(x, dict) else {}))
else:
c.response_from_kitty(self, self.active_window, PayloadGetter(c, payload if isinstance(payload, dict) else {}))

View File

@ -110,7 +110,7 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]:
else:
func, typ = option_type_data(option)
try:
params = inspect.signature(func).parameters
params = dict(inspect.signature(func).parameters)
except Exception:
params = {}
if 'dict_with_parse_results' in params:

View File

@ -210,7 +210,7 @@ def parse_launch_args(args: Optional[Sequence[str]] = None) -> LaunchSpec:
return LaunchSpec(opts, args)
def get_env(opts: LaunchCLIOptions, active_child: Child) -> Dict[str, str]:
def get_env(opts: LaunchCLIOptions, active_child: Optional[Child]) -> Dict[str, str]:
env: Dict[str, str] = {}
if opts.copy_env and active_child:
env.update(active_child.foreground_environ)
@ -308,7 +308,10 @@ def launch(
force_target_tab: bool = False
) -> Optional[Window]:
active = boss.active_window_for_cwd
active_child = getattr(active, 'child', None)
if active:
active_child = active.child
else:
active_child = None
env = get_env(opts, active_child)
kw: LaunchKwds = {
'allow_remote_control': opts.allow_remote_control,

View File

@ -39,7 +39,7 @@ from .notify import NotificationCommand, handle_notification_cmd
from .options.types import Options
from .rgb import to_color
from .terminfo import get_capabilities
from .types import MouseEvent, WindowGeometry, ac
from .types import MouseEvent, WindowGeometry, ac, run_once
from .typing import BossType, ChildType, EdgeLiteral, TabType, TypedDict
from .utils import (
get_primary_selection, load_shaders, log_error, open_cmd, open_url,
@ -50,6 +50,8 @@ MatchPatternType = Union[Pattern[str], Tuple[Pattern[str], Optional[Pattern[str]
if TYPE_CHECKING:
import re
from .file_transmission import FileTransmission
@ -264,13 +266,14 @@ def setup_colors(screen: Screen, opts: Options) -> None:
)
def text_sanitizer(as_ansi: bool, add_wrap_markers: bool) -> Callable[[str], str]:
pat = getattr(text_sanitizer, 'pat', None)
if pat is None:
import re
pat = re.compile('\033\\[.*?m')
setattr(text_sanitizer, 'pat', pat)
@run_once
def text_sanitizer_pat() -> 're.Pattern[str]':
import re
return re.compile('\033\\[.*?m')
def text_sanitizer(as_ansi: bool, add_wrap_markers: bool) -> Callable[[str], str]:
pat = text_sanitizer_pat()
ansi, wrap_markers = not as_ansi, not add_wrap_markers
def remove_wrap_markers(line: str) -> str: