<commit_before># -*- coding: utf-8 -*-

"""Implements custom SQLAlchemy TypeDecorators."""

import uuid

import sqlalchemy.dialects.postgresql
from sqlalchemy.engine.default.interfaces import Dialect
from sqlalchemy.types import BINARY, TypeDecorator

__all__ = [
    'UUID',
]


class UUID(TypeDecorator):
    """Platform-independent UUID type.

    Uses Postgresql's UUID type, otherwise uses BINARY(16).
    Based on http://docs.sqlalchemy.org/en/rel_0_9/core/custom_types.html?highlight=guid#backend-agnostic-guid-type
    """

    impl = BINARY

    def load_dialect_impl(self, dialect: Dialect):
        """Load the implementation for a given dialect.

        :param dialect: The SQLAlchemy dialect (e.g., postgresql)
        """
        if dialect.name == 'postgresql':
            return dialect.type_descriptor(sqlalchemy.dialects.postgresql.UUID())

        return dialect.type_descriptor(BINARY)

    def process_bind_param(self, value, dialect):
        """Process the parameter to bind to the column.

        :param value: The value to bind
        :param dialect: The name of the dialect (e.g., postgresql)
        """
        if value is None:
            return

        if dialect.name == 'postgresql':
            return str(value)

        if isinstance(value, uuid.UUID):
            # raw UUID bytes
            return value.bytes

        value_uuid = uuid.UUID(value)
        return value_uuid.bytes

    def process_result_value(self, value, dialect: Dialect):
        """Process the parameter to load from the column.

        :param value: The value from the column
        :param dialect: The SQLAlchemy dialect (e.g., postgresql)
        """
        if value is None:
            return

        if dialect.name == 'postgresql':
            return uuid.UUID(value)

        return uuid.UUID(bytes=value)<commit_msg>Remove type hint on custom column because it didn't work :'(<commit_after># -*- coding: utf-8 -*-

"""Implements custom SQLAlchemy TypeDecorators."""

import uuid

import sqlalchemy.dialects.postgresql
from sqlalchemy.types import BINARY, TypeDecorator

__all__ = [
    'UUID',
]


class UUID(TypeDecorator):
    """Platform-independent UUID type.

    Uses Postgresql's UUID type, otherwise uses BINARY(16).
    Based on http://docs.sqlalchemy.org/en/rel_0_9/core/custom_types.html?highlight=guid#backend-agnostic-guid-type
    """

    impl = BINARY

    def load_dialect_impl(self, dialect):
        """Load the implementation for a given dialect.

        :param dialect: The SQLAlchemy dialect (e.g., postgresql)
        """
        if dialect.name == 'postgresql':
            return dialect.type_descriptor(sqlalchemy.dialects.postgresql.UUID())

        return dialect.type_descriptor(BINARY)

    def process_bind_param(self, value, dialect):
        """Process the parameter to bind to the column.

        :param value: The value to bind
        :param dialect: The name of the dialect (e.g., postgresql)
        """
        if value is None:
            return

        if dialect.name == 'postgresql':
            return str(value)

        if isinstance(value, uuid.UUID):
            # raw UUID bytes
            return value.bytes

        value_uuid = uuid.UUID(value)
        return value_uuid.bytes

    def process_result_value(self, value, dialect):
        """Process the parameter to load from the column.

        :param value: The value from the column
        :param dialect: The SQLAlchemy dialect (e.g., postgresql)
        """
        if value is None:
            return

        if dialect.name == 'postgresql':
            return uuid.UUID(value)

        return uuid.UUID(bytes=value)
{'fraction_non_alphanumeric': 0.09748771163298744, 'fraction_numerical': 0.002730748225013654, 'mean_word_length': 2.4885714285714284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4914496', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1061, 'n_words': 307}