Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions sublime_lib/_util/collections.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations
from collections.abc import Mapping, Sequence
from typing import Callable, Iterable, TypeVar
from collections.abc import Iterable
from typing import Callable, TypeVar


_V = TypeVar('_V')

__all__ = ['projection', 'get_selector', 'isiterable', 'ismapping', 'is_sequence_not_str']
__all__ = ['projection', 'get_selector']


def projection(
Expand Down Expand Up @@ -47,25 +47,9 @@ def get_selector(selector: object, default_value: object = None) -> Callable: #
return selector
elif isinstance(selector, str):
return lambda this: this.get(selector, default_value)
elif isiterable(selector):
elif isinstance(selector, Iterable):
return lambda this: projection(this, selector) # type: ignore
else:
raise TypeError(
'The selector should be a function, string, or iterable of strings.'
)


def isiterable(obj: object) -> bool:
try:
iter(obj) # type: ignore
return True
except TypeError:
return False


def ismapping(obj: object) -> bool:
return isinstance(obj, Mapping)


def is_sequence_not_str(obj: object) -> bool:
return isinstance(obj, Sequence) and not isinstance(obj, str)
7 changes: 3 additions & 4 deletions sublime_lib/show_selection_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import sublime

from ._util.collections import isiterable
from ._util.named_value import NamedValue
from .flags import QuickPanelOption

Expand Down Expand Up @@ -116,10 +115,10 @@ def on_done(index: int) -> None:

on_highlight_callback = lambda index: on_highlight(items[index]) if on_highlight else None

if isiterable(flags) and not isinstance(flags, str):
flags = QuickPanelOption(*flags)
else:
if isinstance(flags, str):
flags = QuickPanelOption(flags)
else:
flags = QuickPanelOption(*flags)

# The signature in the API docs is wrong.
# See https://github.com/SublimeTextIssues/Core/issues/2290
Expand Down
Loading