Various fixes for mypy 0.920
This commit is contained in:
parent
6a657eec33
commit
8f0825bc5c
@ -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
|
return 1 not in responses or 2 not in responses
|
||||||
|
|
||||||
with NamedTemporaryFile() as f:
|
with NamedTemporaryFile() as f:
|
||||||
f.write(b'abcd'), f.flush()
|
f.write(b'abcd')
|
||||||
|
f.flush()
|
||||||
gc = GraphicsCommand()
|
gc = GraphicsCommand()
|
||||||
gc.a = 'q'
|
gc.a = 'q'
|
||||||
gc.s = gc.v = gc.i = 1
|
gc.s = gc.v = gc.i = 1
|
||||||
@ -455,7 +456,8 @@ def process_single_item(
|
|||||||
try:
|
try:
|
||||||
if isinstance(item, bytes):
|
if isinstance(item, bytes):
|
||||||
tf = NamedTemporaryFile(prefix='stdin-image-data-', delete=False)
|
tf = NamedTemporaryFile(prefix='stdin-image-data-', delete=False)
|
||||||
tf.write(item), tf.close()
|
tf.write(item)
|
||||||
|
tf.close()
|
||||||
item = tf.name
|
item = tf.name
|
||||||
is_tempfile = True
|
is_tempfile = True
|
||||||
if url_pat is not None and url_pat.match(item) is not None:
|
if url_pat is not None and url_pat.match(item) is not None:
|
||||||
|
|||||||
@ -113,7 +113,7 @@ class PatchFile(StreamingJob):
|
|||||||
self.overwrite_src = not output_path
|
self.overwrite_src = not output_path
|
||||||
self.src_file = open(src_path, 'rb')
|
self.src_file = open(src_path, 'rb')
|
||||||
if self.overwrite_src:
|
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:
|
else:
|
||||||
self.dest_file = open(output_path, 'wb')
|
self.dest_file = open(output_path, 'wb')
|
||||||
job = begin_patch(self.read_from_src)
|
job = begin_patch(self.read_from_src)
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from functools import partial
|
|||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, Callable, Container, Dict, Iterable, Iterator, List, Optional, Tuple,
|
Any, Callable, Container, Dict, Iterable, Iterator, List, Optional, Tuple,
|
||||||
Union, cast
|
Union
|
||||||
)
|
)
|
||||||
from weakref import WeakValueDictionary
|
from weakref import WeakValueDictionary
|
||||||
|
|
||||||
@ -518,9 +518,8 @@ class Boss:
|
|||||||
opts, items = parse_subcommand_cli(c, items)
|
opts, items = parse_subcommand_cli(c, items)
|
||||||
payload = c.message_to_kitty(global_opts, opts, items)
|
payload = c.message_to_kitty(global_opts, opts, items)
|
||||||
import types
|
import types
|
||||||
if isinstance(cast(types.GeneratorType, payload), types.GeneratorType):
|
if isinstance(payload, types.GeneratorType):
|
||||||
payloads = cast(types.GeneratorType, payload)
|
for x in payload:
|
||||||
for x in payloads:
|
|
||||||
c.response_from_kitty(self, self.active_window, PayloadGetter(c, x if isinstance(x, dict) else {}))
|
c.response_from_kitty(self, self.active_window, PayloadGetter(c, x if isinstance(x, dict) else {}))
|
||||||
else:
|
else:
|
||||||
c.response_from_kitty(self, self.active_window, PayloadGetter(c, payload if isinstance(payload, dict) else {}))
|
c.response_from_kitty(self, self.active_window, PayloadGetter(c, payload if isinstance(payload, dict) else {}))
|
||||||
|
|||||||
@ -110,7 +110,7 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]:
|
|||||||
else:
|
else:
|
||||||
func, typ = option_type_data(option)
|
func, typ = option_type_data(option)
|
||||||
try:
|
try:
|
||||||
params = inspect.signature(func).parameters
|
params = dict(inspect.signature(func).parameters)
|
||||||
except Exception:
|
except Exception:
|
||||||
params = {}
|
params = {}
|
||||||
if 'dict_with_parse_results' in params:
|
if 'dict_with_parse_results' in params:
|
||||||
|
|||||||
@ -210,7 +210,7 @@ def parse_launch_args(args: Optional[Sequence[str]] = None) -> LaunchSpec:
|
|||||||
return LaunchSpec(opts, args)
|
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] = {}
|
env: Dict[str, str] = {}
|
||||||
if opts.copy_env and active_child:
|
if opts.copy_env and active_child:
|
||||||
env.update(active_child.foreground_environ)
|
env.update(active_child.foreground_environ)
|
||||||
@ -308,7 +308,10 @@ def launch(
|
|||||||
force_target_tab: bool = False
|
force_target_tab: bool = False
|
||||||
) -> Optional[Window]:
|
) -> Optional[Window]:
|
||||||
active = boss.active_window_for_cwd
|
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)
|
env = get_env(opts, active_child)
|
||||||
kw: LaunchKwds = {
|
kw: LaunchKwds = {
|
||||||
'allow_remote_control': opts.allow_remote_control,
|
'allow_remote_control': opts.allow_remote_control,
|
||||||
|
|||||||
@ -39,7 +39,7 @@ from .notify import NotificationCommand, handle_notification_cmd
|
|||||||
from .options.types import Options
|
from .options.types import Options
|
||||||
from .rgb import to_color
|
from .rgb import to_color
|
||||||
from .terminfo import get_capabilities
|
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 .typing import BossType, ChildType, EdgeLiteral, TabType, TypedDict
|
||||||
from .utils import (
|
from .utils import (
|
||||||
get_primary_selection, load_shaders, log_error, open_cmd, open_url,
|
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:
|
if TYPE_CHECKING:
|
||||||
|
import re
|
||||||
|
|
||||||
from .file_transmission import FileTransmission
|
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]:
|
@run_once
|
||||||
pat = getattr(text_sanitizer, 'pat', None)
|
def text_sanitizer_pat() -> 're.Pattern[str]':
|
||||||
if pat is None:
|
import re
|
||||||
import re
|
return re.compile('\033\\[.*?m')
|
||||||
pat = re.compile('\033\\[.*?m')
|
|
||||||
setattr(text_sanitizer, 'pat', pat)
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
ansi, wrap_markers = not as_ansi, not add_wrap_markers
|
||||||
|
|
||||||
def remove_wrap_markers(line: str) -> str:
|
def remove_wrap_markers(line: str) -> str:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user