<commit_before>from basetypes import *
from exttypes import *
from closuretypes import *
from ssatypes import *
from templatetypes import *
from typemapper import *

__all__ = minitypes.__all__ + [
    'O', 'b1', 'i1', 'i2', 'i4', 'i8', 'u1', 'u2', 'u4', 'u8',
    'f4', 'f8', 'f16', 'c8', 'c16', 'c32', 'template',
]

#------------------------------------------------------------------------
# Utilities
#------------------------------------------------------------------------

def is_obj(type):
    return type.is_object or type.is_array

native_type_dict = {}
for native_type in minitypes.native_integral:
    native_type_dict[(native_type.itemsize, native_type.signed)] = native_type

def promote_to_native(int_type):
    return native_type_dict[int_type.itemsize, int_type.signed]

def promote_closest(context, int_type, candidates):
    """
    promote_closest(Py_ssize_t, [int_, long_, longlong]) -> longlong
    """
    for candidate in candidates:
        promoted = context.promote_types(int_type, candidate)
        if promoted.itemsize == candidate.itemsize and promoted.signed == candidate.signed:
            return candidate

    return candidates[-1]

#------------------------------------------------------------------------
# Type shorthands
#------------------------------------------------------------------------

O = object_
b1 = bool_
i1 = int8
i2 = int16
i4 = int32
i8 = int64
u1 = uint8
u2 = uint16
u4 = uint32
u8 = uint64

f4 = float32
f8 = float64
f16 = float128

c8 = complex64
c16 = complex128
c32 = complex256
<commit_msg>Move some code from typesystem.__init__<commit_after>from basetypes import *
from exttypes import *
from closuretypes import *
from ssatypes import *
from templatetypes import *
from typemapper import *

from shorthands import *

__all__ = minitypes.__all__ + [
    'O', 'b1', 'i1', 'i2', 'i4', 'i8', 'u1', 'u2', 'u4', 'u8',
    'f4', 'f8', 'f16', 'c8', 'c16', 'c32', 'template',
]

{'fraction_non_alphanumeric': 0.2614987080103359, 'fraction_numerical': 0.043410852713178294, 'mean_word_length': 2.1842105263157894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6484280', 'n_tokens_mistral': 648, 'n_tokens_neox': 621, 'n_words': 161}