File: _get_args.py

package info (click to toggle)
python-typish 1.9.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: python: 1,636; makefile: 2
file content (18 lines) | stat: -rw-r--r-- 510 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import typing


def get_args(t: type) -> typing.Tuple[type, ...]:
    """
    Get the arguments from a collection type (e.g. ``typing.List[int]``) as a
    ``tuple``.
    :param t: the collection type.
    :return: a ``tuple`` containing types.
    """
    args_ = getattr(t, '__args__', tuple())
    if not args_:
        args_= tuple()
    elif not isinstance(args_,tuple):
        args_ = (args_,)
    args = tuple([attr for attr in args_
                  if type(attr) != typing.TypeVar])
    return args