コード例 #1
0
ファイル: _field_common.py プロジェクト: ArtShp/DataScience
def is_type_cls(type_cls, field_type):
    if type(field_type) is set:
        return True
    types = tuple(field_type)
    if len(types) == 0:
        return False
    return issubclass(get_type(types[0]), type_cls)
コード例 #2
0
def check_type(destination_cls, field, name, value):
    if field.type and not any(isinstance(value, get_type(t)) for t in field.type):
        actual_type = type(value)
        message = "Invalid type for field {0}.{1}, was {2}".format(
            destination_cls.__name__, name, actual_type.__name__
        )
        raise PTypeError(destination_cls, name, field.type, actual_type, message)
コード例 #3
0
    def factory(self):
        # If no factory is specified and the type is another CheckedType use the factory method of that CheckedType
        if self._factory is PFIELD_NO_FACTORY and len(self.type) == 1:
            typ = get_type(tuple(self.type)[0])
            if issubclass(typ, CheckedType):
                return typ.create

        return self._factory
コード例 #4
0
ファイル: _field_common.py プロジェクト: tobgu/pyrsistent
    def factory(self):
        # If no factory is specified and the type is another CheckedType use the factory method of that CheckedType
        if self._factory is PFIELD_NO_FACTORY and len(self.type) == 1:
            typ = get_type(tuple(self.type)[0])
            if issubclass(typ, CheckedType):
                return typ.create

        return self._factory
コード例 #5
0
ファイル: _field_common.py プロジェクト: tobgu/pyrsistent
def is_type_cls(type_cls, field_type):
    types = tuple(field_type)
    if len(types) == 0:
        return False
    return issubclass(get_type(types[0]), type_cls)
コード例 #6
0
ファイル: _field_common.py プロジェクト: tobgu/pyrsistent
def check_type(destination_cls, field, name, value):
    if field.type and not any(isinstance(value, get_type(t)) for t in field.type):
        actual_type = type(value)
        message = "Invalid type for field {0}.{1}, was {2}".format(destination_cls.__name__, name, actual_type.__name__)
        raise PTypeError(destination_cls, name, field.type, actual_type, message)
コード例 #7
0
ファイル: _field_common.py プロジェクト: tobgu/pyrsistent
def _types_to_names(types):
    """Convert a tuple of types to a human-readable string."""
    return "".join(get_type(typ).__name__.capitalize() for typ in types)
コード例 #8
0
ファイル: _field_common.py プロジェクト: ArtShp/DataScience
def _types_to_names(types):
    """Convert a tuple of types to a human-readable string."""
    return "".join(get_type(typ).__name__.capitalize() for typ in types)