Python version independent function to obtain the parameters
    of a typing.Tuple object.
    Omits the ellipsis argument if present. Use is_Tuple_ellipsis for that.
    Tested with CPython 2.7, 3.5, 3.6 and Jython 2.7.1.
768399
def get_Tuple_params(tpl):
    
    try:
        return tpl.__tuple_params__
    except AttributeError:
        try:
            if tpl.__args__ is None:
                return None
            # Python 3.6
            if tpl.__args__[0] == ():
                return ()
            else:
                if tpl.__args__[-1] is Ellipsis:
                    return tpl.__args__[:-1] if len(tpl.__args__) > 1 else None
                else:
                    return tpl.__args__
        except AttributeError:
            return None
1141727
def _ctypes_dtype(parameter):
    
    ctype = parameter.ctype
    if ctype is None:
        if parameter.kind is not None:
            return "{}({})".format(parameter.dtype, parameter.kind)
        else:
            return parameter.dtype
    else:
        return"{}({})".format(parameter.dtype, ctype)
885269
def is_tuple(type_: Type[Any]) -> bool:
    '''
    
    '''
    if HAS_TUPLEARGS:
        # The tuple, Tuple thing is a difference between 3.6 and 3.7
        # In 3.6 and before, Tuple had an __extra__ field, while Tuple[something]
        # would have the normal __origin__ field.
        #
        # Those apply for Dict, List, Set, Tuple
        return _generic_type_check(type_, tuple, Tuple)
    else:
        # Old python
        return _issubclass(type_, Tuple) and _issubclass(type_, tuple) == False
602633
def ensure_unicode_args(function):
    '''
    
    '''
    @wraps(function)
    def wrapped(*args, **kwargs):
        if six.PY2:
            return function(
                *salt.utils.data.decode_list(args),
                **salt.utils.data.decode_dict(kwargs)
            )
        else:
            return function(*args, **kwargs)
    return wrapped
854041
def p_function_expr_2(self, p):
        
        if len(p) == 8:
            p[0] = self.asttypes.FuncExpr(
                identifier=p[2], parameters=None, elements=p[6])
        else:
            p[0] = self.asttypes.FuncExpr(
                identifier=p[2], parameters=p[4], elements=p[7])
        p[0].setpos(p)
437958
function _Type(
    type,       // :: String
    name,       // :: String
    url,        // :: String
    arity,      // :: NonNegativeInteger
    format,
    // :: Nullable ((String -> String, String -> String -> String) -> String)
    supertypes, // :: Array Type
    test,       // :: Any -> Boolean
    tuples      // :: Array (Array3 String (a -> Array b) Type)
  ) {
    var t = Object.create (Type$prototype);
    t._test = test;
    t._extractors = tuples.reduce (function(_extractors, tuple) {
      _extractors[tuple[0]] = tuple[1];
      return _extractors;
    }, {});
    t.arity = arity;  // number of type parameters
    t.extractors = Z.map (B (toArray), t._extractors);
    t.format = format || function(outer, inner) {
      return Z.reduce (function(s, tuple) {
        return s +
               outer (' ') +
               when (tuple[2].arity > 0)
                    (parenthesize (outer))
                    (inner (tuple[0]) (show (tuple[2])));
      }, outer (name), tuples);
    };
    t.keys = tuples.map (function(tuple) { return tuple[0]; });
    t.name = name;
    t.supertypes = supertypes;
    t.type = type;
    t.types = tuples.reduce (function(types, tuple) {
      types[tuple[0]] = tuple[2];
      return types;
    }, {});
    t.url = url;
    return t;
  }
759206
def _function_signature(func):
    
    if sys.version_info.major > 2:
        # Python 3 already implements this functionality
        return func.__name__ + str(inspect.signature(func))

    # In Python 2 we have to do it manually, unfortunately
    spec = inspect.getargspec(func)
    posargs = spec.args
    defaults = spec.defaults if spec.defaults is not None else []
    varargs = spec.varargs
    kwargs = spec.keywords
    deflen = 0 if defaults is None else len(defaults)
    nodeflen = 0 if posargs is None else len(posargs) - deflen

    args = ['{}'.format(arg) for arg in posargs[:nodeflen]]
    args.extend('{}={}'.format(arg, dval)
                for arg, dval in zip(posargs[nodeflen:], defaults))
    if varargs:
        args.append('*{}'.format(varargs))
    if kwargs:
        args.append('**{}'.format(kwargs))

    argstr = ', '.join(args)

    return '{}({})'.format(func.__name__, argstr)
1246825
def infer_typing_namedtuple(node, context=None):
    """"""
    # This is essentially a namedtuple with different arguments
    # so we extract the args and infer a named tuple.
    try:
        func = next(node.func.infer())
    except InferenceError:
        raise UseInferenceDefault

    if func.qname() != "typing.NamedTuple":
        raise UseInferenceDefault

    if len(node.args) != 2:
        raise UseInferenceDefault

    if not isinstance(node.args[1], (nodes.List, nodes.Tuple)):
        raise UseInferenceDefault

    names = []
    for elt in node.args[1].elts:
        if not isinstance(elt, (nodes.List, nodes.Tuple)):
            raise UseInferenceDefault
        if len(elt.elts) != 2:
            raise UseInferenceDefault
        names.append(elt.elts[0].as_string())

    typename = node.args[0].as_string()
    if names:
        field_names = "({},)".format(",".join(names))
    else:
        field_names = "''"
    node = extract_node(
        "namedtuple({typename}, {fields})".format(typename=typename, fields=field_names)
    )
    return infer_named_tuple(node, context)
433063
def get_arg_type_descriptors(self):
        

        if not self.is_method:
            return tuple()

        tp = _typeseq(self.get_descriptor())
        tp = _typeseq(tp[0][1:-1])

        return tp
882693
def params(self):
        
        def fmt_param(el):
            if isinstance(el, str) or isinstance(el, unicode):
                return el
            else:
                return '(%s)' % (', '.join(map(fmt_param, el)))
        try:
            getspec = getattr(inspect, 'getfullargspec', inspect.getargspec)
            s = getspec(self.func)
        except TypeError:
            # I guess this is for C builtin functions?
            return ['...']

        params = []
        for i, param in enumerate(s.args):
            if param.lower() == 'self':
                continue
            if s.defaults is not None and len(s.args) - i <= len(s.defaults):
                defind = len(s.defaults) - (len(s.args) - i)
                default_value = s.defaults[defind]
                value = repr(default_value).strip()
                if value[0] == '<' and value[-1] == '>':
                    if type(default_value) == types.TypeType:
                        value = default_value.__name__
                    elif type(default_value) == types.ObjectType:
                        value = '%s()'%(default_value.__class__.__name__)
                params.append('%s=%s' % (param, value))
            else:
                params.append(fmt_param(param))
        if s.varargs is not None:
            params.append('*%s' % s.varargs)

        # TODO: This needs to be adjusted in Python 3. There's more stuff
        #       returned from getfullargspec than what we're looking at here.
        keywords = getattr(s, 'varkw', getattr(s, 'keywords', None))
        if keywords is not None:
            params.append('**%s' % keywords)
        return params
1194171
def ensure_tuple(obj):
    """"""
    if obj is None:
        return tuple()
    if isinstance(obj, Iterable) and not isinstance(obj, six.string_types):
        return tuple(obj)
    return obj,
148624
def is_base_tuple(type_str):
    
    try:
        abi_type = grammar.parse(type_str)
    except exceptions.ParseError:
        return False

    return isinstance(abi_type, grammar.TupleType) and abi_type.arrlist is None
378152
def get_tuple(nuplet, index, default=None):
    
    if nuplet is None:
        return default
    try:
        return nuplet[index]
    except IndexError:
        return default
1244128
def validate_conversion_arguments(to_wrap):
    

    @functools.wraps(to_wrap)
    def wrapper(*args, **kwargs):
        _assert_one_val(*args, **kwargs)
        if kwargs:
            _validate_supported_kwarg(kwargs)

        if len(args) == 0 and "primitive" not in kwargs:
            _assert_hexstr_or_text_kwarg_is_text_type(**kwargs)
        return to_wrap(*args, **kwargs)

    return wrapper
630296
def tuplify(*args):
    
    if (len(args) == 1) and callable(args[0]):
        func = args[0]

        @wraps(func)
        def _inner(*args, **kwargs):
            return tuple(func(*args, **kwargs))
        return _inner
    else:
        return tuple(args)
783260
def kwargs_only(func):
    
    if hasattr(inspect, 'signature'):  # pragma: no cover
        # Python 3
        signature = inspect.signature(func)
        first_arg_name = list(signature.parameters.keys())[0]
    else:  # pragma: no cover
        # Python 2
        signature = inspect.getargspec(func)
        first_arg_name = signature.args[0]

    if first_arg_name in ('self', 'cls'):
        allowable_args = 1
    else:
        allowable_args = 0

    @wraps(func)
    def wrapper(*args, **kwargs):
        if len(args) > allowable_args:
            raise TypeError("{} should only be called with keyword args".format(func.__name__))
        return func(*args, **kwargs)

    return wrapper
97520
def get_init_args(inst_type, init_args: dict, add_kwargs=False) -> Tuple[List, Dict]:
    ''''''
    try:
        parameters = signature(inst_type).parameters.values()
        args_keys = [p.name for p in parameters \
                if p.kind in [Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD] \
                and p.default == Parameter.empty]
        args = [init_args[key] for key in args_keys]
        kwargs = _get_var_kwargs(parameters, args_keys, init_args)\
                 if add_kwargs else\
                 _get_kwargs(parameters, init_args)
    except KeyError as key_error:
        msg_format = 'parameter with key "{0}" is not found in node args'
        raise RenderingError(msg_format.format(key_error.args[0]))
    return (args, kwargs)