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
16 changes: 6 additions & 10 deletions sublime_lib/_util/collections.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
from __future__ import annotations
from collections.abc import Iterable
from collections.abc import Iterable, Mapping
from typing import Callable, TypeVar


_V = TypeVar('_V')

__all__ = ['projection', 'get_selector']


def projection(
d: dict[str, _V],
keys: dict[str, str] | Iterable[str]
) -> dict[str, _V]:
def projection(d: Mapping[str, _V], keys: Mapping[str, str] | Iterable[str]) -> Mapping[str, _V]:
"""
Return a new :class:`dict` with keys of ``d`` restricted to values in ``keys``.
Return a new :class:`Mapping` with keys of ``d`` restricted to values in ``keys``.

.. code-block:: python

>>> projection({'a': 1, 'b': 2}, ['b'])
{'b': 2}

If ``keys`` is a :class:`dict`, then it maps keys of the original dict to
If ``keys`` is a :class:`Mapping`, then it maps keys of the original Mapping to
keys of the result:

.. code-block:: python

>>> projection({'a': 1, 'b': 2}, {'b': 'c'})
{'c': 2}
"""
if isinstance(keys, dict):
if isinstance(keys, Mapping):
return {
new_key: d[original_key]
for original_key, new_key in keys.items()
Expand All @@ -42,7 +38,7 @@ def projection(
}


def get_selector(selector: object, default_value: object = None) -> Callable: # noqa: F811
def get_selector(selector: object, default_value: object = None) -> Callable:
if callable(selector):
return selector
elif isinstance(selector, str):
Expand Down
4 changes: 2 additions & 2 deletions sublime_lib/encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def to_sublime(name: str) -> str:
raise ValueError("Unknown Python encoding {!r}.".format(name)) from None


SUBLIME_TO_STANDARD = { # noqa: E121
SUBLIME_TO_STANDARD = {
"UTF-8": "utf-8",
"UTF-8 with BOM": "utf-8-sig",
"UTF-16 LE": "utf-16-le",
Expand Down Expand Up @@ -85,7 +85,7 @@ def to_sublime(name: str) -> str:
}


STANDARD_TO_SUBLIME = { # noqa: E121
STANDARD_TO_SUBLIME = {
standard_name: sublime_name
for sublime_name, standard_name in SUBLIME_TO_STANDARD.items()
}
Expand Down
2 changes: 1 addition & 1 deletion sublime_lib/resource_path.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations
from abc import ABCMeta, abstractmethod
from collections import OrderedDict
from collections.abc import Iterable
from pathlib import Path
from typing import Iterable

import os
import posixpath
Expand Down
4 changes: 2 additions & 2 deletions sublime_lib/settings_dict.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import annotations
from collections.abc import Mapping
from functools import partial
from typing import TYPE_CHECKING
from uuid import uuid4
Expand All @@ -12,7 +11,8 @@
__all__ = ['SettingsDict', 'NamedSettingsDict']

if TYPE_CHECKING:
from typing import Any, Callable, Iterable
from collections.abc import Iterable, Mapping
from typing import Any, Callable
from typing_extensions import TypeAlias

Value: TypeAlias = bool | str | int | float | list[Any] | dict[str, Any] | None
Expand Down
11 changes: 6 additions & 5 deletions sublime_lib/show_selection_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def show_selection_panel(
flags: QuickPanelOption = QuickPanelOption.NONE,
labels: Sequence[object] | Callable[[_ItemType], object] | None = None,
selected: NamedValue | _ItemType = NO_SELECTION,
on_select: Callable[[_ItemType], object] | None = None,
on_cancel: Callable[[], object] | None = None,
on_highlight: Callable[[_ItemType], object] | None = None
on_select: Callable[[_ItemType], None] | None = None,
on_cancel: Callable[[], None] | None = None,
on_highlight: Callable[[_ItemType], None] | None = None
) -> None:
"""Open a quick panel in the given window to select an item from a list.

Expand Down Expand Up @@ -113,7 +113,8 @@ def on_done(index: int) -> None:
else:
selected_index = items.index(selected)

on_highlight_callback = lambda index: on_highlight(items[index]) if on_highlight else None
on_highlight_callback: Callable[[int], None] = \
lambda index: on_highlight(items[index]) if on_highlight else None

if isinstance(flags, str):
flags = QuickPanelOption(flags)
Expand All @@ -127,5 +128,5 @@ def on_done(index: int) -> None:
on_select=on_done,
flags=flags, # type: ignore
selected_index=selected_index,
on_highlight=on_highlight_callback # type: ignore
on_highlight=on_highlight_callback
)
3 changes: 2 additions & 1 deletion sublime_lib/view_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any, Generator, Iterable, TypeVar
from collections.abc import Generator, Iterable
from typing import Any, TypeVar
from sublime_types import Value

EnumType = TypeVar('EnumType', bound=Enum)
Expand Down
Loading