<commit_before>#! /usr/bin/env python
# -*- coding: utf-8 -*-

from math                  import ceil, sqrt
from rpython.tool.pairtype import extendabletype

__all__ = ['HashableType']

def is_prime(n):
    upper = int(ceil(sqrt(n)))
    if n % 2 == 0:
        return False
    for i in range(3, upper, 2):
        if n % i == 0:
            return False
    return True

# A hashable type is an extendable type which includes a unique
# value associated with it. All classes generated by HashableType are assigned
# a unique prime number via the |_object_type_hash| method.
class HashableType(extendabletype):
    seed = [3]

    @staticmethod
    def next_prime():
        s = HashableType.seed[0]
        while True:
            s += 2
            if is_prime(s):
                HashableType.seed[0] = s
                return s

    def __new__(cls, name, parents, dct):
        val = HashableType.next_prime()
        dct['_object_type_hash'] = lambda self: val
        return extendabletype.__new__(cls, name, parents, dct)
<commit_msg>Fixup prime number computation<commit_after>#! /usr/bin/env python
# -*- coding: utf-8 -*-

from math                  import ceil, sqrt
from rpython.tool.pairtype import extendabletype

__all__ = ['HashableType']

def is_prime(n):
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    upper = int(ceil(sqrt(n)))
    for i in range(3, upper + 1, 2):
        if n % i == 0:
            return False
    return True

# A hashable type is an extendable type which includes a unique
# value associated with it. All classes generated by HashableType are assigned
# a unique prime number via the |_object_type_hash| method.
class HashableType(extendabletype):
    seed = [3]

    @staticmethod
    def next_prime():
        s = HashableType.seed[0]
        while True:
            s += 2
            if is_prime(s):
                HashableType.seed[0] = s
                return s

    def __new__(cls, name, parents, dct):
        val = HashableType.next_prime()
        dct['_object_type_hash'] = lambda self: val
        return extendabletype.__new__(cls, name, parents, dct)

{'fraction_non_alphanumeric': 0.09623430962343096, 'fraction_numerical': 0.010692701069270108, 'mean_word_length': 2.2409638554216866, 'pattern_counts': {'":': 0, '<': 4, '<?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': '6681611', 'n_tokens_mistral': 673, 'n_tokens_neox': 645, 'n_words': 222}