def _from_class_value(self, value, value_type):
        type_factory = self._type_factory
        collation = self._collation
        bytes_to_unicode = self._bytes_to_unicode
        allow_tz = self._allow_tz

        if issubclass(value_type, bool):
            return type_factory.BitN
        elif issubclass(value_type, six.integer_types):
            if value is None:
                return type_factory.IntN(8)
            if -2 ** 31 <= value <= 2 ** 31 - 1:
                return type_factory.IntN(4)
            elif -2 ** 63 <= value <= 2 ** 63 - 1:
                return type_factory.IntN(8)
            elif -10 ** 38 + 1 <= value <= 10 ** 38 - 1:
                return type_factory.Decimal(0, 38)
            else:
                raise DataError('Numeric value out of range')
        elif issubclass(value_type, float):
            return type_factory.FloatN(8)
        elif issubclass(value_type, Binary):
            if value:
                if len(value) <= 8000:
                    return type_factory.VarBinary(8000)
                else:
                    return type_factory.long_binary_type()
            else:
                return type_factory.long_binary_type()
        elif issubclass(value_type, six.binary_type):
            if bytes_to_unicode:
                return type_factory.long_string_type(collation=collation)
            else:
                return type_factory.long_varchar_type(collation=collation)
        elif issubclass(value_type, six.string_types):
            return type_factory.long_string_type(collation=collation)
        elif issubclass(value_type, datetime):
            if value and value.tzinfo and allow_tz:
                return type_factory.datetime_with_tz(precision=6)
            else:
                return type_factory.datetime(precision=6)
        elif issubclass(value_type, date):
            return type_factory.date()
        elif issubclass(value_type, time):
            return type_factory.time(precision=6)
        elif issubclass(value_type, Decimal):
            if value is None:
                return type_factory.Decimal()
            else:
                return type_factory.Decimal.from_value(value)
        elif issubclass(value_type, uuid.UUID):
            return type_factory.UniqueIdentifier.instance
        elif issubclass(value_type, TableValuedParam):
            columns = value.columns
            rows = value.rows
            if columns is None:
                # trying to auto detect columns using data from first row
                if rows is None:
                    # rows are not present too, this means
                    # entire tvp has value of NULL
                    pass
                else:
                    try:
                        rows = iter(rows)
                    except TypeError:
                        raise DataError('rows should be iterable')

                    try:
                        row = next(rows)
                    except __HOLE__:
                        # no rows
                        raise DataError("Cannot infer columns from rows for TVP because there are no rows")
                    else:
                        # put row back
                        rows = itertools.chain([row], rows)

                        # use first row to infer types of columns
                        columns = []
                        try:
                            cell_iter = iter(row)
                        except TypeError:
                            raise DataError('Each row in table should be an iterable')
                        for cell in cell_iter:
                            if isinstance(cell, TableValuedParam):
                                raise DataError('TVP type cannot have nested TVP types')
                            col_type = self.from_value(cell)
                            col = Column(type=col_type)
                            columns.append(col)

            return Table(typ_schema=value.typ_schema, typ_name=value.typ_name, columns=columns, rows=rows)
        else:
            raise DataError('Cannot infer TDS type from Python value: {!r}'.format(value))
dataset/ETHPy150Open denisenkom/pytds/pytds/tds_types.py/TdsTypeInferrer._from_class_value