take a BaseX descendant from sqparse2, return a type class from above
170178
def expression_type(con, topx, ex):
  ""
  if isinstance(ex,sqparse2.Literal):
    if isinstance(ex.val,basestring): return STRING
    else: raise NotImplementedError('literal', type(ex.val))
  elif isinstance(ex,sqparse2.AttrX):
    if ex.parent.name in con.db: # warning: what if it's not a table? what if it's aliased?
      return expression_type(con, topx, con.db[ex.parent.name].get_column(ex.attr.name).coltp)
    else:
      raise NotImplementedError(ex.parent)
  elif isinstance(ex,sqparse2.TypeX):
    return dict(
      integer=NUMBER,
      text=STRING,
    )[ex.type.lower()]
  else:
    raise NotImplementedError('unk type', type(ex))
772058
def fromType(datatype):
        
        if issubclass(datatype, GPBaseType):
            return GPBaseType._get_type_by_name("GPMultiValue:%s" % 
                                                datatype.__name__)
        else:
            return GPBaseType._get_type_by_name("GPMultiValue:%s" % 
                                                str(datatype))
86895
def base_type
      n = NodeCache.find(attributes["type"])
      n.is_a?(Type) ? n.base_type : n
    end
1198005
def from_expr(cls, expr):
        """"""
        return cls(expr.args, expr.kwargs, cls=expr.__class__)
812843
function typeInAncestry(type, input) {
	return ancestry(input)
		.reduce((carry, obj) => carry || Type.objectName(obj) === type, false);
}
852218
def _recognize_basic_types(s):
    
    tps = [int, float]
    if not six.PY3:  # compat for older versions of six that don't have PY2
        tps.append(long)
    for tp in tps:
        try:
            return tp(s)
        except ValueError:
            pass
    if s.lower() == 'true':
        return True
    if s.lower() == 'false':
        return False
    if s.lower() in ['none', 'null']:
        return None

    return s
1052074
def normalize_type(type_, level=0):
    
    if not typing or not isinstance(type_, typing.TypingMeta) or type_ is AnyType:
        return type_
    if isinstance(type_, typing.TypeVar):
        if type_.__constraints__ or type_.__bound__:
            return type_
        else:
            return AnyType
    if issubclass(type_, typing.Union):
        if not type_.__union_params__:
            raise OverloadingError("typing.Union must be parameterized")
        return typing.Union[tuple(normalize_type(t, level) for t in type_.__union_params__)]
    if issubclass(type_, typing.Tuple):
        params = type_.__tuple_params__
        if level > 0 or params is None:
            return typing.Tuple
        elif type_.__tuple_use_ellipsis__:
            return typing.Tuple[normalize_type(params[0], level + 1), ...]
        else:
            return typing.Tuple[tuple(normalize_type(t, level + 1) for t in params)]
    if issubclass(type_, typing.Callable):
        return typing.Callable
    if isinstance(type_, typing.GenericMeta):
        base = find_base_generic(type_)
        if base is typing.Generic:
            return type_
        else:
            return GenericWrapper(type_, base, level > 0)
    raise OverloadingError("%r not supported yet" % type_)
558056
def from_fromx(class_, tables, fromx, ctes=()):
    
    if ctes: raise NotImplementedError # note: I don't think any other part of the program supports CTEs yet either
    scope_ = class_(fromx)
    for exp in fromx:
      if isinstance(exp, basestring):
        scope_.add(exp, tables[exp])
      elif isinstance(exp, sqparse2.AliasX) and isinstance(exp.name, sqparse2.NameX):
        scope_.add(exp.alias, tables[exp.name.name])
      elif isinstance(exp, sqparse2.AliasX) and isinstance(exp.name, sqparse2.SelectX):
        scope_.add(exp.alias, SyntheticTable(exp.name))
      elif isinstance(exp, sqparse2.JoinX):
        raise NotImplementedError('todo: join')
      else:
        raise TypeError('bad fromx type', type(exp), exp)
    return scope_
1141885
def generate(
        cls: Type[T], data: Generic, name: str = None, *, recursive: bool = True
    ) -> T:
        """"""
        if name is None:
            name = cls.__name__
        kls = make_class(name, {k: ib(default=None) for k in data}, bases=(cls,))
        data = {
            k: (
                cls.generate(v, k.title())
                if recursive and isinstance(v, Mapping)
                else v
            )
            for k, v in data.items()
        }
        return kls(**data)
162706
function parse(tokens, basePath, iterSuffix) {
  const len = tokens.length;
  const body = [];

  let i = 0;
  while (i < len) {
    const token = tokens[i];
    if (subroutines[token.tokenType]) {
      const rest = tokens.slice(i + 1);
      const [
        branches,
        tokensHandled,
        shouldBreak,
      ] = subroutines[token.tokenType](token, rest, basePath, iterSuffix);

      body.push(...branches);

      i += tokensHandled;

      if (shouldBreak) {
        break;
      }
    } else {
      i += 1;
    }
  }

  return [body, i + 1];
}
942729
def convert(origin, target, type):
    
    _origin = origin.upper()
    if _origin == 'ROOTCODE':
        _origin = root_type_codes
    elif _origin == 'ROOTNAME':
        _origin = root_type_names
    elif _origin == 'ARRAY':
        _origin = python_codes
    elif _origin == 'NUMPY':
        _origin = numpy_codes
    else:
        raise ValueError("{0} is not a valid type".format(origin))

    _target = target.upper()
    if _target == 'ROOTCODE':
        _target = root_type_codes
    elif _target == 'ROOTNAME':
        _target = root_type_names
    elif _target == 'ARRAY':
        _target = python_codes
    elif _target == 'NUMPY':
        _target = numpy_codes
    else:
        raise ValueError("{0} is not a valid type".format(target))

    if type not in _origin:
        raise ValueError("{0} is not a valid {1} type".format(type, origin))

    return _target[_origin.index(type)]
788357
def subclass(cls, vt_code, vt_args):
        
        return type(vt_code.replace('/', '_'), (cls,), {'vt_code': vt_code, 'vt_args': vt_args})
620165
def load_dynamic_class(fqn, subclass):
    
    if not isinstance(fqn, basestring):
        return fqn

    cls = load_class_from_name(fqn)

    if cls == subclass or not issubclass(cls, subclass):
        raise TypeError("%s is not a valid %s" % (fqn, subclass.__name__))

    return cls
688920
private int getOrAppendVertex(Coordinate newCoord, Quadtree ptQuad) {
        Envelope queryEnv = new Envelope(newCoord);
        queryEnv.expandBy(epsilon);
        QuadTreeVisitor visitor = new QuadTreeVisitor(epsilon, newCoord);
        try {
            ptQuad.query(queryEnv, visitor);
        } catch (RuntimeException ex) {
            //ignore
        }
        if (visitor.getNearest() != null) {
            return visitor.getNearest().index;
        }
        // Not found then
        // Append to the list and QuadTree
        EnvelopeWithIndex ret = new EnvelopeWithIndex(triVertex.size(), newCoord);
        ptQuad.insert(queryEnv, ret);
        triVertex.add(ret);
        return ret.index;
    }
1261426
def of_type(cls, iterable, types):
    

    return cls(x for x in iterable if isinstance(x, types))
53478
def base_ctx(ctx):
    """"""

    result = None

    if isclass(ctx):
        result = getattr(ctx, '__base__', None)
        if result is None:
            mro = getmro(ctx)
            if len(mro) > 1:
                result = mro[1]
    else:
        result = ctx.__class__

    return result
429287
def typechecked_class(cls, force = False, force_recursive = False):
    
    return _typechecked_class(cls, set(), force, force_recursive)