mypyの可変長な引数と戻り値の型の書き方

可変長引数

import typing as t
import mypy_extensions as mx

def f0() -> t.List[int]:
    return []


def f1(x0: int) -> t.List[int]:
    return [x0]


def f2(x0: int, x1: int) -> t.List[int]:
    return [x0, x1]


def fN(*xs: int) -> t.List[int]:
    return list(xs)

Callableの方ではVarArgを使う。

import typing as t
import mypy_extensions as mx

def g(f: t.Callable[[mx.VarArg(int)], t.List[int]], *xs: int) -> t.List[int]:
    return f(*xs)

可変長な戻り値

tupleが以下なので

import typing as t

x0 = ()  # type: t.Tuple
x1 = (1, )  # type: t.Tuple[int]
x2 = (1, 2)  # type: t.Tuple[int, int]

y0 = ()  # type: t.Tuple[int, ...]
y1 = (1, )  # type: t.Tuple[int, ...]
y2 = (1, 2)  # type: t.Tuple[int, ...]

関数の戻り値のときも同様に。

def h0(x: int) -> t.Tuple:
    return ()


def h1(x: int) -> t.Tuple[int, ]:
    return (x, )


def h2(x: int) -> t.Tuple[int, int]:
    return (x, x)


def hN(x: int) -> t.Tuple[int, ...]:
    return (x, x, x, x)

ちなみにtupleとlistを区別したくない場合にはSequenceを使う

def kN(x: int) -> t.Sequence[int]:
    return (x, x, x, x)


def kM(x: int) -> t.Sequence[int]:
    return [x, x, x, x]

参考

python-environment.elを使うのにvirtualenvを不要にする

python-environment.elというelispが、jediなどをemacsで使おうとした時に使われます (正確に言うと、emacs上でepc(emacs用のrpc) serverをつかったjediのinterfaceをインストールした際に使われる) 。

このpython-environment.elですが、python2.x系のことも考慮してだと思うのですが、defaultでは環境の隔離にvirtualenvを使います。python3.xのみの環境であれば標準でvenvが使えるのでそちらを使うように設定を変えます。

(require 'python-environment)
(custom-set-variables
 '(python-environment-virtualenv (list "python" "-m" "venv" "--system-site-packages")))

ちなみに、--system-site-packages は付けなくても上手く動作するとは思います(隔離された環境内でデフォルト環境でインストールされたパッケージをそのまま使いたいかどうかという話です)。