File: util.py

package info (click to toggle)
python-pynvim 0.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 424 kB
  • sloc: python: 3,067; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 925 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Shared utility functions."""

import sys
from traceback import format_exception
from typing import Any, Dict, Optional, Tuple, TypeVar

from pynvim._version import VERSION


def format_exc_skip(skip: int, limit: Optional[int] = None) -> str:
    """Like traceback.format_exc but allow skipping the first frames."""
    etype, val, tb = sys.exc_info()
    for _ in range(skip):
        if tb is not None:
            tb = tb.tb_next
    return ("".join(format_exception(etype, val, tb, limit))).rstrip()


T1 = TypeVar("T1")
T2 = TypeVar("T2")


def get_client_info(
    kind: str, type_: T1, method_spec: T2
) -> Tuple[str, Dict[str, Any], T1, T2, Dict[str, str]]:
    """Returns a tuple describing the client."""
    name = "python{}-{}".format(sys.version_info[0], kind)
    attributes = {"license": "Apache v2", "website": "github.com/neovim/pynvim"}
    return (name, VERSION.__dict__, type_, method_spec, attributes)