Generate newer-style type checks out of JSON-type-name-to-type mappings.

    Arguments:

        types (dict):

            A mapping of type names to their Python types

    Returns:

        A dictionary of definitions to pass to `TypeChecker`
332970
def _generate_legacy_type_checks(types=()):
    
    types = dict(types)

    def gen_type_check(pytypes):
        pytypes = _utils.flatten(pytypes)

        def type_check(checker, instance):
            if isinstance(instance, bool):
                if bool not in pytypes:
                    return False
            return isinstance(instance, pytypes)

        return type_check

    definitions = {}
    for typename, pytypes in iteritems(types):
        definitions[typename] = gen_type_check(pytypes)

    return definitions
511866
def _dict_to_obj(self, d):
    """"""
    if JsonEncoder.TYPE_ID not in d:
      return d

    type_name = d.pop(JsonEncoder.TYPE_ID)
    if type_name in _TYPE_NAME_TO_DECODER:
      decoder = _TYPE_NAME_TO_DECODER[type_name]
      return decoder(d)
    else:
      raise TypeError("Invalid type %s.", type_name)
21540
def _compile_type(self, schema):
        
        # Prepare self
        self.compiled_type = const.COMPILED_TYPE.TYPE
        self.name = get_type_name(schema)

        # Error partials
        err_type = self.Invalid(_(u'Wrong type'), self.name)

        # Type check function
        if six.PY2 and schema is basestring:
            # Relaxed rule for Python2 basestring
            typecheck = lambda v: isinstance(v, schema)
        else:
            # Strict type check for everything else
            typecheck = lambda v: type(v) == schema

        # Matcher
        if self.matcher:
            def match_type(v):
                return typecheck(v), v
            return match_type

        # Validator
        def validate_type(v):
            # Type check
            if not typecheck(v):
                # expected=<type>, provided=<type>
                raise err_type(get_type_name(type(v)))
            # Fine
            return v

        return validate_type
900446
def queryTypesDescriptions(self, types):
        
        types = list(types)
        if types:
            types_descs = self.describeSObjects(types)
        else:
            types_descs = []
        return dict(map(lambda t, d: (t, d), types, types_descs))
982278
def get_multi_match_mapping(self) -> Dict[Type, List[Type]]:
        
        if self._multi_match_mapping is None:
            self._multi_match_mapping = {}
            basic_types = self.get_basic_types()
            for basic_type in basic_types:
                if isinstance(basic_type, types.MultiMatchNamedBasicType):
                    matched_types: List[str] = []
                    # We need to check if each type in the `types_to_match` field for the given
                    # MultiMatchNamedBasic type is itself in the set of basic types allowed in this
                    # world, and add it to the mapping only if it is. Some basic types that the
                    # multi match type can match with may be diallowed in the world due to the
                    # instance-specific context.
                    for type_ in basic_type.types_to_match:
                        if type_ in basic_types:
                            matched_types.append(type_)
                    self._multi_match_mapping[basic_type] = matched_types
        return self._multi_match_mapping
1234036
def _type_digest(self, config: bool) -> Dict[str, Any]:
        
        res = {"base": self.yang_type()}
        if self.name is not None:
            res["derived"] = self.name
        return res
675489
def get_json_encoders_for_type(self, type_to_encode: type) -> Optional[Iterable[JSONEncoder]]:
        
        if type_to_encode not in self._json_encoders:
            return None
        return self._json_encoders[type_to_encode]
607837
def __type_to_tag(self, type_: Type) -> str:
        
        if type_ in scalar_type_to_tag:
            return scalar_type_to_tag[type_]

        if is_generic_list(type_):
            return 'tag:yaml.org,2002:seq'

        if is_generic_dict(type_):
            return 'tag:yaml.org,2002:map'

        if type_ in self._registered_classes.values():
            return '!{}'.format(type_.__name__)

        raise RuntimeError((
            'Unknown type {} in type_to_tag,'  # pragma: no cover
            ' please report a YAtiML bug.').format(type_))
1369598
def check_json(json_type):
        
        try:
            str_types = (str, unicode)
        except NameError:
            str_types = (str,)

        if type(json_type) == dict:
            return json_type
        elif type(json_type) in str_types:
            return json.loads(json_type)
        else:
            raise ValueError("json_type should be a json dict or string.")
604512
def get_types(func):
    
    return _get_types(func, util.is_classmethod(func), util.is_method(func))
786267
def types(self) -> GraphQLTypeList:
        """"""
        try:
            types = resolve_thunk(self._types)
        except GraphQLError:
            raise
        except Exception as error:
            raise TypeError(f"{self.name} types cannot be resolved: {error}")
        if types is None:
            types = []
        if not isinstance(types, (list, tuple)):
            raise TypeError(
                f"{self.name} types must be a list/tuple"
                " or a function which returns a list/tuple."
            )
        if not all(isinstance(value, GraphQLObjectType) for value in types):
            raise TypeError(f"{self.name} types must be GraphQLObjectType objects.")
        return types[:]
1088629
def spec_from_json_dict(
        json_dict  # type: Dict[str, Any]
):
    # type: (...) -> FieldSpec
    
    if 'ignored' in json_dict:
        return Ignore(json_dict['identifier'])
    type_str = json_dict['format']['type']
    spec_type = cast(FieldSpec, FIELD_TYPE_MAP[type_str])
    return spec_type.from_json_dict(json_dict)
192630
def get_type(bind):
    
    types = bind.types + [bind.schema.get('format')]
    for type_name in ('date-time', 'date', 'decimal', 'integer', 'boolean',
                      'number', 'string'):
        if type_name in types:
            return type_name
    return 'string'
1340317
def config_to_dict_of_dict(desired_type: Type[T], config: ConfigParser, logger: Logger,
                           conversion_finder: ConversionFinder, **kwargs) -> DictOfDict:
    
    # return dict(config)

    # get the base collection type if provided
    base_typ, discarded = _extract_collection_base_type(desired_type, exception_if_none=False)
    # if none, at least declare dict
    base_typ = base_typ or Dict

    # convert the whole config to a dictionary by flattening all sections. If a key is found twice in two different
    # sections an error is raised
    results = dict()
    for section, props in config.items():
        # convert all values of the sub-dictionary
        results[section] = ConversionFinder.convert_collection_values_according_to_pep(props, base_typ,
                                                                                       conversion_finder, logger,
                                                                                       **kwargs)

    return results
1273746
def _CollectTypeChecks(function, parent_type_check_dict, stack_location,
                      self_name):
  """"""
  type_check_dict = dict(parent_type_check_dict)
  type_check_dict.update(_ParseDocstring(function))

  # Convert any potential string based checks into python instances.
  for key, value in type_check_dict.items():
    if isinstance(value, str):
      type_check_dict[key] = _ParseTypeCheckString(value, stack_location + 1,
                                                  self_name)

  return type_check_dict
1092871
def python_type(textx_type_name):
    """"""
    return {
        'ID': text,
        'BOOL': bool,
        'INT': int,
        'FLOAT': float,
        'STRICTFLOAT': float,
        'STRING': text,
        'NUMBER': float,
        'BASETYPE': text,
    }.get(textx_type_name, textx_type_name)
647912
def to_type(cls, typename):
        
        NAME_TYPES = {cls.TYPE_NAMES[x]: x for x in cls.TYPE_NAMES}
        return NAME_TYPES.get(typename, None)