<commit_before>#!/usr/bin/env python3

"""Implementation of the Bypassers handlers."""

import collections
import types
import enum

from .decorators import (

    DescriptorProperty,
    Singleton,
    readonly,

)

__all__ = ["NoValue"] # the Bypassers get added to this later

def is_dunder(name):
    """Return True if a __dunder__ name, False otherwise."""
    return name[:2] == name[-2:] == "__" and "_" not in (name[2:3], name[-3:-2])

def sorter(x):
    # this is very ugly and I am not pleased with it, so if anyone can
    # come up with a better solution, I'm all open
    # see http://bugs.python.org/issue20630 and
    #     http://bugs.python.org/issue20632
    """Make sure non-string objects are last."""
    if "__lt__" not in type(x).__dict__:
        return "????????"
    if not isinstance(x, str):
        return "????" + str(x).lower()
    return x.lower()

def convert_to_od(mapping, order):
    """Convert mapping to an OrderedDict instance using order."""
    return collections.OrderedDict([(i, mapping[i]) for i in order])

@Singleton
class NoValue:
    """Express the lack of value, as None has a special meaning."""

    def __repr__(self):
        """Return the explicit NoValue string."""
        return "NoValue"

    def __bool__(self):
        """Return False no matter what."""
        return False

class Viewer: # TODO: set-like methods
    """Return a view object over the items of the instance."""

    def __init__(self, name, value, position, instance):
        self.name = name
        self.value = value
        self.position = position
        self.instance = instance

    def __repr__(self):
        """Return a view of the items."""
        return "%s([%s])" % (self.value, ", ".join(repr(x) for x in self))

    def __len__(self):
        """Return the number of items self will return."""
        return len(self.instance)

    def __contains__(self, item):
        """Return True if item is in self, False otherwise."""
        for value in self:
            if value == item:
                return True

        return False

    def __iter__(self, factory=iter):
        """Return a modular iterator over the items in the instance."""
        mapping = self.instance.__mapping__
        item_length = self.instance.__item_length__
        if self.position == (0,): # short-circuit for common use of keys
            if mapping:
                yield from factory(mapping)
<commit_msg>Remove the lengths of view objects<commit_after>#!/usr/bin/env python3

"""Implementation of the Bypassers handlers."""

import collections
import types
import enum

from .decorators import (

    DescriptorProperty,
    Singleton,
    readonly,

)

__all__ = ["NoValue"] # the Bypassers get added to this later

def is_dunder(name):
    """Return True if a __dunder__ name, False otherwise."""
    return name[:2] == name[-2:] == "__" and "_" not in (name[2:3], name[-3:-2])

def sorter(x):
    # this is very ugly and I am not pleased with it, so if anyone can
    # come up with a better solution, I'm all open
    # see http://bugs.python.org/issue20630 and
    #     http://bugs.python.org/issue20632
    """Make sure non-string objects are last."""
    if "__lt__" not in type(x).__dict__:
        return "????????"
    if not isinstance(x, str):
        return "????" + str(x).lower()
    return x.lower()

def convert_to_od(mapping, order):
    """Convert mapping to an OrderedDict instance using order."""
    return collections.OrderedDict([(i, mapping[i]) for i in order])

@Singleton
class NoValue:
    """Express the lack of value, as None has a special meaning."""

    def __repr__(self):
        """Return the explicit NoValue string."""
        return "NoValue"

    def __bool__(self):
        """Return False no matter what."""
        return False

class Viewer: # TODO: set-like methods
    """Return a view object over the items of the instance."""

    def __init__(self, name, value, position, instance):
        self.name = name
        self.value = value
        self.position = position
        self.instance = instance

    def __repr__(self):
        """Return a view of the items."""
        return "%s([%s])" % (self.value, ", ".join(repr(x) for x in self))

    def __contains__(self, item):
        """Return True if item is in self, False otherwise."""
        for value in self:
            if value == item:
                return True

        return False

    def __iter__(self, factory=iter):
        """Return a modular iterator over the items in the instance."""
        mapping = self.instance.__mapping__
        item_length = self.instance.__item_length__
        if self.position == (0,): # short-circuit for common use of keys
            if mapping:
                yield from factory(mapping)

{'fraction_non_alphanumeric': 0.12196652719665271, 'fraction_numerical': 0.007531380753138075, 'mean_word_length': 2.619227857683573, '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': '309031', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1342, 'n_words': 507}